behavior and documents conflict for SELECT LAST_INSERT_ID()

2017-04-21 Thread Chenxi Li
Dear friends, 1. https://bugs.mysql.com/bug.php?id=78934 2. https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_last-insert-id The document (2) says that LAST_INSERT_ID() will not be changed if no rows are inserted successfully. But (1) says that it's undefined when

last_insert_id

2009-12-27 Thread Victor Subervi
row in set (0.00 sec) mysql select last_insert_id() from products; +--+ | last_insert_id() | +--+ |0 | +--+ 1 row in set (0.00 sec) mysql Now, I was expecting 1, not 0! What up? TIA, Victor

Re: last_insert_id

2009-12-27 Thread Mattia Merzi
2009/12/27 Victor Subervi victorsube...@gmail.com: mysql select * from products; [...] mysql select last_insert_id() from products; [...] Now, I was expecting 1, not 0! What up? [...] LAST_INSERT_ID() (no arguments) returns the first automatically generated value successfully inserted

Re: last_insert_id

2009-12-27 Thread Victor Subervi
On Sun, Dec 27, 2009 at 11:27 AM, Mattia Merzi mattia.me...@gmail.comwrote: 2009/12/27 Victor Subervi victorsube...@gmail.com: mysql select * from products; [...] mysql select last_insert_id() from products; [...] Now, I was expecting 1, not 0! What up? [...] LAST_INSERT_ID

Re: last_insert_id

2009-12-27 Thread Michael Dykman
last_insert_id() returns the last id auto-incremented in *the current session*. If you disconnect and reconnect, it can not be retrieved. - michael dykman On Sun, Dec 27, 2009 at 11:42 AM, Victor Subervi victorsube...@gmail.com wrote: On Sun, Dec 27, 2009 at 11:27 AM, Mattia Merzi mattia.me

Re: last_insert_id

2009-12-27 Thread Victor Subervi
On Sun, Dec 27, 2009 at 12:00 PM, Michael Dykman mdyk...@gmail.com wrote: last_insert_id() returns the last id auto-incremented in *the current session*. If you disconnect and reconnect, it can not be retrieved. Ahah! So how do I retrieve the last id inserted irrespective of connection? TIA

Re: last_insert_id

2009-12-27 Thread Gary Smith
Victor Subervi wrote: On Sun, Dec 27, 2009 at 12:00 PM, Michael Dykman mdyk...@gmail.com wrote: last_insert_id() returns the last id auto-incremented in *the current session*. If you disconnect and reconnect, it can not be retrieved. Ahah! So how do I retrieve the last id inserted

Re: last_insert_id

2009-12-27 Thread Steve Edberg
| | ++--+--+---++-+---++--++-+--+---+--+---+---++--+--+--+--+-+--+ 1 row in set (0.00 sec) mysql select last_insert_id() from products; +--+ | last_insert_id() | +--+ |0 | +--+ 1 row in set (0.00 sec) mysql Now, I was expecting 1, not 0! What up? TIA

Re: last_insert_id

2009-12-27 Thread Victor Subervi
On Sun, Dec 27, 2009 at 1:30 PM, Gary Smith li...@l33t-d00d.co.uk wrote: Victor Subervi wrote: On Sun, Dec 27, 2009 at 12:00 PM, Michael Dykman mdyk...@gmail.com wrote: last_insert_id() returns the last id auto-incremented in *the current session*. If you disconnect and reconnect

Re: last_insert_id

2009-12-27 Thread Gary Smith
Steve Edberg wrote: (2) autoincrement values are not reused after deletion, so if you deleted the record with ID=1000 inserted in (1), the next autoincrement would still be 1001, even if the existing records are IDs 1,2,3. This is usually the desired behavior, but again, may not be what *you*

Re: last_insert_id

2009-12-27 Thread Carsten Pedersen
Gary Smith skrev: ... An example of where it wouldn't be: Although ID is auto_increment, you could define a row as, say, '10005583429'. This would be a valid input. Selecting max(id) would return that number. However, auto_increment wouldn't change - it would still be '34' (or whatever) for

Re: last_insert_id

2009-12-27 Thread Mark Goodge
Gary Smith wrote: Steve Edberg wrote: (2) autoincrement values are not reused after deletion, so if you deleted the record with ID=1000 inserted in (1), the next autoincrement would still be 1001, even if the existing records are IDs 1,2,3. This is usually the desired behavior, but again, may

Re: LAST_INSERT_ID and CRC32

