Article ID: 139511
Article Last Modified on 11/21/2006
void RFX_Text2(CFieldExchange* pFX, const char* szName,
CString& value, int nMaxLength=255,
int nColumnType=SQL_VARCHAR);
In your recordset's .cpp file add:
void RFX_Text2(CFieldExchange* pFX, const char* szName,
CString& value, int nMaxLength /*=255*/ , int nColumnType
/* =SQL_VARCHAR */)
{
if (pFX->m_nOperation != CFieldExchange::NameValue &&
pFX->m_nOperation != CFieldExchange::Value &&
pFX->m_nOperation != CFieldExchange::BindParam)
{
RFX_Text(pFX, szName, value, nMaxLength, nColumnType);
return;
}
ASSERT(AfxIsValidAddress(pFX, sizeof(CFieldExchange)));
ASSERT(AfxIsValidString(szName));
ASSERT(AfxIsValidAddress&value, sizeof(CString)));
RETCODE nRetCode;
UINT nField;
if (!pFX->IsFieldType(&nField))
return;
LONG* plLength = pFX->m_prs->GetFieldLength(pFX);
switch (pFX->m_nOperation)
{
case CFieldExchange::NameValue:
if (pFX->m_prs->IsFieldFlagDirty(nField,pFX->m_nFieldType))
{
*pFX->m_pstr += pFX->m_prs->m_pDatabase->QuoteName(szName);
*pFX->m_pstr += "=";
}
// Fall through
case CFieldExchange::Value:
if (pFX->m_prs->IsFieldFlagDirty(nField, pFX->m_nFieldType))
{
// If user marked column NULL, reflect this in length
if (pFX->m_prs->IsFieldFlagNull(nField, pFX->m_nFieldType))
*plLength = SQL_NULL_DATA;
else
*plLength = SQL_NTS;
// If optimizing for bulk add, just set length.
if (!(pFX->m_prs->m_dwOptions & CRecordset::optimizeBulkAdd))
{
*pFX->m_pstr += "?";
*pFX->m_pstr += pFX->m_lpszSeparator;
pFX->m_nParamFields++;
AFX_SQL_SYNC(::SQLSetParam(pFX->m_hstmt,
(unsigned short int)pFX->m_nParamFields,
SQL_C_CHAR,
(short int)nColumnType,
nMaxLength,
0,
value.GetBuffer(0),
plLength));
value.ReleaseBuffer();
if (nRetCode != SQL_SUCCESS)
pFX->m_prs->ThrowDBException(nRetCode, pFX->m_hstmt);
}
}
return;
case CFieldExchange::BindParam:
*plLength = SQL_NTS;
// Preallocate to nMaxLength
value.GetBufferSetLength(nMaxLength);
AFX_SQL_SYNC(::SQLSetParam(pFX->m_hstmt,
(unsigned short int)nField,
(short int)SQL_C_CHAR,
(short int)nColumnType,
nMaxLength,
0,
value.GetBuffer(0),
plLength));
value.ReleaseBuffer();
if (nRetCode != SQL_SUCCESS)
pFX->m_prs->ThrowDBException(nRetCode, pFX->m_hstmt);
return;
}
}CMyRecordSet rs; rs.Open(CRecordset::snapshot, NULL, CRecordset::optimizeBulkAdd); rs.AddNew(); rs.m_field1="1234"; rs.Update(); rs.AddNew(); rs.m_field1="12345"; rs.Update(); rs.Close();The table will look like this:
field1 ------ 1234 1234instead of this:
field1 ------ 1234 12345
126131 How to Speed Up Apps that Use Microsoft Access 2.0 ODBC Driver
The MFC CRecordset class has a new optimization (in both 16- and 32-bit versions) that improves efficiency when you're adding new records in bulk to a table. A new option for the dwOptions parameter to the CRecordset::Open member function, optimizeBulkAdd, improves performance when you're adding multiple records consecutively without calling Requery or Close. Only those fields that are "dirty" prior to the first Update call are marked as "dirty" for subsequent AddNew/Update calls. If you are using the database classes to take advantage of the ::SQLSetPos API function for adding, editing, and deleting records, this optimization is unnecessary. If the ODBC Cursor Library is loaded or the ODBC driver doesn't support adding, editing, and deleting via ::SQLSetPos, this optimization should improve bulk add performance. To turn on this optimization, set the dwOptions parameter in the Open call for your recordset to:
appendOnly | optimizeBulkAdd
Additional query words: 1.5 1.50 1.52
Keywords: kbbug kbdatabase kbfix KB139511