-
January 25th, 2001, 07:55 PM
#1
CRecordSets with CLongBinaries or CByteArrays
Hopefully someone has had a similar problem to mine and can help me.
I am using Visual C++ 6.0 and I am trying to use CRecordsets to insert and retrieve pictures from a database (using myODBC drivers). All database operations that are not related to BLOBs work great, but here are my problems:
At first, I tried to use the CLongBinary class to insert/retrieve pictures from the database. Inserting the pictures works fine (I know because I can view the pictures in the database using urSQL). But for some reason, when I try to retrieve the picture from the database, it contains no data. Specifically, the CLongBinary.m_dwDataLength is 0 and the CLongBinary.m_hData does not contain my picture. After banging my head against this problem for hours, I decided to use the CByteArray class instead.
The CByteArray class seemed to work great. I can put pictures in the database and retrieve them. The only problem is if I try to call Open() on the recordset with a SQL call that results in an empty row (for instance, if I called Open() on an empty table), I receive an ASSERTION failure in the RFX_Binary() method (This occurs inside of the Open() method).
Also, if I try to add a picture to the database after opening the recordset that does NOT result in an empty row (For instance, I call Open() when the table contains a row with a picture that is different from the picture I am currently adding), it will throw an exception that says "Error: field address (column 7) has changed!".
Any help for any of these problems would be greatly appreciated. Thank you.
-
January 26th, 2001, 01:10 PM
#2
Re: CRecordSets with CLongBinaries or CByteArrays
Check out this article. I hope it helps.
Using CLongBinary for BLOBs
http://www.codeproject.com/database/usingblob.asp
-
May 10th, 2001, 07:04 AM
#3
Re: CRecordSets with CLongBinaries or CByteArrays
Hi,
I have exactly the same problem. I can save a CLongBinary in a Access Database. The problem is that I can't save it in a FileMaker Pro database ( cannot modify a table which has been opened read only ).
Everything works well with texts, dates, ... but not with BLOBs ( pictures ).
Do you know something about that ???
Any help for any of these problems would be greatly appreciated. Thank you.
Yannick
-
May 10th, 2001, 01:33 PM
#4
Re: CRecordSets with CLongBinaries or CByteArrays
I don't know about FileMaker Pro, but I solved the MFC/mySQL problem by using CByteArrays instead of CLongBinaries. This seems to work well except that occasionally I receive an ASSERTION failure that says "Error column 7 has changed". I basically ignore this error and it has never been anything more than a nuisance.
Just remember that if you are using CByteArrays, the default maximum size of transfer is something like 255. You can override it in the CRecordset DoFieldExchange with something like this:
RFX_Binary(pFX, _T("[FieldContents]"), m_FieldContents, NEWMAXSIZE)
-
June 19th, 2002, 05:27 AM
#5
Re: Re: CRecordSets with CLongBinaries or CByteArrays
Originally posted by PeterK
Check out this article. I hope it helps.
Using CLongBinary for BLOBs
http://www.codeproject.com/database/usingblob.asp
In the example GlobalFree() is not called!! Because the CLongBinary dbImage.m_BLOBImage is reused (not calling its destructor) it left a lot memory leaks!
Theo Buys
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|