2009-05-06 Thread thun...@isfahan.at
Thank you very much for all answers I will trying Triggers and the example with the update after an INSERT. Ant then, I use the best for me;-) Thunder Yes, Triggers... I so rarely use them I forget they exist. On Tue, May 5, 2009 at 10:22 AM, Thomas Pundt mli...@rp-online.de wrote:

Re: LAST_INSERT_ID and CRC32

2009-05-05 Thread Thomas Pundt
Johnny Withers schrieb: Well, I think an update after insert is the only way. Other than perpopulating another table with possibe crc values then usinga join: Select id from testtable Inner join crctable on testtable.id=crctable.id Where crctable.crcval='xxx' Just be sure to index the

Re: LAST_INSERT_ID and CRC32

2009-05-05 Thread Johnny Withers
Yes, Triggers... I so rarely use them I forget they exist. On Tue, May 5, 2009 at 10:22 AM, Thomas Pundt mli...@rp-online.de wrote: Johnny Withers schrieb: Well, I think an update after insert is the only way. Other than perpopulating another table with possibe crc values then usinga join:

LAST_INSERT_ID and CRC32

2009-05-03 Thread thun...@isfahan.at
-- CRC32('3') I would like insert the CRC32 directly when I make a new Insert. E.G. INSERT INTO `db283796092`.`testtable` ( `id` , `id-crc` ) VALUES ( NULL , LAST_INSERT_ID() ); But LAST_INSERT_ID() is 0 How can I make that, that he use the actual INSERT-ID? Best regards Thunder

Re: LAST_INSERT_ID and CRC32

2009-05-03 Thread Johnny Withers
I don't think its possible to do what you want in a single statement. Since LAST_INSERT_ID() is set to the last insert id of the connection... and the row you are inserting doesn't exist.. well.. until you create it, it will always either be zero or the record BEFORE your next insert, ie: INSERT

Re: LAST_INSERT_ID and CRC32

2009-05-03 Thread thun...@isfahan.at
) = 46316330 0.5712 sec. OK, I can make an UPDATE after an INSERT but then I can't use UNIQUE for the Coloumn with the CRC32... Before I can make an Update, the Value is 0... I don't think its possible to do what you want in a single statement. Since LAST_INSERT_ID() is set to the last insert id

Re: LAST_INSERT_ID and CRC32

2009-05-03 Thread thun...@isfahan.at
I'm so sorry for the mistake... I mean: I think it is to slow when I make a SELECT later in this form: I don't think its possible to do what you want in a single statement. Since LAST_INSERT_ID() is set to the last insert id of the connection... and the row you are inserting doesn't exist

Re: LAST_INSERT_ID and CRC32

2009-05-03 Thread Johnny Withers
statement. Since LAST_INSERT_ID() is set to the last insert id of the connection... and the row you are inserting doesn't exist.. well.. until you create it, it will always either be zero or the record BEFORE your next insert, ie: INSERT INTO testtable(NULL,LAST_INSERT_ID()); INSERT INTO testtable

Re: MySQL, perl, last_insert_id() question

2008-01-29 Thread Baron Schwartz
a valid DB handle and after an insert I try to get the ID of that inserted row, a la: my $id = $DBH-last_insert_id(); This has been working everywhere until I tried installing the exact same script on this newest machine. When the script runs now I get: DBI last_insert_id: invalid

MySQL, perl, last_insert_id() question

2008-01-28 Thread Dean Karres
, a la: my $id = $DBH-last_insert_id(); This has been working everywhere until I tried installing the exact same script on this newest machine. When the script runs now I get: DBI last_insert_id: invalid number of arguments: got handle + 0, expected handle + between 4 and 5 Usage

Re: MySQL, perl, last_insert_id() question

2008-01-28 Thread Octavian Rasnita
Do you have the latest version of DBI and DBD::mysql installed? First try: $ cpan cpan install DBI cpan install DBD::mysql You can also do: my $sth = $dbh-prepare(select last_insert_id()); $sth-execute(); my ($last_insert_id) = $sth-fetchrow_array(); Octavian - Original Message

Re: Using the last_insert_id() function

2007-06-02 Thread Baron Schwartz
up tables. Do I need to do this manually or can I use the last_insert_id() function? But not sure if this would work since I¹m not populating the garments table one row at a time ­ I¹m inserting all info in one go with LOAD DATA INFILE, as mentioned above. Just wondered if someone could help solve

Using the last_insert_id() function

2007-06-01 Thread gwh
garment_id from the garments table into the correct foreign key fields in the garments_to_colour, garments_to_sizes and garments_to_categories look up tables. Do I need to do this manually or can I use the last_insert_id() function? But not sure if this would work since I¹m not populating the garments

LAST_INSERT_ID LAST_UPDATE_ID

