PRB: CLongBinary Data Doesn't Update with CRecordset::Open appendOnly OptionID: Q234797
|
When you call CRecordset::Open with the appendOnly option, you can't update any data that is in CLongBinary member variables. The Update call does not cause any errors, but the data in that field is not written to the database.
The CLongBinary member variable is not being bound to the table's column in the RFX_LongBinary function. RFX_LongBinary only binds the column if the recordset is updateable [CanUpdate() returns TRUE], but when opened with the appendOnly option, the recordset is only appendable and not updateable.
NOTE: If a driver does not support SQL_GD_BOUND for the SQL_GETDATA_EXTENSIONS value of SQLGetInfo(), MFC will attempt to perform SQL updates rather than positioned updates using SQLSetPos(), and therefore you will not see this problem. For example, if you are using a SQL Server datasource, you will not see a problem.
Use one of the following three workarounds:
case CFieldExchange::BindFieldToColumn:
// Don't bind if using update SQL, just do SQLGetData on Fixup.
if (!pFX->m_prs->m_bUseUpdateSQL && pFX->m_prs->CanUpdate())
to the following:
case CFieldExchange::BindFieldToColumn:
// Don't bind if using update SQL, just do SQLGetData on Fixup.
if (!pFX->m_prs->m_bUseUpdateSQL && (pFX->m_prs->CanUpdate() || pFX->m_prs->CanAppend()))
CMyRecordset rs;
rs.Open(CRecordset::dynaset, NULL, CRecordset::appendOnly);
CFile myBitmap("c:\\temp\\myBitmap.bmp", CFile::modeRead);
//Read from bitmap file into buffer.
LONG nTotalBytes = myBitmap.GetLength();
//Allocate a buffer for the input and read from file.
BYTE * inputBuf = new BYTE[nTotalBytes];
UINT nBytesRead = myBitmap.Read(inputBuf, nTotalBytes);
rs.AddNew();
rs.m_FirstName = "Cleo";
rs.m_LastName = "Haw";
//Copy the data into the CLongBinary member variable.
LPVOID pVoid = NULL;
DWORD bmpSize = nTotalBytes;
rs.m_Photo.m_hData = ::GlobalAlloc(GMEM_MOVEABLE,bmpSize);
pVoid = ::GlobalLock(rs.m_Photo.m_hData);
::memcpy(pVoid,inputBuf,bmpSize);
::GlobalUnlock(rs.m_Photo.m_hData);
rs.m_Photo.m_dwDataLength =::GlobalSize(rs.m_Photo.m_hData);
rs.SetFieldNull(&rs.m_Photo,FALSE);
rs.SetFieldDirty(&rs.m_Photo,TRUE);
rs.Update();
delete [] inputBuf;
::GlobalFree(rs.m_Photo.m_hData);
© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Sarah Parra, Microsoft Corporation
Additional query words: blob updatable canappend
Keywords : kbDatabase kbMFC kbODBC kbVC kbGrpVCDB
Version : winnt:5.0,6.0
Platform : winnt
Issue type : kbprb
Last Reviewed: August 5, 1999