[fpc-pascal] Re: How to insert a record and get the primary key with sqldb?

Reinier Olislagers reinierolislagers at gmail.com
Mon Oct 24 12:50:33 CEST 2011


On 24-10-2011 11:14, michael.vancanneyt at wisa.be wrote:
> On Mon, 24 Oct 2011, Reinier Olislagers wrote:
>> Also, using INSERT...RETURNING it's very well possible to get the
>> sequence value directly when inserting the data.
> 
> Yes, but not all DBs support this. We use Firebird a lot, and it didn't
> support that construct until version 2.1 or so.
Yep, it's one of many really nice cross-db incompatibilities. Long live
SQL ;)
> 
> In each case: it's hard to abstract correctly, but nevertheless we'll try
> and make managing this easier. Martin's ideas for this are useful.
Yes, he's got experience with it already - more than you can say of some
armchair theorists like me ;)
> 
> What's funny is that I never understood how the MySQL/SQL-Server way could
> correctly work. For example I have 2 tables, both with an auto-incremental
> field. Table 1 has an after insert trigger that does an extra insert in
> table 2. When I do an insert in table 1 , what does 'last_insert_id'
> return ? The value for table 2 or table 1 ? The last inserted id for
> your connection is the one for table 2, but you need/expect the last id
> for table 1 :-)

True. Fortunately, I've never needed to do that ;)

Regards,
Reinier



More information about the fpc-pascal mailing list