2007-05-26 Thread sam rumaizan
=Whatever I found LAST_INSERT_ID but i doesn't work What I want to do is: 1-user has 10 columns (fields). 2- User updated one of these fields using CONCAT_WS(adding new data to previous data). 3- When user views any of his information he sees only the last updated part of the data. So

Re: InnoDB Transaction and LAST_INSERT_ID()

2006-11-29 Thread Nico Sabbi
Mike Kruckenberg wrote: mysql SET @staff_id = LAST_INSERT_ID(); Query OK, 0 rows affected (0.01 sec) I don't know if this behaviour has changed in later versions of mysql, but using session variables, although lovely, was the quickest way to break replication (at least up to and including

InnoDB Transaction and LAST_INSERT_ID()

2006-11-28 Thread Andre Matos
INTO staff (`Name`) VALUES ('ABC'); INSERT INTO changes (`Key`, `Table`, `Value`) VALUES (LAST_INSERT_ID(), 'staff', 'ABC'); COMMIT; SET AUTOCOMMIT=1; This works fine in my test environment, however what about many users doing at the same time. Does the LAST_INSERT_ID() get the correct ID for each user

Re: InnoDB Transaction and LAST_INSERT_ID()

2006-11-28 Thread Mike Kruckenberg
(`Key`, `Table`, `Value`) VALUES (LAST_INSERT_ID(), 'staff', 'ABC'); COMMIT; SET AUTOCOMMIT=1; This works fine in my test environment, however what about many users doing at the same time. Does the LAST_INSERT_ID() get the correct ID for each user? LAST_INSERT_ID() is connection-specific so

Re: InnoDB Transaction and LAST_INSERT_ID()

2006-11-28 Thread Mike Kruckenberg
Andre Matos wrote: SET AUTOCOMMIT=0; START TRANSACTION; INSERT INTO staff (`Name`) VALUES ('ABC'); INSERT INTO changes (`Key`, `Table`, `Value`) VALUES (LAST_INSERT_ID(), 'staff', 'ABC'); COMMIT; SET AUTOCOMMIT=1; This works fine in my test environment, however what about many users doing

Re: InnoDB Transaction and LAST_INSERT_ID()

2006-11-28 Thread Andre Matos
the LAST_INSERT_ID() and open another transaction to write my audit trail. However, if the first one went through ok but if I got a problem at the second transaction, I need to delete the inserted or updated or move back the deleted information. This doesn't work well. Let's expand my staff and change tables

Re: InnoDB Transaction and LAST_INSERT_ID()

2006-11-28 Thread Mike Kruckenberg
. Then, I get the LAST_INSERT_ID() and open another transaction to write my audit trail. However, if the first one went through ok but if I got a problem at the second transaction, I need to delete the inserted or updated or move back the deleted information. This doesn't work well. Let's expand my staff

Re: InnoDB Transaction and LAST_INSERT_ID()

2006-11-28 Thread Andre Matos
is what I am doing now: open one transaction to insert, or update, or delete certain information and close with the commit. Then, I get the LAST_INSERT_ID() and open another transaction to write my audit trail. However, if the first one went through ok but if I got a problem at the second

last_insert_id problem

2006-07-07 Thread Afshad Dinshaw
Hi Im using the latest version of mysql. When I run the following query : select last_insert_id() if get the error message: function vcontacts.last_insert_id does not exist note: vcontacts is the name of my database. anyone know why? thanks

Re: last_insert_id problem

2006-07-07 Thread John L Meyer
Afshad Dinshaw wrote: Hi Im using the latest version of mysql. When I run the following query : select last_insert_id() if get the error message: function vcontacts.last_insert_id does not exist note: vcontacts is the name of my database. anyone know why? thanks I can run it both

'on duplicate key update' and 'last_insert_id'

2006-06-30 Thread Rob Desbois
can just say e.g. ON DUPLICATE KEY UPDATE id=id The problem with this is that if I then do SELECT LAST_INSERT_ID(); then I don't get the id of the 'updated' table, I get the *next* auto increment value. Is the last bit a bug? Can I get what I want without using REPLACE? Does this post make

Re: 'on duplicate key update' and 'last_insert_id'

2006-06-30 Thread David Hillman
On Jun 30, 2006, at 10:44 AM, Rob Desbois wrote: That leaves me with ON DUPLICATE KEY UPDATE. It's not amazingly helpful as you have to provide a column to update - however I can just say e.g. ON DUPLICATE KEY UPDATE id=id The problem with this is that if I then do SELECT LAST_INSERT_ID

Questions about last_insert_id() instead of @@IDENTITY

