diff options
author | unknown <bell@sanja.is.com.ua> | 2004-03-23 14:26:54 +0200 |
---|---|---|
committer | unknown <bell@sanja.is.com.ua> | 2004-03-23 14:26:54 +0200 |
commit | a36185af9a9c3da71a7e58772e494df91e3a6a8a (patch) | |
tree | 0ee4c065678c0345c7f253128ee7b46a70fde77f /tests/client_test.c | |
parent | 78b4ba746b79ea7d89044e3eecd56338a8f4eb6f (diff) | |
download | mariadb-git-a36185af9a9c3da71a7e58772e494df91e3a6a8a.tar.gz |
fixed union with prepared statement bug found by Konstantin
sql/sql_lex.cc:
initialisation for safety
sql/sql_union.cc:
item list should be saved in statement memory
tests/client_test.c:
test suite
Diffstat (limited to 'tests/client_test.c')
-rw-r--r-- | tests/client_test.c | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/tests/client_test.c b/tests/client_test.c index 31a53f6d81e..5aa48255a64 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -160,7 +160,10 @@ static void print_st_error(MYSQL_STMT *stmt, const char *msg) MYSQL_STMT *STDCALL mysql_simple_prepare(MYSQL *mysql, const char *query) { - return mysql_prepare(mysql, query, strlen(query)); + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + if (mysql_stmt_prepare(stmt, query, strlen(query))) + return 0; + return stmt; } @@ -8377,6 +8380,58 @@ static void test_subqueries_ref() myquery(rc); } + +static void test_union() +{ + MYSQL_STMT *stmt; + int rc; + + myheader("test_union"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2"); + myquery(rc); + + rc= mysql_query(mysql, + "CREATE TABLE t1 " + "(id INTEGER NOT NULL PRIMARY KEY, " + " name VARCHAR(20) NOT NULL)"); + myquery(rc); + rc= mysql_query(mysql, + "INSERT INTO t1 (id, name) VALUES " + "(2, 'Ja'), (3, 'Ede'), " + "(4, 'Haag'), (5, 'Kabul'), " + "(6, 'Almere'), (7, 'Utrecht'), " + "(8, 'Qandahar'), (9, 'Amsterdam'), " + "(10, 'Amersfoort'), (11, 'Constantine')"); + myquery(rc); + rc= mysql_query(mysql, + "CREATE TABLE t2 " + "(id INTEGER NOT NULL PRIMARY KEY, " + " name VARCHAR(20) NOT NULL)"); + myquery(rc); + rc= mysql_query(mysql, + "INSERT INTO t2 (id, name) VALUES " + "(4, 'Guam'), (5, 'Aruba'), " + "(6, 'Angola'), (7, 'Albania'), " + "(8, 'Anguilla'), (9, 'Argentina'), " + "(10, 'Azerbaijan'), (11, 'Afghanistan'), " + "(12, 'Burkina Faso'), (13, 'Faroe Islands')"); + myquery(rc); + + stmt= mysql_simple_prepare(mysql, + "SELECT t1.name FROM t1 UNION " + "SELECT t2.name FROM t2"); + mystmt_init(stmt); + + rc= mysql_stmt_execute(stmt); + mystmt(stmt,rc); + assert(20 == my_process_stmt_result(stmt)); + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1, t2"); + myquery(rc); +} + /* Read and parse arguments and MySQL options from my.cnf */ @@ -8634,8 +8689,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_union(); /* test union with prepared statements */ end_time= time((time_t *)0); total_time+= difftime(end_time, start_time); |