Hi,
I am programmatically adding a user by doing a insert into the users table.

I am getting the last issued UID from the sequence table just by doing a query against it then adding one to the value , then updating the sequences table with the new uid.
Now this works fine in my test environment,but I am concerned that two users could register themselves(This is a ecommerce project, registration occurs after a valid paypal purchase) at the same time and get the same ID which of course would cause a problem
with the primary key.

I tried doing a grep of the Drupal source for any mentions of the sequences table but no hits came up.

How is drupal protecting access to this table to prevent primary key conflicts?

On a better database like PostgreSQL a real sequence does not have this issue because of transactions and MVCC. In this case I don't have a choice as the ISP only provides
MySQL.

Thanks,

Tony Caduto
AM Software Design
http://www.amsoftwaredesign.com
Home of Lightning Admin for MySQL and PostgreSQL.

Comments

brenda003’s picture

This is just a guess, but I think locking the tables first protects from this.

yelvington’s picture

Why are you poking directly on the database instead of using the Drupal API?