2005-09-07 Thread Ryan Stille
as a single query. I gave it a name of insertquery, and I can get the ID back as insertquery.adid. I am having trouble getting the same functionality with MySQL. cfquery name=insertquery INSERT INTO TABLE (...) SELECT LAST_INSERT_ID() as adid /cfquery I get this MySQL error: You have an error in your

Re: Questions about last_insert_id() instead of @@IDENTITY

2005-09-07 Thread Tim
LAST_INSERT_ID() as adid /cfquery I get this MySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO rps_names (nameid, name) VALUES (NULL, Ryan Smithland) SELECT LA' at line 2 With MSSQL the trick

RE: Questions about last_insert_id() instead of @@IDENTITY

2005-09-07 Thread Ryan Stille
it might be best to ask this in the cf forums, however did you try to separate the statements with a ; ? I haven't tried 2 query statements for MySQL in cfquery...yet ;-) Also I believe MySQL 3.23+ supports @@identity Yes I've tried semicolons after the statements, and I've tried setting

Re: Questions about last_insert_id() instead of @@IDENTITY

2005-09-07 Thread Remo Tex
having trouble getting the same functionality with MySQL. cfquery name=insertquery INSERT INTO TABLE (...) SELECT LAST_INSERT_ID() as adid /cfquery I get this MySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use

last_insert_id

2005-02-15 Thread mel list_php
Hi! I have a database where several users can connect and input data. I managed to have my insert queries as atomic, but I was wondering about one special case: I make one insert, and retrieve the last id inserted by mysql because I need to update an other table with that id. - if one user

Re: last_insert_id

2005-02-15 Thread Johan Höök
Hi, You can probably use SELECT LAST_INSERT_ID() which keeps auto-increment values on a per connection basis. See: http://dev.mysql.com/doc/mysql/en/getting-unique-id.html /Johan mel list_php wrote: Hi! I have a database where several users can connect and input data. I managed to have my insert

Re: last_insert_id

2005-02-15 Thread Alec . Cawley
? - is there a way to make an atomic query with this that would avoid me to use locks? last_insert_id is on a per-connection basis i.e. it gives the last id inserted using that particular connection. Therefore you will always get the most recent ID that you inserted, not the most recent that anyone

Re: last_insert_id

2005-02-15 Thread Philippe Poelvoorde
. - if one user inserts and retrieves the id, but between both one other has inserted something the id returned will be the right one? Last_insert_id() is consistent on a per-connection basis, meaning you don't need to use lock (hopefullly !) http://dev.mysql.com/doc/mysql/en/getting-unique

Re: last_insert_id

2005-02-15 Thread mel list_php
To: mel list_php [EMAIL PROTECTED] CC: mysql@lists.mysql.com Subject: Re: last_insert_id Date: Tue, 15 Feb 2005 10:50:40 + mel list_php wrote: Hi! I have a database where several users can connect and input data. I managed to have my insert queries as atomic, but I was wondering about one special

Re: last_insert_id

2005-02-15 Thread mel list_php
-To: 'mysql@lists.mysql.com ' mysql@lists.mysql.com To: mel list_php [EMAIL PROTECTED] CC: mysql@lists.mysql.com Subject: Re: last_insert_id Date: Tue, 15 Feb 2005 10:50:40 + mel list_php wrote: Hi! I have a database where several users can connect and input data. I managed to have my insert queries

Re: last_insert_id

2005-02-15 Thread mel list_php
at the beginning of each script. This seems fine to me as I don't want to lock the tables, and the last_insert_id is performed in the same file than the insert, so on the per connection basis it's perfect (thank you very much for your help!!). But it seems a bit strange to me to open so many connections. I

Re: Rollback and INSERT_ID() or LAST_INSERT_ID()

2005-01-18 Thread Joerg Bruehe
Hi! Am Di, den 18.01.2005 schrieb Paul DuBois um 3:53: At 21:27 -0500 1/17/05, Andre Matos wrote: Thanks Eric, but I can let it increment because I cannot have a gave in the numbers. I think I will need to use MAX() in this case. Using MAX() won't guarantee that you won't have gaps. What

Re: Rollback and INSERT_ID() or LAST_INSERT_ID()

2005-01-18 Thread Clint Edwards
and INSERT_ID() or LAST_INSERT_ID() Date: Tue, 18 Jan 2005 11:08:40 +0100 Hi! Am Di, den 18.01.2005 schrieb Paul DuBois um 3:53: At 21:27 -0500 1/17/05, Andre Matos wrote: Thanks Eric, but I can let it increment because I cannot have a gave in the numbers. I think I will need to use MAX

