summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorunknown <pem@mysql.comhem.se>2004-03-25 17:42:13 +0100
committerunknown <pem@mysql.comhem.se>2004-03-25 17:42:13 +0100
commitdf06466976e3d9e63ed8f95e5543578b7ec572ac (patch)
treeb848643a5a893df72a10e6264bc0406b6c9ec236 /tests
parentd8c5358115abb7134943a8ec9b1f2ec0fabcae26 (diff)
downloadmariadb-git-df06466976e3d9e63ed8f95e5543578b7ec572ac.tar.gz
Fixed BUG#3117: LAST_INSERT_ID() works incorrectly inside stored procedure.
This turned out to be a problem for prepared statements as well; the id was evaluated once, at parse time. mysql-test/r/auto_increment.result: Updated results after bugfix in last_insert_id(). mysql-test/r/query_cache.result: Updated results after bugfix in last_insert_id(). mysql-test/r/variables.result: Updated results after bugfix in last_insert_id(). sql/item_func.cc: Fixed bug in last_insert_id(); get id at each evaluation (and not in the parser). Renamed the class Item_func_set_last_insert_id too, since it's not only for setting. sql/item_func.h: Fixed bug in last_insert_id(); get id at each evaluation (and not in the parser). Renamed the class Item_func_set_last_insert_id too, since it's not only for setting. sql/sql_yacc.yy: Fixed bug in last_insert_id(); get id at each evaluation (and not in the parser). Renamed the class Item_func_set_last_insert_id too, since it's not only for setting. tests/client_test.c: Test case for last_insert_id() in prepared statements.
Diffstat (limited to 'tests')
-rw-r--r--tests/client_test.c65
1 files changed, 63 insertions, 2 deletions
diff --git a/tests/client_test.c b/tests/client_test.c
index 31a53f6d81e..bc30451deae 100644
--- a/tests/client_test.c
+++ b/tests/client_test.c
@@ -8377,6 +8377,68 @@ static void test_subqueries_ref()
myquery(rc);
}
+static void test_bug3117()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND buffer;
+ longlong lii;
+ ulong length;
+ my_bool is_null;
+ int rc;
+
+ myheader("test_bug3117");
+
+ rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+ myquery(rc);
+
+ rc= mysql_query(mysql,"CREATE TABLE t1 (id int auto_increment primary key)");
+ myquery(rc);
+
+ stmt = mysql_simple_prepare(mysql, "SELECT LAST_INSERT_ID()");
+ mystmt_init(stmt);
+
+ rc= mysql_query(mysql, "INSERT INTO t1 VALUES (NULL)");
+ myquery(rc);
+
+ rc = mysql_execute(stmt);
+ mystmt(stmt,rc);
+
+ buffer.buffer_type= MYSQL_TYPE_LONGLONG;
+ buffer.buffer_length= sizeof(lii);
+ buffer.buffer= (char *)&lii;
+ buffer.length= &length;
+ buffer.is_null= &is_null;
+
+ rc= mysql_bind_result(stmt, &buffer);
+ mystmt(stmt,rc);
+
+ rc= mysql_stmt_store_result(stmt);
+ mystmt(stmt,rc);
+
+ rc = mysql_fetch(stmt);
+ mystmt(stmt, rc);
+
+ assert(is_null == 0 && lii == 1);
+ fprintf(stdout, "\n\tLAST_INSERT_ID() = 1 ok\n");
+
+ rc= mysql_query(mysql, "INSERT INTO t1 VALUES (NULL)");
+ myquery(rc);
+
+ rc = mysql_execute(stmt);
+ mystmt(stmt,rc);
+
+ rc = mysql_fetch(stmt);
+ mystmt(stmt, rc);
+
+ assert(is_null == 0 && lii == 2);
+ fprintf(stdout, "\tLAST_INSERT_ID() = 2 ok\n");
+
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "DROP TABLE t1");
+ myquery(rc);
+}
+
/*
Read and parse arguments and MySQL options from my.cnf
*/
@@ -8634,8 +8696,7 @@ int main(int argc, char **argv)
test_distinct(); /* distinct aggregate functions */
test_subqueries_ref(); /* outer reference in subqueries converted
Item_field -> Item_ref */
-
-
+ test_bug3117(); /* BUG#3117: LAST_INSERT_ID() */
end_time= time((time_t *)0);
total_time+= difftime(end_time, start_time);