I have been using this set of functions to do sequences, especially for
tables where AUTO_INCREMENT can be inconvenient.  Maybe it will help you
over just incrementing the ID by 1 in your code.

I based them on the DBIx::MysqlSequence perl module

http://brazil.addictmud.org/wiki/index.php/MySQL_Sequences

I'd also welcome any criticisms on it if anyone else is bored enough to
check it out.

Dan.


-----Original Message-----
From: Dan Buettner [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 27, 2006 8:55 AM
To: balaraju mandala
Cc: mysql@lists.mysql.com
Subject: Re: concurrency problem

Use a transaction and an InnoDB table.
http://dev.mysql.com/doc/refman/5.0/en/transactional-commands.html

Or, use the LOCK TABLES command:
http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html

An ideal solution (in my mind) is to use a stored procedure to read the 
table, increment the current value, update the table, and return the new

UID to the caller - all inside a transaction.  Used to do this with 
Sybase all the time; never tried it with MySQL's transactions and stored

procedures, but don't know why it wouldn't work.

Dan


balaraju mandala wrote:
> Hi Comunity,
> 
> I am facing concurrency problem. The scenario is, I have a table, the
> primary key of that table say 'uid' is a unique number, which is used
by my
> application. So every time i fire a query, i get max(uid) i read this
> ResultSet from my Java application. I increament this uid to +1. This
> resulted 'uid' will be updated to the Table. This table is used by
more 
> than
> one thread at any given time. So if some threads fire SQL command at
same
> time, they are getting same uid and result is a duplicate values
Exception.
> I cannot use AUTOINCREMENT. Please anybody have any solution for this?
> 

-- 
Dan Buettner

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]

-----------------------------------------------------------------------------------------------------------------------
This e-mail transmission is strictly confidential and intended solely
for the person or organization to whom it is addressed. It may contain
privileged and confidential information and if you are not the intended
recipient, you must not copy, distribute or take any action in reliance
on it. If you have received this e-mail in error, please notify the sender
as soon as possible and delete the e-mail message and any attachment(s).
This message has been scanned for viruses by TechTeam's email gateway.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to