Solved

CRecordet and CLongBinary (BLOB problem)

Posted on 1998-08-20
1
291 Views
Last Modified: 2013-11-20
How do I store a blob through ODBC !
I got a CLongBinary object in a derived CRecordset and a BMP-file on disk.
1. - How do I load the BMP into the CLongBinary-object
2. - Does the CLongBinary automaticly get into the base on CRecordset.update() ?
Codesample please !!

0
Comment
Question by:Jeb
1 Comment
 
LVL 4

Accepted Solution

by:
piano_boxer earned 70 total points
ID: 1321089
Instead of using the CLongBinary class use CByteArray. In this I will name this as m_rgBin.

To save a block of binary data:

*** Before this open recordset and make a call to AddNew()
*** or Edit().

// First set size of CByteArray to the size needed.
rs.m_rgBin.SetSize( nSizeNeeded );

// If you are updating an existing record,
// check if it has changed.
// Otherwize ommit this test.
if(memcmp(&rs.m_rgBin[0], pMyData, rs.m_rgBin.GetSize()))
{
    // Its changed.
    // Copy the memory block into the CByteArrar object
    memcpy(&rs.m_rgBin[0], pMyData, rs.m_rgBin.GetSize());

    // Flag field as having a value, and dirty
    rs.SetFieldNull(&rs.m_rgBin, FALSE);
    rs.SetFieldDirty(&rs.m_rgBin, TRUE);
}

// NOTE: If you want to clear the field in the database
//       make this call: rs.m_rgBin.SetSize(0) and also
//       do the SetFieldDirty() call.

*** Somewhere after this call update to store the data.

---
To load a block of binary data:

// Are the field empty?
if(rs.m_userData.GetSize())
{
    // No, copy to our local buffer pMyData
    memcpy(pMyData, &rs.m_rgBin[0], rs.m_rgBin.GetSize());
}
else
{
    //
    // TODO: Insert code for handling empty field from database.
    //
}

------
THATS IT !!!!!!!!

The key to all this is the two functions SetFieldNull() and SetFieldDirty();
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tab names are off by one 5 54
WinWaitActive parameters 12 31
sumNumber challenge 16 122
Annoying "thing" blocks my view 4 100
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question