Recent

Author Topic: Firebird - add +1 to the column on insert  (Read 11805 times)

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Firebird - add +1 to the column on insert
« Reply #15 on: December 12, 2014, 07:49:53 pm »
Suggested [ WITH LOCK] because of
Quote
When an UPDATE statement tries to access a record that is locked by another transaction, it either raises an update conflict exception or waits for the locking transaction to finish, depending on TPB mode.
providing that you use update before reading the max you will get what you want

i can't see how i can help more on this
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

goodname

  • Sr. Member
  • ****
  • Posts: 297
Re: Firebird - add +1 to the column on insert
« Reply #16 on: December 12, 2014, 09:19:44 pm »
Quote
WITH LOCK is not available:
...
with the DISTINCT operator, a GROUP BY clause or any other aggregating operation;
...
Max() is an aggregate so cannot be used with lock. This is a transaction isolation issue.
Apparently TPB stands for Transaction Parameter Buffer.

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Firebird - add +1 to the column on insert
« Reply #17 on: December 12, 2014, 10:36:29 pm »
you are right this
Code: [Select]
SELECT MAX([field]) FROM [table].... WITH LOCK ............in the same command is wrong

Edit*** my contribution to this subject ends here
the only way to ensure uniqness with transactions is to use the build in autoinc,sequences or whatever is named from the engin... these algorithms operate outside of the transaction isolation to ensure the values produced are unique
the other way is to find your way to do it
one way provided already and in order to brake it and make it fault you must run amazon, ebay or something like that...
 well if you are in this category you are in trouble with max+1 inside a transaction
« Last Edit: December 12, 2014, 11:02:32 pm by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

 

TinyPortal © 2005-2018