reading the just generated identity throws an exception [ODBC208]
firebird-automations opened this issue · 1 comments
Submitted by: Michael von Boetticher (michael)
With MS-Access I used the identity column as primary key for table joining.
Firebird gives the possibility to create a similar table with:
CREATE TABLE TestTable (ID INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, Name VARCHAR(50));
The whole app is written with ADO, so I'd like to use the firebird ODBC. But here occurs the following problem:
reading the just generated identity throws an exception, I didn't have with MS-Access.
ADODB::\_RecordsetPtr prs = NULL;
CREATEINSTANCE\(prs, ADODB::Recordset\);
prs\-\>CursorLocation = ADODB::adUseClient;
prs\-\>Properties\-\>Item\["Update Resync"\]\-\>Value = \(long\)ADODB::adResyncAll;
prs\-\>Open\(\_bstr\_t\("SELECT \* FROM TestTable WHERE 1=0"\), \(IDispatch \*\)m\_pConnection, ADODB::adOpenKeyset, ADODB::adLockOptimistic, ADODB::adCmdText\);
prs\-\>AddNew\(\);
prs\-\>Fields\-\>Item\["Name"\]\-\>Value = "Some Text";
prs\-\>Update\(\);
long id = \(long\)prs\-\>Fields\-\>Item\["ID"\]\-\>Value; // throws an DB\_E\_DELETEDROW
prs\-\>Close\(\);
prs = NULL;
I need to know the generated ID for further actions in other subtables.
I think you're opening a guaranteed empty cursor (where 1=0) and then trying to get a field from NULL dataset, so you get a DB_E_DELETEDROW exception.
Try to use a separate generator for your table key.