Article ID: 120513
Article Last Modified on 11/21/2006
#define SQL_OUTPUT_PARAM_VALUE 65536
void AFXAPI RFX_LongOut(CFieldExchange* pFX, const char *szName, long&
value)
{
if( pFX->m_nOperation == CFieldExchange::BindParam )
{
// deal with the special case ourselves
RETCODE nRetCode;
ASSERT(AfxIsValidAddress(pFX, sizeof(CFieldExchange)));
ASSERT(AfxIsValidString(szName));
UINT nField;
if (!pFX->IsFieldType(&nField))
return;
LONG* plLength = pFX->m_prs->GetFieldLength(pFX);
if (pFX->m_prs->IsFieldFlagNull(nField, CFieldExchange::param))
*plLength = SQL_NULL_DATA;
else
*plLength = sizeof(value);
// For params, CType is same as SQL type
AFX_SQL_SYNC(::SQLSetParam(pFX->m_hstmt,
(unsigned short int)nField,
(short int)SQL_C_LONG, (short int)SQL_C_LONG,
(unsigned long )SQL_OUTPUT_PARAM_VALUE, 0, &value, plLength))
;
if (nRetCode != SQL_SUCCESS)
pFX->m_prs->ThrowDBException(nRetCode, pFX->m_hstmt);
}
else
{
// let MFC handle all other operations
RFX_Long( pFX, szName, value );
}
}
void AFXAPI RFX_TextOut( CFieldExchange* pFX, const char *szName,
CString& value, int nMaxLength /*= 255*/,
int nColumnType /*= SQL_VARCHAR*/ )
{
// handle this ourselves
if( pFX->m_nOperation == CFieldExchange::BindParam )
{
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);
*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)SQL_OUTPUT_PARAM_VALUE + value.GetLength(),
0, value.GetBuffer(0), plLength));
value.ReleaseBuffer();
if (nRetCode != SQL_SUCCESS)
pFX->m_prs->ThrowDBException(nRetCode, pFX->m_hstmt);
}
else
{
// let MFC handle all other operations
RFX_Text( pFX, szName, value, nMaxLength, nColumnType );
}
}
NOTE: The ODBC 2.0 Programmer's Reference recommends using the
SQLBindParameter() function rather than SQLSetParam(). The only reason
SQLSetParam() is used here is because it is documented in the on-line
documentation for Microsoft Visual C++ version 1.5.
Additional query words: 1.50 1.51 1.52 2.00 2.10 2.50 2.51 2.52
Keywords: kbcode kbdatabase kbprb KB120513