Subject Deadlocks
Author Brad Pepers
I have code that returns back unique ids (I'm not using Interbase generators
because I want it to work with other databases). The code basically does
these commands:

update id_table set next_id = next_id + 1 where table_name = ?
select next_id from id_table where table_name = ?
commit

I'm using the native Interbase API and I get errors from isc_dsql_execute.
When I run two copies of the program I get these errors (as seen from using
isc_print_status):

deadlock
-update conflicts with concurrent update

I've tried different transaction options in isc_start_transaction but I can't
seem to find a good combination. And I don't understand where the deadlock
is coming from in the above case.

One thing I would like is a document explaining how Interbase does locking.
When using Sybase SQL Anywhere, it came with a section talking about the
different lock types (shared, exclusive, ...) and told you which were applied
when (on select, update, ...) so I could know just what kinds of locking
problems I faced. In the case of Sybase the above works since the one
program will get an exclusive lock on the table_name row in the id_table when
the update is done. If another program tries to do the same thing, it will
wait for the first lock to be released and then grab the lock for itself.

Any hints on getting this working with Interbase?

--
Brad Pepers
brad@...