Solved

How to Store and retrieve BMP's and JPG's into database recordset

Posted on 1998-09-01
4
712 Views
Last Modified: 2008-02-01
We need to store some large binary data into database . It may be of bitmap or jPEG or text file.
How to store them in database. I think we can make use of " CLongBinary" and corresponding RFX_LongBinary for CRecordset classes .
We are not able to store data and retrieve data from table.
Can anybody suggest the way of reading and writing bitmap file from database , using CLongBinary and RFX_LongBinary or any other way how ro deal witrh BLOB.
The database may be any type Oracle or MSAccess etc. It should be database indipendent.
0
Comment
Question by:rsquek
  • 2
4 Comments
 

Author Comment

by:rsquek
Comment Utility
Adjusted points to 200
0
 
LVL 2

Expert Comment

by:duneram
Comment Utility
blobs are definitely the way to go. I'll look into it
0
 
LVL 2

Accepted Solution

by:
milenvk earned 200 total points
Comment Utility
Well, here's the deal. You better use CByteArray and RFX_Binary, since they don't have boundary limit like CLongBinary and RFX_LongBinary. The way to go is:

// theByteArray is the array that is binded to the BLOB using RFX_Binary
// theImageByteSize is the size of the file in bytes
theByteArray.SetSize(theImageByteSize)
BYTE* pb = theByteArray.GetData();
// pbTheImageDataFromFile is the memory where you copied the data from the file
memcpy(pb, pbTheImageDataFromFile, theImageByteSize);
// rs is your recordset - you have to have called AddNew or Edit before that
rs.Update();

That's the way to put the data in the DB...
To get the data (assuming the recordset has positioned its cursor to the record of interest):

BYTE *pb = theByteArray.GetData();
int size = theByteArray.GetSize();

// Now *pb points to the memory with the data from the picture file
// and size is the size of the picture file
0
 
LVL 2

Expert Comment

by:milenvk
Comment Utility
Opps... I forgot the binding...
Here is the recordset's DoFieldExchange() part:

void CMyRecordset::DoFieldExchange( CFieldExchange* pFX )
{
  //...
  RFX_Binary(pFX, "TheColumnName", theByteArray);
  //...
}

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

744 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

13 Experts available now in Live!

Get 1:1 Help Now