@@ -15526,6 +15526,75 @@ static void test_mysql_insert_id()
15526
15526
myquery(rc);
15527
15527
}
15528
15528
15529
+ /*
15530
+ Test for bug#22028117: MYSQLCLIENT DOES NOT RETURN CORRECT
15531
+ MYSQL_INSERT_ID VIA DATABASE HANDLE
15532
+ */
15533
+
15534
+ static void test_bug22028117()
15535
+ {
15536
+ my_ulonglong res;
15537
+ int rc;
15538
+ MYSQL_STMT *stmt;
15539
+
15540
+ myheader("test_bug22028117");
15541
+
15542
+ rc = mysql_query(mysql, "USE test");
15543
+ myquery(rc);
15544
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
15545
+ myquery(rc);
15546
+ rc= mysql_query(mysql, "CREATE TABLE t1 ("
15547
+ "f1 INT NOT NULL PRIMARY KEY AUTO_INCREMENT,"
15548
+ "f2 VARCHAR(255))");
15549
+ myquery(rc);
15550
+ res= mysql_insert_id(mysql);
15551
+ DIE_UNLESS(res == 0);
15552
+
15553
+ rc= mysql_query(mysql, "INSERT INTO t1 (f2) VALUES ('a')");
15554
+ myquery(rc);
15555
+ res= mysql_insert_id(mysql);
15556
+ DIE_UNLESS(res == 1);
15557
+
15558
+ rc= mysql_query(mysql, "INSERT INTO t1 (f2) VALUES ('b')");
15559
+ myquery(rc);
15560
+ res= mysql_insert_id(mysql);
15561
+ DIE_UNLESS(res == 2);
15562
+
15563
+ /* Make sure that the value of insert_id is not lost after SELECT */
15564
+ stmt= mysql_simple_prepare(mysql, "SELECT MAX(f1) FROM t1");
15565
+ check_stmt(stmt);
15566
+ rc= mysql_stmt_execute(stmt);
15567
+ check_execute(stmt, rc);
15568
+ rc= my_process_stmt_result(stmt);
15569
+ DIE_UNLESS(rc == 1);
15570
+ mysql_stmt_close(stmt);
15571
+
15572
+ res= mysql_insert_id(mysql);
15573
+ DIE_UNLESS(res == 2);
15574
+ /* insert_id will be reset to 0 after a new table is created */
15575
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS t2");
15576
+ myquery(rc);
15577
+
15578
+ rc= mysql_query(mysql, "CREATE TABLE t2 ("
15579
+ "f1 INT NOT NULL PRIMARY KEY AUTO_INCREMENT,"
15580
+ "f2 VARCHAR(255))");
15581
+ myquery(rc);
15582
+ res= mysql_insert_id(mysql);
15583
+ DIE_UNLESS(res == 0);
15584
+
15585
+ /*
15586
+ mysql_insert_id() should return expr when the INSERT query contains
15587
+ last_insert_id(expr)
15588
+ */
15589
+ rc= mysql_query(mysql, "INSERT INTO t1 (f1) VALUES (last_insert_id(100))");
15590
+ myquery(rc);
15591
+ res= mysql_insert_id(mysql);
15592
+ DIE_UNLESS(res == 100);
15593
+
15594
+ rc= mysql_query(mysql, "DROP TABLE t1,t2");
15595
+ myquery(rc);
15596
+ }
15597
+
15529
15598
/*
15530
15599
Bug#20152: mysql_stmt_execute() writes to MYSQL_TYPE_DATE buffer
15531
15600
*/
@@ -21177,6 +21246,7 @@ static struct my_tests_st my_tests[]= {
21177
21246
{ "test_bug22559575", test_bug22559575 },
21178
21247
{ "test_bug24963580", test_bug24963580 },
21179
21248
{ "test_mysql_binlog", test_mysql_binlog },
21249
+ { "test_bug22028117", test_bug22028117 },
21180
21250
{ 0, 0 }
21181
21251
};
21182
21252
0 commit comments