Solved

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

Posted on 1998-09-01
4
718 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
ID: 1171821
Adjusted points to 200
0
 
LVL 2

Expert Comment

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

Accepted Solution

by:
milenvk earned 200 total points
ID: 1171823
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
ID: 1171824
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Load and store *.pnm image file 1 86
C++ assignment question 7 206
best sources to up-to-date in C++? 8 82
Arduino EDI - Programming language 3 97
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

825 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