Article ID: 133311
Article Last Modified on 11/21/2006
AFX_SQL_SYNC(::SQLSetParam(pFX->m_hstmt,
(unsigned short int)pFX->m_nParamFields, SQL_C_DEFAULT,
// Get actual SQL type - may differ from CType (e.g. DECIMAL)
(short int)pFX->GetColumnType(nField), value.m_dwDataLength,
0, &value, plLength));
Replace it with this code:
AFX_SQL_SYNC(::SQLBindParameter(pFX->m_hstmt,
(unsigned short int)pFX->m_nParamFields,SQL_PARAM_INPUT,
SQL_C_DEFAULT,
// Get actual SQL type - may differ from CType (e.g. DECIMAL)
(short int)pFX->GetColumnType(nField), value.m_dwDataLength,
0, &value, sizeof(value), plLength));
Replace the following code in the CFieldExchange::Value case:
*plLength = SQL_DATA_AT_EXEC;
with this code:
*plLength=SQL_LEN_DATA_AT_EXEC(((LONG)value.m_dwDataLength));
AFX_SQL_ASYNC(pFX->m_prs, ::SQLGetData(pFX->m_prs->m_hstmt,
(UWORD)nField,SQL_C_BINARY, (UCHAR*)lpLongBinary,
*plLength, plLength));
with this code:
do
{
DWORD dwChunkSize = value.m_dwDataLength - dwDataLength;
if (dwChunkSize > 0x8000)
dwChunkSize = 0x8000;
// Ignore expected data truncated warnings
AFX_SQL_ASYNC(pFX->m_prs, ::SQLGetData(pFX->m_prs->m_hstmt,
(unsigned short int)nField, SQL_C_BINARY,
(UCHAR FAR*)lpLongBinary, dwChunkSize, plLength));
dwDataLength += dwChunkSize;
lpLongBinary += dwChunkSize;
} while (nRetCode == SQL_SUCCESS || nRetCode ==
SQL_SUCCESS_WITH_INFO);
And do the following:
void AFXAPI RFX_LongBinary2(CFieldExchange* pFX,
const char *szName, CLongBinary& value)
{
DWORD dwDataLength = 0; // Add this line!
.
.
.
static char* szComma = ",";
Do this because RFX_LongBinary() refers to this variable, which is
in the file DBRFX.CPP. Because it is declared static in that file,
it cannot be seen outside of it, so it must be supplied in the file
that contains RFX_LongBinary2().
AFX_SQL_ASYNC(this, ::SQLPutData(hstmt, (PTR)lpData,
pLongBinary->m_dwDataLength));
::GlobalUnlock(pLongBinary->m_hData);
if (!Check(nRetCode))
{
// cache away error
CDBException* pException = new CDBException(nRetCode);
pException->BuildErrorString(m_pDatabase, hstmt);
// then cancel Execute operation
Cancel();
THROW(pException);
}
with this code:
DWORD dwDataLength = 0;
while (dwDataLength != pLongBinary->m_dwDataLength)
{
DWORD dwSend = pLongBinary->m_dwDataLength-dwDataLength;
if (dwSend > 0x8000)
dwSend = 0x8000;
AFX_SQL_ASYNC(this, ::SQLPutData(m_hstmtUpdate,
(PTR)lpData, dwSend));
if (!Check(nRetCode))
{
::GlobalUnlock(pLongBinary->m_hData);
// Cache away error
CDBException* pException = new CDBException(nRetCode);
pException->BuildErrorString(m_pDatabase, m_hstmtUpdate);
// Then cancel Execute operation
Cancel();
THROW(pException);
}
lpData += dwSend;
dwDataLength += dwSend;
}
BOOL CMyRecordset::Update()
{
// Insert the CRecordset::Update() code from MFC\SRC\DBCORE.CPP
}
BOOL CMyRecordset::UpdateInsertDelete()
{
// Insert the CRecordset::UpdateInsertDelete() code
// from MFC\SRC\DBCORE.CPP
}
void CMyRecordset::ExecuteUpdateSQL()
{
// Insert the CRecordset::ExecuteUpdateSQL() code
// from MFC\SRC\DBCORE.CPP
}
void CMyRecordset::ExecuteSetPosUpdate()
{
// Insert the CRecordset::ExecuteSetPosUpdate() code
// from MFC\SRC\DBCORE.CPP
}
void CMyRecordset::SendLongBinaryData(HSTMT hstmt)
{
RETCODE nRetCode;
void* pv;
AFX_SQL_ASYNC(this, ::SQLParamData(hstmt, &pv));
if (!Check(nRetCode))
{
// cache away error
CDBException* pException = new CDBException(nRetCode);
pException->BuildErrorString(m_pDatabase, hstmt);
// then cancel Execute operation
Cancel();
THROW(pException);
}
while (nRetCode == SQL_NEED_DATA)
{
CLongBinary* pLongBinary = (CLongBinary*)pv;
ASSERT_VALID(pLongBinary);
const BYTE* lpData =
(const BYTE*)::GlobalLock(pLongBinary->m_hData);
ASSERT(lpData != NULL);
DWORD dwDataLength = 0;
while (dwDataLength != pLongBinary->m_dwDataLength)
{
DWORD dwSend =
pLongBinary->m_dwDataLength-dwDataLength;
if (dwSend > 0x8000)
dwSend = 0x8000;
AFX_SQL_ASYNC(this,
::SQLPutData(m_hstmtUpdate, (PTR)lpData, dwSend));
if (!Check(nRetCode))
{
::GlobalUnlock(pLongBinary->m_hData);
// Cache away error
CDBException* pException =
new CDBException(nRetCode);
pException->BuildErrorString(
m_pDatabase, m_hstmtUpdate);
// Then cancel Execute operation
Cancel();
THROW(pException);
}
lpData += dwSend;
dwDataLength += dwSend;
}
// Check for another DATA_AT_EXEC
AFX_SQL_ASYNC(this, ::SQLParamData(hstmt, &pv));
if (!Check(nRetCode))
{
TRACE0("Error: failure handling long binary"
"value during update.\n");
ThrowDBException(nRetCode, hstmt);
}
}
}
125306 BUG: Cannot Insert BLOB Data Sized Between 64K and 128K
Additional query words: 2.00 2.10 2.20 2.5 2.51 2.52 2.52a 3.0 3.1 3.10 3.2 3.20
Keywords: kbbug kbcode kbdatabase kbfix KB133311