I am working on refactoring some data-handling code in a MFC application that uses the CRecordset API (actually, a derived class from it, but the failures are coming out of CRecordset itself AFAICT) to talk to an ODBC data source backed by an Oracle database, but have encountered a sequence of operations that the CRecordset API, at least as of the version shipped with Visual Studio 2012 (which I know is old, but am hog-tied to for the time being) seems to be unable to perform.
In particular, in the following sequence of events, intended to flush changes to the record to the DB so that other queries performed during this sequence can see them:
CRecordset aRecordset(myDatabase);
aRecordset.Open(CRecordset::snapshot, "<some query that yields no records>"); // using CRecordset::dynaset doesn't change things
aRecordset.AddNew();
// set some values on aRecordset...
aRecordset.Update();
aRecordset.Requery(); // removing the Requery calls changes the failure mode
aRecordset.Edit(); // This call fails if the Requery is present
// perform query that needs to pick up on the values set on aRecordset above
// set some more values on aRecordset...
aRecordset.Update(); // This call fails if the Requery is not present
aRecordset.Requery();
aRecordset.Edit();
// perform query that needs to pick up on the values set on aRecordset above
// set yet more values on aRecordset...
aRecordset.Update();
aRecordset.Close();
I get two different failure modes, depending on whether the Requery calls are present or not.
With the Requery calls present, I get the following error from the first call to Edit in the sequence:
Error: Edit attempt failed - not on a record.
Operation failed, no current record.
while with them absent, I get a different error, this time from the second call to Update in the sequence, as follows:
Error: failure updating record.
Invalid cursor state
State:24000,Native:0,Origin:[Microsoft][ODBC Driver Manager]
Am I completely off my rocker in expecting CRecordset to be capable of flushing a newly added record to the database then going back to update the row further? Or is this a simple case of API operator error, and if so, what am I missing here? Is my Visual Studio/MFC too old for this fancy footwork?
Furthermore, it turns out that doing a .Requery() is not an option due to a requirement that I be able to .Open() a recordset with multiple rows, then do an .Edit()/.Update()/.Edit()/.Update() sequence on each row. Using the .Requery() in this case causes the cursor to be reset to the beginning with no good way to restore the cursor position, as the Oracle ODBC drivers do not support bookmarking across a requery.