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
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
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
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
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
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
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
| |
++--+--+---++-+---++--++-+--+---+--+---+---++--+--+--+--+-+--+
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
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
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*
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
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
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:
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
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:
-- 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
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
) = 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
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
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
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
, 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
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
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
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
=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
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
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
(`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
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
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
.
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
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
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
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
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
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
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
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
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
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
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
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
?
- 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
.
- 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
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
-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
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
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
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
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
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
,
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
,
- 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
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
-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
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
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
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
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
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
(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
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
, 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
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
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
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
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
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
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 ... :)
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
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 - 100 of 190 matches
Mail list logo