IZResultSet not reference last inserted record

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
josimarz
Junior Boarder
Junior Boarder
Posts: 41
Joined: 14.09.2009, 17:29
Location: Brazil

IZResultSet not reference last inserted record

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
Post Reply