Rollback and INSERT_ID() or LAST_INSERT_ID()

2005-01-17 Thread Andre Matos
Hi List, I have a field in one of my tables that uses auto-increment from MySQL 4.1.8-nt (Windows XP). My problem is to get the last insert ID when the insert fails and I use rollback. The MySQL is still incrementing the field. How can I avoid this if it is possible? I am trying to avoid to use

Re: Rollback and INSERT_ID() or LAST_INSERT_ID()

2005-01-17 Thread Eric Bergen
Just let it increment. Keeping it incremented is MySQL's way ot insuring that the same id doesn't get used twice for different records. It's doing everything correctly. -Eric On Mon, 17 Jan 2005 19:06:45 -0500, Andre Matos [EMAIL PROTECTED] wrote: Hi List, I have a field in one of my tables

Re: Rollback and INSERT_ID() or LAST_INSERT_ID()

2005-01-17 Thread Andre Matos
Thanks Eric, but I can let it increment because I cannot have a gave in the numbers. I think I will need to use MAX() in this case. Thanks. Andre On 1/17/05 8:14 PM, Eric Bergen [EMAIL PROTECTED] wrote: Just let it increment. Keeping it incremented is MySQL's way ot insuring that the same

Re: Rollback and INSERT_ID() or LAST_INSERT_ID()

2005-01-17 Thread Paul DuBois
At 21:27 -0500 1/17/05, Andre Matos wrote: Thanks Eric, but I can let it increment because I cannot have a gave in the numbers. I think I will need to use MAX() in this case. Using MAX() won't guarantee that you won't have gaps. What you're describing cannot be achieved in the general case.

Re: Rollback and INSERT_ID() or LAST_INSERT_ID()

2005-01-17 Thread Andre Matos
Yes, I know about this. What I plan is to remove the auto_increment. I will do this by hand locking the entire table just right before inserting the field. Actually, it is running like this. I am just upgrading the PHP. I will keep the auto_increment in other tables that does not have this kind

Re: last_insert_id() and load data infile

2004-12-25 Thread Gleb Paharenko
Hello. As said at: http://dev.mysql.com/doc/mysql/en/Information_functions.html If you insert many rows at the same time with an insert statement, LAST_INSERT_ID() returns the value for the first inserted row. LOAD DATA INFILE inserts several rows a time, so this is a usual behavior

last_insert_id() and load data infile

2004-12-22 Thread Martin d'Anjou
Hi, I am trying to find in the manual what select last_insert_id() will return after a load data infile command is executed. From my experiments, it returns the id of the FIRST record in the file, I would have expected the LAST, but that is not the case. Is that documented somewhere? Can I

RE: DBI and last_insert_id()

2004-06-15 Thread Paul McNeil
You wrote $pk = $dbh-last_insert_id(); I believe you can get the created ID with the query, Select @@IDENTITY; This returns the last created ID from the connector object. Peace -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe

RE: DBI and last_insert_id()

2004-06-15 Thread Paul McNeil
last_insert_id() should work. You are updating using @bind_values. What is the text of that? Does it indeed create a record? God Bless Paul C. McNeil Developer in Java, MS-SQL, MySQL, and web technologies. GOD BLESS AMERICA! To God Be The Glory! -Original Message

Re: DBI and last_insert_id()

2004-06-15 Thread Daniel Kasak
Paul McNeil wrote: last_insert_id() should work. You are updating using @bind_values. What is the text of that? Does it indeed create a record? @bind_values is an array of values that gets populated from my form. It has the same number of elements as the number of placeholders in my SQL

Re: DBI and last_insert_id()

2004-06-15 Thread Garth Webb
last_insert_id() function. I have so far: eval { $sth-execute (@bind_values) || die $dbh-errstr; }; # If the above failed, there will be something in the special variable $@ if ($@) { # Dialog explaining error... my $dialog

Re: DBI and last_insert_id()

2004-06-15 Thread William R. Mussatto
with DBI's last_insert_id() function. I have so far: eval { $sth-execute (@bind_values) || die $dbh-errstr; }; # If the above failed, there will be something in the special variable $@ if ($@) { # Dialog explaining error... my $dialog

DBI and last_insert_id()

2004-06-14 Thread Daniel Kasak
Hi all. I'm writing an app in Perl / Gtk2, and I'm having trouble with DBI's last_insert_id() function. I have so far: eval { $sth-execute (@bind_values) || die $dbh-errstr; }; # If the above failed, there will be something in the special variable

Re: last_insert_id() value not updated

