Subject | Re: [IB-Conversions] Last Inserted Record |
---|---|
Author | Helen Borrie |
Post date | 2003-01-29T13:46:12Z |
At 12:21 AM 30/01/2003 +1100, you wrote:
concept of "last inserted record", since every operation occurs inside a
transaction and each transaction is isolated from all other transactions.
Firebird tables do not even have an external record number (although there
is rdb$db_key, which can be accessed within the context of one set and one
database transaction for the limited purpose of assessing the cardinality
of rows in a set...)
If you need to have a serial number for a record, you can create a field
for it and use a generator to populate it. For more information on this
technique (which is the commonest way to work surrogate primary keys), ask
on ib-support....
However, reading the last number of the generator won't necessarily tell
you what was the serial number of the last inserted record, since
generators operate outside of transaction control. Once generated, a
number cannot be generated again (unless the developer permits something
very-very foolish); but the record carrying a particular generated number
may remain uncommitted whilst some earlier or later numbers in the sequence
may be committed.
In short, in a transactional, multi-user database you cannot predict the
order in which inserts are committed, so your requirement predicates an
untenable context - except in an application which will only ever be used
by one user, who commits inserts always in a strict sequence.
Your question begs my question: why do you need it? I have a horrible
feeling you are going to say "so that I can calculate the primary key for
the next insert." Aaaargh.
Please would you be so good as to set your email client NOT to post to our
lists in HTML or multipart...plain text only, please.
Helen
>Hi,It is not done in Firebird, which is a multi-user database. There is no
>
>I am trying to successfully convert an R-Base database onto Firebird.
>
>In RBase we can do the following to get the last inserted record:
>
>Select * from TableName Where Count = Insert.
>
>How is this done in Firebird?
concept of "last inserted record", since every operation occurs inside a
transaction and each transaction is isolated from all other transactions.
Firebird tables do not even have an external record number (although there
is rdb$db_key, which can be accessed within the context of one set and one
database transaction for the limited purpose of assessing the cardinality
of rows in a set...)
If you need to have a serial number for a record, you can create a field
for it and use a generator to populate it. For more information on this
technique (which is the commonest way to work surrogate primary keys), ask
on ib-support....
However, reading the last number of the generator won't necessarily tell
you what was the serial number of the last inserted record, since
generators operate outside of transaction control. Once generated, a
number cannot be generated again (unless the developer permits something
very-very foolish); but the record carrying a particular generated number
may remain uncommitted whilst some earlier or later numbers in the sequence
may be committed.
In short, in a transactional, multi-user database you cannot predict the
order in which inserts are committed, so your requirement predicates an
untenable context - except in an application which will only ever be used
by one user, who commits inserts always in a strict sequence.
Your question begs my question: why do you need it? I have a horrible
feeling you are going to say "so that I can calculate the primary key for
the next insert." Aaaargh.
Please would you be so good as to set your email client NOT to post to our
lists in HTML or multipart...plain text only, please.
Helen