Subject Re: Proper transaction & deadlock handling
Hi Daniel,

It's been a while since I coded a solution to this but as best I recall this is what I did in a similar situation.

I think I ended up checking the specific error code that is returned when you get a deadlock. For this I think you can use ibase_errorcode. You should be able to look up all the various error codes and what they mean for your version of Firebird. You can then test for the errror code and if matched retry your query.

It will obviously depend on your polling interval as to how may times you retry. You might also want to randomise a suitable delay between each retry.

One other thing that might help is that if you are trying to work on mulitple rows is to work in "chunks" rather than trying to do the whole lot in one go. In this way the chances of a deadlock between the two processes might be reduced, or you might end up with fewer "chunks" to reprocess on each retry if there is a deadlock.