General Info:

OS: Mac OS X 
MySQL version: 3.23.52 (Jaguar)
PERL: 5.6.0
DBI: 1.30

I've got an application that was written to use Oracle sequences, as such
the program pulls a sequence number then creates a file based on that
number and populates a database record with infomation.  I've read
everything I can find out AUTO_INCREMENT values, but I can't seem to
reproduce the same functionality without causing some possible conflict
condition where two people may get the same numbers.

At the heart of the matter is a Perl sub I call "GetCounter()".  It
accepts a sequence name, pulls a value from the sequence and returns that
value.  Originally I was doing this with mSQL sequences.  With a minor
change to the code it ran fun in Oracle also.  Now I'm looking at porting
my stuff to MySQL, but can't seem to match the functionality.

Note, I'm importing a lot of these records from the Oracle DB to MySQL so
the counter would not be starting at 0.

Thoughts so far:

I've thought about "select MAX(ID+1) from mytable", but if two people
happen to be doing this at the same time, they'll get the same number -
bad.

"select LAST_INSERT_ID(ID+1)" seems like a similar solution since two
people could get the same LAST_INSERT_ID().

I'd like some way to pull the number and make sure it is not pulled again.
By the time I need the number, the information has been verified.  The
record will be populated using this number (ID field), a file will be
created using this number, etc.  I'd hate to have to do something like

"insert into mytable (ID) values (NULL)"

only to go back and

"select LAST_INSERT_ID(ID) from mytable"
"update mytable set LastName='blah',FirstName='foo',Phone='xxx',... where
ID=LAST_INSERT_ID()"

--Chuck


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to