Article ID: 123977
Article Last Modified on 11/21/2006
case CFieldExchange::BindFieldToColumn:
{
UINT cbColumn;
int nSqlType = pFX->GetColumnType(nField, &cbColumn);
switch (nSqlType)
{
default:
pFX->m_prs->ThrowDBException(AFX_SQL_ERROR_FIELD_SCHEMA_MISMATCH);
case SQL_LONGVARCHAR:
case SQL_CHAR:
case SQL_VARCHAR:
break;
case SQL_DECIMAL:
case SQL_NUMERIC:
// Add room for sign and decimal point
cbColumn += 2;
break;
}
NOTE: The RFX_Text() function supports converting SQL_LONGVARCHAR,SQL_CHAR,
SQL_VARCHAR, SQL_DECIMAL, and SQL_NUMERIC fields to a CString. If the
column that the RFX_Text() function represents has any other SQL type, you
will get the exception.
case CFieldExchange::BindFieldToColumn:
{
UINT cbColumn;
int nSqlType = pFX->GetColumnType(nField, &cbColumn);
switch (nSqlType)
{
default:
break;
case SQL_DECIMAL:
case SQL_NUMERIC:
// Add room for sign and decimal point
cbColumn += 2;
break;
}
By removing the strict type checking of the RFX functions, you can use
functions like RFX_Text() to store SQL_DATE or SQL_TIMESTAMP column data in
strings rather than structures.
void RFX_MyText(CFieldExchange* pFX, const char *szName,
CString& value, int nMaxLength, int nColumnType)
{
ASSERT(AfxIsValidAddress(pFX, sizeof(CFieldExchange)));
ASSERT(AfxIsValidString(szName));
ASSERT(AfxIsValidAddress(&value, sizeof(CString)));
RETCODE nRetCode;
UINT nField;
if (!pFX->IsFieldType(&nField))
return;
if (pFX->m_nOperation==CFieldExchange::BindFieldToColumn)
{
UINT cbColumn;
int nSqlType = pFX->GetColumnType(nField, &cbColumn);
switch (nSqlType)
{
default:
break;
case SQL_DECIMAL:
case SQL_NUMERIC:
// Add room for sign and decimal point
cbColumn += 2;
break;
}
// Constrain to user specified max length
if (cbColumn > (UINT)nMaxLength)
cbColumn = nMaxLength;
AFX_SQL_SYNC(::SQLBindCol(pFX->m_prs->m_hstmt,
(unsigned short int)nField, SQL_C_CHAR,
value.GetBufferSetLength(cbColumn+1), cbColumn+1,
pFX->m_prs->GetFieldLength(pFX)));
value.ReleaseBuffer();
if (!pFX->m_prs->Check(nRetCode))
pFX->m_prs->ThrowDBException(nRetCode);
return;
}
// Undo the increments done in the IsFieldType call above
if (pFX->m_nFieldType == CFieldExchange::outputColumn)
--pFX->m_nFields;
else
--pFX->m_nParams;
RFX_Text(pFX, szName, value, nMaxLength, nColumnType);
}
MFC Technote #43 - "RFX Routines" MFC Encyclopedia articles on RFX in the online books
Additional query words: 1.50 2.00 2.50 2.51 3.00
Keywords: kbcode kbdatabase kbprb KB123977