Solved

CRecordet and CLongBinary (BLOB problem)

Posted on 1998-08-20
1
287 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Error on moodle after upgrade 3 106
no14 challenge 14 57
twoTwo  challenge 35 86
zeroFront challenge 7 71
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now