#1 2015-07-09 13:20:12

alpinistbg
Member
Registered: 2014-11-12
Posts: 124

Autoincrementing IDs and the DB backends

Since I would like to generate sequence of natural numbers using the database itself, It occured to me that I can use the ID field of some side table for the purpose. My question is: Is the atomicity guaranteed when using different DB backends?

MSSQL for example usually gives such a guarantee on single statements (when outside of transaction) and for Firebird - there is always a pending transaction, so my concern is that in the MSSQL case, between the 'SELECT MAX(ID)+1 FROM' unitil actual 'INSERT INTO' there is a slight window where things can get messy and for the Firebird - that the insert can conflict with another one.

Regards,

Offline

#2 2015-07-09 20:15:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Autoincrementing IDs and the DB backends

All this works as long as the ORM is the only one to access the database.

This is how it is expected to be.

Online

#3 2015-07-09 23:07:48

alpinistbg
Member
Registered: 2014-11-12
Posts: 124

Re: Autoincrementing IDs and the DB backends

Of course, but AFAIK it is not single threaded ...

Offline

#4 2015-07-10 10:52:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Autoincrementing IDs and the DB backends

ID generation is protected by a critical section, so is thread safe within the ORM.

Online

Board footer

Powered by FluxBB