2004-06-02 Thread Victoria Reznichenko
paqogomez [EMAIL PROTECTED] wrote: I am trying to build a stored procedure in v. 5. This is what I have so far. delimiter | create procedure get_id(out oid int) begin insert into mercury.merchant (name) values(null); select last_insert_id() into @mid; insert

last_insert_id() value not updated

2004-06-01 Thread paqogomez
I am trying to build a stored procedure in v. 5. This is what I have so far. delimiter | create procedure get_id(out oid int) begin insert into mercury.merchant (name) values(null); select last_insert_id() into @mid; insert into mercury.customers( address1 ) values (null); select

LAST_INSERT_ID() and Stored Procs

2004-04-22 Thread Matt Chatterley
Hi all. Another hiccup along the happy road with MySQL 5.0! The last bit of a stored procedure I have just put together does this: -- insert cluster row INSERT INTO clusters (Name) VALUES (sName); SELECT LAST_INSERT_ID() INTO iNewClusterID; -- insert map row INSERT INTO map (X, Y) VALUES (iX

RE: LAST_INSERT_ID() and Stored Procs

2004-04-22 Thread Matt Chatterley
, Matt -Original Message- From: Matt Chatterley [mailto:[EMAIL PROTECTED] Sent: 23 April 2004 02:08 To: 'MySQL List' Subject: LAST_INSERT_ID() and Stored Procs Hi all. Another hiccup along the happy road with MySQL 5.0! The last bit of a stored procedure I have just put together

Changing LAST_INSERT_ID()/AUTO_INCREMENT()

2003-10-19 Thread Jason Williard
I have a ticketing system that sets the ID of the ticket as the LAST_INSERT_ID. By default, it was counting up from 0. I updated the ID of the last ticket to reflect a different numbering scheme (MM). I would like to automate this but I don't want to change the ID of a current ticket

Re: Changing LAST_INSERT_ID()/AUTO_INCREMENT()

2003-10-19 Thread Mark V
Hi Jason, For MyISAM tables only, you can manually set the auto increment counter using the syntax: ALTER TABLE table_name AUTO_INCREMENT = 1000 Keep in mind, however, that this does not change the value of the LAST_INSERT_ID() since it still represents the value last inserted. On a freshly

RE: Changing LAST_INSERT_ID()/AUTO_INCREMENT()

2003-10-19 Thread Jason Williard
Thanks, Mark, for the syntax. I had actually played around enough to figure it out already and got it to work the way that I wanted to. I guess when I asked the question, I wasn't fully aware of what I was wanting. The LAST_INSERT_ID wasn't a major issue. I ended up using the following code

last_insert_id()

2003-09-24 Thread R.Dobson
Hi, Is it possible to obtain the last_insert_id() for a particular column in a particular table? eg, say i wanted to obtain the last insert id of a column called id in table reference, something along the lines of: last_insert_id(reference.id) The reason I ask is because I want to initially

Re: last_insert_id()

2003-09-24 Thread William R. Mussatto
R.Dobson said: Hi, Is it possible to obtain the last_insert_id() for a particular column in a particular table? eg, say i wanted to obtain the last insert id of a column called id in table reference, something along the lines of: last_insert_id(reference.id) The reason I ask is because

Re: last_insert_id()

2003-09-24 Thread Haydies
Don't forget that if you commit then last_insert_id will return 0 - Original Message - From: William R. Mussatto [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 24, 2003 6:56 PM Subject: Re: last_insert_id() : R.Dobson said: : Hi, : : Is it possible to obtain

Re: LAST_INSERT_ID() returns different values on different connections

2003-06-24 Thread Paul DuBois
At 16:02 +0300 6/17/03, Baris Akin wrote: Hello, I try to get last inserted autoincrement record ID on table with LAST_INSERT_ID() function (SELECT LAST_INSERT_ID() FROM TABLE). Every connection returns it's own last inserted ID not actual ID. Is this a bug? Also it returns more than one

LAST_INSERT_ID() returns different values on different connections

2003-06-17 Thread Baris Akin
Hello, I try to get last inserted autoincrement record ID on table with LAST_INSERT_ID() function (SELECT LAST_INSERT_ID() FROM TABLE). Every connection returns it's own last inserted ID not actual ID. Is this a bug? Also it returns more than one record (20 rows). Thanks Baris AKIN

Re: LAST_INSERT_ID() returns different values on different connections

2003-06-17 Thread Fred van Engen
On Tue, Jun 17, 2003 at 04:02:46PM +0300, Baris Akin wrote: I try to get last inserted autoincrement record ID on table with LAST_INSERT_ID() function (SELECT LAST_INSERT_ID() FROM TABLE). Every connection returns it's own last inserted ID not actual ID. Is this a bug? Also it returns more

Re: LAST_INSERT_ID() returns different values on different connections

2003-06-17 Thread Victoria Reznichenko
Baris Akin [EMAIL PROTECTED] wrote: LAST_INSERT_ID() function (SELECT LAST_INSERT_ID() FROM TABLE). Every connection returns it's own last inserted ID not actual ID. Is this a bug? No. LAST_INSERT_ID() works per-connection. It returns the last inserted auto_increment value from current

Autoincrement/last_insert_id race safe?

2003-03-26 Thread Steve Rapaport
A programmer just asked me about a possible race condition, and I didn't know what to answer: If I insert a line using autoincrement, then ask for last_insert_id() am I guaranteed to get the same ID I just inserted? It seems that another program could be inserting at almost the same time

Re: Autoincrement/last_insert_id race safe?

2003-03-26 Thread Fred van Engen
Hi, On Wed, Mar 26, 2003 at 03:17:42PM +0100, Steve Rapaport wrote: A programmer just asked me about a possible race condition, and I didn't know what to answer: If I insert a line using autoincrement, then ask for last_insert_id() am I guaranteed to get the same ID I just inserted

Re: Autoincrement/last_insert_id race safe?

2003-03-26 Thread Alec . Cawley
A programmer just asked me about a possible race condition, and I didn't know what to answer: If I insert a line using autoincrement, then ask for last_insert_id() am I guaranteed to get the same ID I just inserted? Yes It seems that another program could be inserting at almost the same

Re: Autoincrement/last_insert_id race safe?

2003-03-26 Thread Ray
On Wednesday 26 March 2003 08:25, you wrote: A programmer just asked me about a possible race condition, and I didn't know what to answer: If I insert a line using autoincrement, then ask for last_insert_id() am I guaranteed to get the same ID I just inserted? Yes It seems

re: Bug: last_insert_id() not replicated correctly

2003-03-20 Thread Victoria Reznichenko
, - b INT UNSIGNED NOT NULL, - PRIMARY KEY (a) - ); Query OK, 0 rows affected (0.02 sec) mysql INSERT INTO test (b) VALUES (1); Query OK, 1 row affected (0.01 sec) mysql INSERT INTO test (b) VALUES (LAST_INSERT_ID()); Query OK, 1 row affected (0.00 sec) mysql INSERT

Bug: last_insert_id() not replicated correctly

2003-03-18 Thread Chris Wilson
KEY (a) - ); Query OK, 0 rows affected (0.02 sec) mysql INSERT INTO test (b) VALUES (1); Query OK, 1 row affected (0.01 sec) mysql INSERT INTO test (b) VALUES (LAST_INSERT_ID()); Query OK, 1 row affected (0.00 sec) mysql INSERT INTO test (b) VALUES (LAST_INSERT_ID()); Query OK, 1 row affected

