summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorkroki/tomash@moonlight.intranet <>2006-10-06 13:34:07 +0400
committerkroki/tomash@moonlight.intranet <>2006-10-06 13:34:07 +0400
commitee0cebf9a7fa364df44aeb0579bdaa80d11f0125 (patch)
tree9d3af9e4d1ede2e842e8a4a18d1a01c0d66cf0ea /tests
parentacaa584c5523753cab5b3a50ed3c95672b462541 (diff)
downloadmariadb-git-ee0cebf9a7fa364df44aeb0579bdaa80d11f0125.tar.gz
BUG#21726: Incorrect result with multiple invocations of LAST_INSERT_ID.
Note: bug#21726 does not directly apply to 4.1, as it doesn't have stored procedures. However, 4.1 had some bugs that were fixed in 5.0 by the patch for bug#21726, and this patch is a backport of those fixes. Namely, in 4.1 it fixes: - LAST_INSERT_ID(expr) didn't return value of expr (4.1 specific). - LAST_INSERT_ID() could return the value generated by current statement if the call happens after the generation, like in CREATE TABLE t1 (i INT AUTO_INCREMENT PRIMARY KEY, j INT); INSERT INTO t1 VALUES (NULL, 0), (NULL, LAST_INSERT_ID()); - Redundant binary log LAST_INSERT_ID_EVENTs could be generated.
Diffstat (limited to 'tests')
-rw-r--r--tests/mysql_client_test.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 9fabde993b8..6ae9dcb9476 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -11909,6 +11909,43 @@ static void test_bug20152()
/*
+ Bug#21726: Incorrect result with multiple invocations of
+ LAST_INSERT_ID
+
+ Test that client gets updated value of insert_id on UPDATE that uses
+ LAST_INSERT_ID(expr).
+*/
+static void test_bug21726()
+{
+ const char *update_query = "UPDATE t1 SET i= LAST_INSERT_ID(i + 1)";
+ int rc;
+ my_ulonglong insert_id;
+
+ DBUG_ENTER("test_bug21726");
+ myheader("test_bug21726");
+
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+ myquery(rc);
+ rc= mysql_query(mysql, "CREATE TABLE t1 (i INT)");
+ myquery(rc);
+ rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)");
+ myquery(rc);
+
+ rc= mysql_query(mysql, update_query);
+ myquery(rc);
+ insert_id= mysql_insert_id(mysql);
+ DIE_UNLESS(insert_id == 2);
+
+ rc= mysql_query(mysql, update_query);
+ myquery(rc);
+ insert_id= mysql_insert_id(mysql);
+ DIE_UNLESS(insert_id == 3);
+
+ DBUG_VOID_RETURN;
+}
+
+
+/*
Read and parse arguments and MySQL options from my.cnf
*/
@@ -12134,6 +12171,7 @@ static struct my_tests_st my_tests[]= {
{ "test_bug12925", test_bug12925 },
{ "test_bug15613", test_bug15613 },
{ "test_bug20152", test_bug20152 },
+ { "test_bug21726", test_bug21726 },
{ 0, 0 }
};