FIX: CRecordset::AddNew Inserts 32484 Into int Fields (RFX_INT)Last reviewed: December 1, 1997Article ID: Q170257 |
The information in this article applies to:
SYMPTOMSYou may see one of the following problems when you update a newly-added record using a CRecordset derived class that uses RFX_Int:
CAUSEThis problem is caused by a bug in the RFX_Int function which always causes it to mark the int data member as dirty during AddNew. This problem occurs only if the value of the int data member was not explicitly changed. When a record is added, all of the data members are set to pseudo null values. The application then sets the values of any members that are to be changed. Subsequently, any fields where the corresponding data member is not a pseudo null are marked as dirty and an SQL statement including all of the dirty fields is generated. In the RFX_Int::MarkForAddNew in Visual C++ 5.0, the if clause that checks for the pseudo null value was removed. The code in 5.0 appears as follows:
case CFieldExchange::MarkForAddNew: // can force writing of psuedo-null value (as a non-null) by ... if (!pFX->m_prs->IsFieldStatusDirty(nField - 1)) { pFX->m_prs->SetDirtyFieldStatus(nField - 1); pFX->m_prs->ClearNullFieldStatus(nField - 1); } return;The effect of the change is to force the field to be set as dirty (no matter what value it has), and write that value out to the underlying table. If the application has not changed that value since the AddNew, then it will be AFX_RFX_INT_PSEUDO_NULL = 32484.
RESOLUTIONThe resolution depends on the application. The cleanest workaround is to change the int data member to a long, and use the RFX_Long function. The code problem above only exists with the int type, and most of the server data types that might be mapped to an int, such as Integer, Numeric(9), etc., will map to a long as well. This method also creates more portable code, since the size and max value of the int data type varies from one platform and operating system to another. Another solution is to create your own RFX_Int functions. To create your own RFX_Int function, follow these steps:
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Studio 97 Service Pack 3. For more information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q170365 TITLE : INFO: Visual Studio 97 Service Packs - What, Where, and Why |
Additional query words: AddNew identity Update
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |