Getting generated value

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
amacprogramming
Posts: 2
Joined: Fri 05 Feb 2010 10:59

Getting generated value

Post by amacprogramming » Fri 05 Feb 2010 11:16

Hi!

I'm currently on a project that uses Firebird 1.0.

Assume following table structure:

Code: Select all

nameTable(id integer primary key, name varchar(30));
where id is auto incremented by an on before insert trigger.

The code used is like this:

Code: Select all

TIBCTable1.Append;
TIBCTable1.Edit;
TIBCTable1.FieldByName('name').AsString := 'jfdlsfj';
TIBCTable1.Post;

generatedId := TIBCTable1.FieldByName('id').AsInteger;
The problem is that generatedId is always '0'. Because the field is updated in the db, but not on the TIBCTable1's field.

I already read about using a returning clause (e.g. setting the DMLRefresh property to true) but this only seems to work for Firebird 2.0 and up.

Is there a similar way for Firebird 1.0 or do I have to somehow change the whole process.

My next try would be to use the KeyGenerator functionality, but this way I would probably have to change the database structure.

Any thoughts on this?

Thanks, amac

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Fri 05 Feb 2010 13:01

With Firebird 1.0 you can call the Refresh method to refresh the full dataset or use the KeyGenerator property.

amacprogramming
Posts: 2
Joined: Fri 05 Feb 2010 10:59

Post by amacprogramming » Fri 05 Feb 2010 13:16

Ok, thanks,

I'm using the keyGenerator strategy now, but will give the refresh option a try!


amac

Post Reply