Re: Connector J (3.1.0) - invalid return upon select last_insert_id()

2003-03-02 Thread Mark Matthews
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Tea Yu wrote: Not really, I substituted the queryStmt with the actual one but it gave the same result. After some work: select last_insert_id();//getInt() should return 14 //but now it gives

Re: Connector J (3.1.0) - invalid return upon select last_insert_id()

2003-03-02 Thread Tea Yu
The only way I can debug this is if you give me a repeatable test case. Since the test case I showed you does not repeat the bug, you will need to generate a standalone test case, with schema, data, and the java code that demonstrates the issue. -Mark Hey mark, here are the files that

Re: Connector J (3.1.0) - invalid return upon select last_insert_id()

2003-03-01 Thread Mark Matthews
VARCHAR(255), primary key (id)); 2) here is the code segment String insertStmt = insert into test (name) values ('hi'); String queryStmt = select last_insert_id(); try { stmt.executeUpdate(insertStmt); ResultSet rs = stmt.executeQuery(queryStmt); if(rs.next()) System.out.println(last

Re: Connector J (3.1.0) - invalid return upon select last_insert_id()

2003-02-28 Thread Tea Yu
insert into TABLE (name) values ('test'); select last_insert_id() from TABLE; but got the Exception java.sql.SQLException: Invalid value for getInt() - 'q' while successive running of program returns 'r', 's', 't'... Query from console returns the correct result, but it returns n rows

Re: Connector J (3.1.0) - invalid return upon select last_insert_id()

2003-02-28 Thread Mark Matthews
auto_increment, name varchar(255)) and did an SQLQuery thru JDBC insert into TABLE (name) values ('test'); select last_insert_id() from TABLE; but got the Exception java.sql.SQLException: Invalid value for getInt() - 'q' while successive running of program returns 'r', 's', 't

Re: Connector J (3.1.0) - invalid return upon select last_insert_id()

2003-02-28 Thread gerald_clark
You don't select last_insert_id() from table. This will return the last_insert_id() for each row of the table. You just select last_insert_id(). Tea Yu wrote: Hi! I just tried Windows ME + MySQL Server - 4.0.9/4.0.11 + ConnectorJ - 3.0.4/3.0.6/3.1.0 with an InnoDB table test (id

Re: Connector J (3.1.0) - invalid return upon select last_insert_id()

2003-02-28 Thread Tea Yu
(id int not null auto_increment, name varchar(255)) and did an SQLQuery thru JDBC insert into TABLE (name) values ('test'); select last_insert_id() from TABLE; but got the Exception java.sql.SQLException: Invalid value for getInt() - 'q' while successive running

Re: Connector J (3.1.0) - invalid return upon select last_insert_id()

2003-02-28 Thread Tea Yu
Yea thanks for correct this, so I'm getting the right resultSet in console... but still having problem thru ConnectorJ, select last_insert_id() returns a String to me, rs.getString(1) throws no exception. Tea You don't select last_insert_id() from table. This will return

Re: Connector J (3.1.0) - invalid return upon select last_insert_id()

2003-02-28 Thread Mark Matthews
, name varchar(255)) also tried test (id int not null auto_increment, name varchar(255)) and did an SQLQuery thru JDBC insert into TABLE (name) values ('test'); select last_insert_id() from TABLE; but got the Exception java.sql.SQLException: Invalid value for getInt() - 'q' while successive

