Paul DuBois wrote:
> Yes, it should remain visible. The 0 return should happen only if you
> haven't generated an AUTO_INCREMENT value during the course of the
> connection yet.
Well, please try running the following:
-8<- C code -
#include <stdio.h>
#include "mysql.h"
#define DBHOST "WHEREVER"
#define DBUSER "WHATEVER"
#define DBPASSWD "WHATEVER"
#define DBDB "WHATEVER"
int main(void)
{
MYSQL con;
mysql_init(&con);
mysql_real_connect(&con, DBHOST, DBUSER, DBPASSWD, DBDB, 0, NULL,
0);
mysql_query(&con, "insert into a (val) values('test')");
printf("last insert id is %d\n", mysql_insert_id(&con));
mysql_query(&con, "insert into b (id,val)
values(last_insert_id(),'test')");
printf("last insert id is %d\n", mysql_insert_id(&con));
mysql_close(&con);
return 0;
}
-8<- C code -
The table definitions:
-8<- SQL -
CREATE TABLE a (
id tinyint not null auto_increment,
val varchar(10) not null,
PRIMARY KEY(id)
);
CREATE TABLE b (
id tinyint not null,
val varchar(10) not null,
PRIMARY KEY(id)
);
-8<- SQL -
On my system (with local server, ie 3.22.22) this prints "last insert id
is 1\nlast insert id is 0", but I expected it to print id 1 twice.
Can anyone confirm my observations?
Thanks a lot, Matthias
--
w e b f a c t o r y | matthias pigulla
www.webfactory.de mp@stripped