Article ID: 134679
Article Last Modified on 11/21/2006
void AFXAPI RFX_MyText(CFieldExchange* pFX, const char* szName,
CString& value, int nMaxLength,
int nColumnType, int nScale)
{
if (pFX->m_nOperation != CFieldExchange::NameValue &&
pFX->m_nOperation != CFieldExchange::Value &&
pFX->m_nOperation != CFieldExchange::BindParam)
{
RFX_Text(pFX, szName, value, nMaxLength, nColumnType);
return;
}
// initialize and check things
switch (pFX->m_nOperation)
{
case NameValue:
// handle NameValue case
case Value:
// handle Value case
// not required for Visual C++ 4.2 or greater
case BindParam:
// handle BindParam case
}
}
The NameValue case is brought along because it falls into the Value case.
In the Value case, you need to change the call to SQLSetParam to specify
the scale. Here is the relevant section of the Value case from the MFC 2.52
RFX_Text() function (slightly reformatted):
AFX_SQL_SYNC(::SQLSetParam(m_hstmt,
(unsigned short int)m_nParamFields,
(short int)nCType,
// Get actual SQL type -
// may differ from CType (e.g. DECIMAL)
(short int)GetColumnType(nField),
(unsigned long int)cbPrecision,
0,
pv,
plLength));
NOTE: The sixth parameter is 0. This is what you need to change. Change
it to what is passed in the nScale parameter added to the RFX function. You
will also be using the value passed in the nColumnType parameter to specify
the SQL data type (4th parameter of SQLSetParam()):
AFX_SQL_SYNC(::SQLSetParam(pFX->m_hstmt,
(unsigned short int)pFX->m_nParamFields,
SQL_C_CHAR,
(short int)nColumnType,
(unsigned long int)value.GetLength(),
(short int)nScale,
value.GetBuffer(0),
plLength));
value.ReleaseBuffer();
NOTE: Because the SQLSetParam() call is now in the context of an RFX
function, you must use the CFieldExchange pointer (pFX) to access the
CFieldExchange members m_hstmt and m_nParamFields. If you borrow the rest
of the NameValue and Value case code from the CFieldExchange::Default()
function (which you should), you need to be aware of this throughout the
code.
/* Compile options needed: None
*/
// implementation based on VC++ 1.52 code
// prototype
void AFXAPI RFX_MyText(CFieldExchange* pFX, const char* szName,
CString& value, int nMaxLength, int nColumnType, int nScale);
// implementation
void AFXAPI RFX_MyText(CFieldExchange* pFX, const char* szName,
CString& value, int nMaxLength, int nColumnType, int nScale)
{
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 = value.GetLength();
// 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,
(unsigned long int)value.GetLength(),
(short int)nScale,
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,
(unsigned long int)value.GetLength(),
nScale,
value.GetBuffer(0),
plLength));
value.ReleaseBuffer();
if (nRetCode != SQL_SUCCESS)
pFX->m_prs->ThrowDBException(nRetCode, pFX->m_hstmt);
return;
}
}
Additional query words: kbvc150bug kbvc151bug kbvc152bug kbvc200bug kbvc210bug kbvc220bug kbvc400bug kbvc410bug kbvc420bug kbvc500bug kbvc600fix kbmfc kbdatabase kbODBC Oracle RFX_Text
Keywords: kbbug kbfix kbvc600fix KB134679