Re: Connector J (3.1.0) - invalid return upon select last_insert_id()

2003-02-28 Thread Tea Yu
is the code segment String insertStmt = insert into test (name) values ('hi'); String queryStmt = select last_insert_id(); try { stmt.executeUpdate(insertStmt); ResultSet rs = stmt.executeQuery(queryStmt); if(rs.next()) System.out.println(last insert id

last_insert_id() returns 0 in windows

2003-02-02 Thread Alan
Okay, I've seen just about every question on last_insert_id(), except this one: I am running MySQL on Win XP and when I generate a test table (test) with an AUTO_INCREMENT column (aid) and a second column (a) then use an insert statement like: INSERT INTO test (a) values (1); then: SELECT

Re: last_insert_id() returns 0 in windows

2003-02-02 Thread Dan Nelson
In the last episode (Feb 01), Alan said: Okay, I've seen just about every question on last_insert_id(), except this one: I am running MySQL on Win XP and when I generate a test table (test) with an AUTO_INCREMENT column (aid) and a second column (a) then use an insert statement like: INSERT

Re: Re: last_insert_id() returns 0 in windows

2003-02-02 Thread Nasser Ossareh
about every question on last_insert_id(), except this one: I am running MySQL on Win XP and when I generate a test table (test) with an AUTO_INCREMENT column (aid) and a second column (a) then use an insert statement like: INSERT INTO test (a) values (1); then: SELECT LAST_INSERT_ID(); I get

Re: Accessing last_insert_id problem.

2003-01-02 Thread Matthew Smith
LAST_INSERT_ID is held for the database connection, not agaist the server So, as long as you do not do another insert using the same database connection, LAST_INSERT_ID will be fine. (for database connection, $dbh=DBI-connect. ) No table locking required. Regards M On Wed, 18 Dec 2002

RE: Accessing last_insert_id problem.

2002-12-20 Thread Will Merrell
Jeff Snoxell wrote: At 09:46 19/12/02 -0500, you wrote: Jeff Snoxell wrote: Nope. That doesn't do it either! I go: TRUNCATE TABLE my_table Are you using InnoDB tables? You'll have to do something akin to ALTER TABLE my_table AUTO_INCREMENT=1 ... at least according to Paul ... :)

re: Accessing last_insert_id problem.

2002-12-19 Thread Jeff Snoxell
I'm working with MySQL 3.23.36 so, according to MySQL, Paul Dubois, New Riders running the query: DELETE FROM my_table_name should reset the auto-increment value... but it doesnt'. What SQL do I use to reset the val. You can't believe anything that book says. The author didn't even include

re: Accessing last_insert_id problem.

2002-12-19 Thread Wico de Leeuw
http://www.mysql.com/doc/en/SET_OPTION.html last option(s) maybe you can do somehting with that Gr At 10:54 19-12-02 +, Jeff Snoxell wrote: I'm working with MySQL 3.23.36 so, according to MySQL, Paul Dubois, New Riders running the query: DELETE FROM my_table_name should reset the

  1   2   >