Subject Re: [firebird-php] insert_id() for Interbase/Firebird
Author Lester Caine
Ard Biesheuvel wrote:

> I have a preliminary version of an ibase_insert_id() function that
> emulates the behaviour of mysql_insert_id() in Firebird. If some
> conditions are met, it is possible to query the database for the last
> assigned value. (Uncommitted snapshot transaction, the table has a field
> which is a singular primary key, the field has a 'before insert' trigger
> associated with it that is also associated with a generator, and the
> most recent operation was an INSERT and it didn't affect more than one
> record)
>
> If anyone is interested, I'll be adding this to PHP5 as soon as its
> first release is final. This would mean the function can be available in
> PHP 5.1
>
> Comments anyone?

While I can see the uses, I'm not sure we want to 'propagate bad
practice' ;)
If you need the number back, then you probably needed it before you
started the inserts

Most Firebird users have had the 'proper' way of using generators
drilled into them, and the ADOdb actions for gen_id() to get the next
number first is always preferable.

The CORRECT fix for this will come with Firebird 2 when RETURNING is
implemented, and ALL the trigger generated fields can be accessed.

The major problem we have is converting people who are used to the bad
practices of MySQL into correct relational practices with the proper use
of triggers and procedures.

That said, I only use Firebird via the ADOdb library, which masks some
of these differences anyway, and does provide a simple generic
'sequence' facility so I'm probably not a good judge :)

--
Lester Caine
-----------------------------
L.S.Caine Electronic Services