summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <pem@mysql.com>2004-03-25 17:48:00 +0100
committerunknown <pem@mysql.com>2004-03-25 17:48:00 +0100
commitd31bb74adeddabad3d708faf4cc264493a623416 (patch)
tree0795028fc3c1987590aa4d86fbb5e55b6a4278b2
parentbdb874226efb55979eb8eef909f050ba6f949ab8 (diff)
parentdf06466976e3d9e63ed8f95e5543578b7ec572ac (diff)
downloadmariadb-git-d31bb74adeddabad3d708faf4cc264493a623416.tar.gz
Merge fix.
sql/sql_yacc.yy: Auto merged tests/client_test.c: Merge fix (two new test cases at the same time).
-rw-r--r--mysql-test/r/auto_increment.result2
-rw-r--r--mysql-test/r/query_cache.result2
-rw-r--r--mysql-test/r/variables.result2
-rw-r--r--sql/item_func.cc19
-rw-r--r--sql/item_func.h7
-rw-r--r--sql/sql_yacc.yy5
-rw-r--r--tests/client_test.c63
7 files changed, 86 insertions, 14 deletions
diff --git a/mysql-test/r/auto_increment.result b/mysql-test/r/auto_increment.result
index 8f77b306d3e..9541fa6d355 100644
--- a/mysql-test/r/auto_increment.result
+++ b/mysql-test/r/auto_increment.result
@@ -142,7 +142,7 @@ explain extended select last_insert_id();
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 select high_priority no_cache 255 AS `last_insert_id()`
+Note 1003 select high_priority no_cache last_insert_id() AS `last_insert_id()`
insert into t1 set i = 254;
ERROR 23000: Duplicate entry '254' for key 1
select last_insert_id();
diff --git a/mysql-test/r/query_cache.result b/mysql-test/r/query_cache.result
index 85bc50ef708..bbba7026b14 100644
--- a/mysql-test/r/query_cache.result
+++ b/mysql-test/r/query_cache.result
@@ -292,7 +292,7 @@ DATABASE()
select ENCRYPT("test") from t1;
ENCRYPT("test")
select LAST_INSERT_ID() from t1;
-last_insert_id()
+LAST_INSERT_ID()
select RAND() from t1;
RAND()
select UNIX_TIMESTAMP() from t1;
diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result
index 8934cd705b6..ab550026dbc 100644
--- a/mysql-test/r/variables.result
+++ b/mysql-test/r/variables.result
@@ -93,7 +93,7 @@ explain extended select @@IDENTITY,last_insert_id(), @@identity;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 select high_priority no_cache 345 AS `@@IDENTITY`,345 AS `last_insert_id()`,345 AS `@@identity`
+Note 1003 select high_priority no_cache 345 AS `@@IDENTITY`,last_insert_id() AS `last_insert_id()`,345 AS `@@identity`
set big_tables=OFF, big_tables=ON, big_tables=0, big_tables=1, big_tables="OFF", big_tables="ON";
set global concurrent_insert=ON;
show variables like 'concurrent_insert';
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 5151fb2876d..9f80686e72c 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2139,13 +2139,22 @@ longlong Item_func_release_lock::val_int()
}
-longlong Item_func_set_last_insert_id::val_int()
+longlong Item_func_last_insert_id::val_int()
{
DBUG_ASSERT(fixed == 1);
- longlong value=args[0]->val_int();
- current_thd->insert_id(value);
- null_value=args[0]->null_value;
- return value;
+ if (arg_count)
+ {
+ longlong value=args[0]->val_int();
+ current_thd->insert_id(value);
+ null_value=args[0]->null_value;
+ return value;
+ }
+ else
+ {
+ Item *it= get_system_var(current_thd, OPT_SESSION, "last_insert_id", 14,
+ "last_insert_id()");
+ return it->val_int();
+ }
}
/* This function is just used to test speed of different functions */
diff --git a/sql/item_func.h b/sql/item_func.h
index 4558c1c6f62..4142498af6c 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -729,13 +729,14 @@ public:
};
-class Item_func_set_last_insert_id :public Item_int_func
+class Item_func_last_insert_id :public Item_int_func
{
public:
- Item_func_set_last_insert_id(Item *a) :Item_int_func(a) {}
+ Item_func_last_insert_id() :Item_int_func() {}
+ Item_func_last_insert_id(Item *a) :Item_int_func(a) {}
longlong val_int();
const char *func_name() const { return "last_insert_id"; }
- void fix_length_and_dec() { max_length=args[0]->max_length; }
+ void fix_length_and_dec() { if (arg_count) max_length= args[0]->max_length; }
};
class Item_func_benchmark :public Item_int_func
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 2ba4a74c963..8184ea366d9 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -2750,13 +2750,12 @@ simple_expr:
}
| LAST_INSERT_ID '(' ')'
{
- $$= get_system_var(YYTHD, OPT_SESSION, "last_insert_id", 14,
- "last_insert_id()");
+ $$= new Item_func_last_insert_id();
Lex->safe_to_cache_query= 0;
}
| LAST_INSERT_ID '(' expr ')'
{
- $$= new Item_func_set_last_insert_id($3);
+ $$= new Item_func_last_insert_id($3);
Lex->safe_to_cache_query= 0;
}
| LEFT '(' expr ',' expr ')'
diff --git a/tests/client_test.c b/tests/client_test.c
index 5aa48255a64..b50c9d58dc6 100644
--- a/tests/client_test.c
+++ b/tests/client_test.c
@@ -8432,6 +8432,68 @@ static void test_union()
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
*/
@@ -8690,6 +8752,7 @@ int main(int argc, char **argv)
test_subqueries_ref(); /* outer reference in subqueries converted
Item_field -> Item_ref */
test_union(); /* test union with prepared statements */
+ test_bug3117(); /* BUG#3117: LAST_INSERT_ID() */
end_time= time((time_t *)0);
total_time+= difftime(end_time, start_time);