[fpc-pascal] How to insert a record and get the primary key withsqldb?

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Sat Oct 22 18:25:34 CEST 2011


Ok, thanks a lot =)

On 10/22/11, Michael Van Canneyt <michael at freepascal.org> wrote:
> ... And mainly the reason I think it is not abstractable... :-)

In this case I would suggest to abstract it like this:

// ASequenceName -> The name of the sequence for usage in Postgres,
etc. Ignored for MSSQL, etc.
// ARecordValues -> The values of the fields, all should be placed in
the sequence in which they exist in the table columns. nil is
accepted.
// Returns the index to the primary key
TSQLQuery.InsertNewRecordWithAutoGeneratedPrimaryKey(ASequenceName:
string; ARecordValues: array of const): Integer;

Then it will ... insert a new record with the record values that you
provided and give back the primary key for it.

At least that's how I would expect it =D

For each database it would simply figure out if it needs to get the
sequence number or if it will auto-generate or whatever.

-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list