from include/db.inc.php
---------------------------------------
DBexecute("update ids set nextid=nextid+1 where
nodeid=$nodeid and table_name='$table' and field_name='$field'");
$row = DBfetch(DBselect("select nextid from ids
where nodeid=$nodeid and table_name='$table' and field_name='$field'"));
---------------------------------------
If 2 people simultaneoulsy add some element (like graph) it can cause race condition, ids will get incremented 2 times then both users will get the same ID which was incremented 2 times -> database inconsistency as result. You could lock the table between increment and select, but why make thinks so complicated?
Why can't you use autoincrement indexes on all tables?
You dont need ids table at all then, and since operation will be atomic you will avoid race condition without locking.
---------------------------------------
DBexecute("update ids set nextid=nextid+1 where
nodeid=$nodeid and table_name='$table' and field_name='$field'");
$row = DBfetch(DBselect("select nextid from ids
where nodeid=$nodeid and table_name='$table' and field_name='$field'"));
---------------------------------------
If 2 people simultaneoulsy add some element (like graph) it can cause race condition, ids will get incremented 2 times then both users will get the same ID which was incremented 2 times -> database inconsistency as result. You could lock the table between increment and select, but why make thinks so complicated?
Why can't you use autoincrement indexes on all tables?
You dont need ids table at all then, and since operation will be atomic you will avoid race condition without locking.
Comment