Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CRecordet and CLongBinary (BLOB problem)

Posted on 1998-08-20
1
Medium Priority
?
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
piano_boxer earned 140 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

636 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