Page 1 of 1

IZResultSet not reference last inserted record

Posted: 02.03.2012, 21:35
by josimarz
Hello,

I have the following table in the database:

Code: Select all

PERSON
{
   CODE INTEGER (PRIMARY KEY),
   NAME VARCHAR
}
I'm using the interface ZDBC to insert records:

Code: Select all

function NewPerson(const Name: string): Integer;
var
   Stmt: IZPreparedStatement;
   Rs: IZResultSet;
begin
   Stmt := Conn.PrepareStatement('SELECT CODE, NAME FROM PERSON');
   Rs := Stmt.ExecuteQueryPrepared;
   Rs.MoveToInsertRow;
   Rs.UpdateString(2, Name);
   Rs.InsertRow;
   Result := Rs.GetInt(1);
end;
Connecting to a MySQL database, this code returns the identifier of the last inserted row, but not in Oracle (return 0).

This is a bug?

Tanks,
Josimar

Posted: 14.03.2012, 23:39
by mdaems
This is a bug?
No, it's rather a feature that's not supported for Oracle. If you want that behaviour with oracle you should use a TZSequence component to fill the auto-increment value.
If I'm not mistaken it's almost impossible to retrieve the autincremented column in the oracle OCI interface the way it works for mysql.
For mysql zeoslib can see if the field has autoincrement behaviour AND the mysql library provides a function to retrieve the last incremented value.
Oracle does not provide an easy way to see such autoincrement behaviour (only way would be parsing triggers on the table, but I don't even want to think about implementing that) AND it would be difficult to fetch the new value (only way is requerying the record, but with what search riteria?).

Mark