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

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Mon Oct 24 12:12:24 CEST 2011


michael.vancanneyt at wisa.be wrote:

>> Before MySQL 5.0.12 last_insert_id returns table 2, since 5.0.12 table 1.
>> Triggers were introduced in 5.0.2.
>>
>> SQLServer's SCOPE_IDENTITY() returns table 1 (the trigger is out of 
>> scope)
>> and @@IDENTITY returns 2.
> 
> This mess is why I prefer sequences :-)

:-) I had to tackle this one with PostgreSQL about ten years ago. I 
don't know whether sequences weren't implemented at the time or if I was 
simply too unfamiliar with the system to get things working, but I ended 
up generating a random primary key in the (Delphi) program that was 
committing the data and relying on the server to reject it if not unique.

A minor warning about Postgres's serial type: if the table is cleared 
the underlying sequence isn't automatically reset. That might or might 
not be what's needed/expected.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list