CRecordSets with CLongBinaries or CByteArrays
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: CRecordSets with CLongBinaries or CByteArrays

  1. #1
    Join Date
    Jan 2001
    Posts
    2

    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.


  2. #2
    Join Date
    May 1999
    Location
    Wisconsin, USA
    Posts
    953

    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




  3. #3
    Join Date
    May 2001
    Location
    London/Paris
    Posts
    29

    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


  4. #4
    Join Date
    Jan 2001
    Posts
    2

    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)


  5. #5
    Join Date
    Jun 2002
    Location
    Holland
    Posts
    3

    Thumbs down 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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center