The information in this article applies to:
SYMPTOMSWhen you add or update a record that includes a numeric or decimal field (ODBC SQL data types SQL_DECIMAL and SQL_NUMERIC), all the digits to the right of the decimal point are lost. CAUSE
By default, ClassWizard or AppWizard map the SQL_DECIMAL and SQL_NUMERIC
SQL data types to the C data type SQL_C_CHAR. The MFC RFX_Text() routine
that is used for this data type (and also for normal character types)
always specifies 0 for the ibScale parameter when calling the ODBC API
function SQLSetParam() (as of Visual C++ 4.0, SQLBindParameter is the ODBC
API that is called). The ibScale parameter is used to specify the number of
digits to the right of the decimal point. WORKAROUNDWrite a custom RFX function that specifies the correct scale value and use it in place of RFX_Text() for those fields that have the problem. See the "Building and Using a New RFX Function" section in this article for details. One possible implementation based on the MFC 2.52 RFX_Text() implementation is shown in the sample code section at the end of this article. STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was corrected in Visual C++ version 6.0 for Windows. MORE INFORMATIONBuilding and Using a New RFX Function to Work Around ProblemThe first step is to create a new RFX function. This function should delegate to RFX_Text() for everything but the CFieldExchange::NameValue case, the CFieldExchange::Value case (for fields that are bound to database columns), and the CFieldExchange::BindParam case (for parameter fields -- not required for Visual C++ version 4.2 or later) of the CFieldExchange object's m_nOperation member variable. You will also need to add an extra parameter to the RFX function and pass the scale value there. Note that this parameter already exists in Visual C++ version 4.2 or later.NOTE: To be ODBC 2.0 compliant, you can replace calls to SQLSetParam with calls to SQLBindParameter. Visual C++ 4.x uses SQLBindParameter. The RFX_ function should be structured like this:
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):
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()):
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.For the BindParam case, you can just copy the implementation of this case from RFX_Text() and change the sixth parameter of the SQLSetParam() call from 0 to the value passed in through the nScale parameter of your custom RFX_ function (not required for Visual C++ version 4.2 or later). To use the new RFX function, change the call to RFX_Text for the fields in question in your recordset's DoFieldExchange() function to calls to the new RFX function you just wrote. Be aware that you will now be specifying six parameters in your RFX function call. This call should be placed outside of Class Wizard's AFX_FIELD_MAP comment block. Sample Code to Implement Workaround
REFERENCESODBC 2.0 Programmer's Reference, Appendix D - Data Types Additional query words: kbvc150bug kbvc151bug kbvc152bug kbvc200bug kbvc210bug kbvc220bug kbvc400bug kbvc410bug kbvc420bug kbvc500bug kbvc600fix kbmfc kbdatabase kbODBC Oracle RFX_Text
Keywords : kbMFC kbVC150bug kbVC151bug kbVC152bug kbVC200bug kbVC210bug kbVC220bug kbVC400bug kbVC410bug kbVC420bug kbVC500bug kbVC600fix |
Last Reviewed: August 3, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |