diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 11 | ||||
-rw-r--r-- | tests/bug25714.c | 3 | ||||
-rwxr-xr-x | tests/fork_big.pl | 2 | ||||
-rw-r--r-- | tests/fork_big2.pl | 2 | ||||
-rwxr-xr-x | tests/mail_to_db.pl | 2 | ||||
-rw-r--r-- | tests/mysql_client_test.c | 2604 | ||||
-rw-r--r-- | tests/thread_test.c | 28 |
7 files changed, 2011 insertions, 641 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 1c39a3630dd..ddc6da86e1c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -17,6 +17,13 @@ ## Process this file with automake to create Makefile.in + +if THREAD_SAFE_CLIENT +LIBMYSQLCLIENT_LA = $(top_builddir)/libmysql_r/libmysqlclient_r.la +else +LIBMYSQLCLIENT_LA = $(top_builddir)/libmysql/libmysqlclient.la +endif + EXTRA_DIST = auto_increment.res auto_increment.tst \ function.res function.tst lock_test.pl lock_test.res \ export.pl big_record.pl \ @@ -34,7 +41,7 @@ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ $(openssl_includes) LIBS = @CLIENT_LIBS@ LDADD = @CLIENT_EXTRA_LDFLAGS@ \ - $(top_builddir)/libmysql/libmysqlclient.la + $(LIBMYSQLCLIENT_LA) mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS) mysql_client_test_SOURCES= mysql_client_test.c\ @@ -49,7 +56,7 @@ bug25714_SOURCES= bug25714.c bug25714_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) # Fix for mit-threads -DEFS = -DUNDEF_THREADS_HACK +DEFS = -DMYSQL_CLIENT_NO_THREADS thread_test.o: thread_test.c $(COMPILE) -c $(INCLUDES) $< diff --git a/tests/bug25714.c b/tests/bug25714.c index b9c0708f352..c0d9fbf7652 100644 --- a/tests/bug25714.c +++ b/tests/bug25714.c @@ -72,4 +72,5 @@ int main (int argc, char **argv) my_end(0); return 0; -}; +} + diff --git a/tests/fork_big.pl b/tests/fork_big.pl index c72eb59946b..5c4f11b00e2 100755 --- a/tests/fork_big.pl +++ b/tests/fork_big.pl @@ -65,7 +65,7 @@ if (!$opt_skip_create) } # Create the table we use to signal that we should end the test $dbh->do("drop table if exists $abort_table"); - $dbh->do("create table $abort_table (id int(6) not null) type=heap") || + $dbh->do("create table $abort_table (id int(6) not null) ENGINE=heap") || die $DBI::errstr; } diff --git a/tests/fork_big2.pl b/tests/fork_big2.pl index 567cfafa176..8a0c5e317a0 100644 --- a/tests/fork_big2.pl +++ b/tests/fork_big2.pl @@ -89,7 +89,7 @@ if (!$opt_skip_create) } # Create the table we use to signal that we should end the test $dbh->do("drop table if exists $abort_table"); - $dbh->do("create table $abort_table (id int(6) not null) type=heap") || + $dbh->do("create table $abort_table (id int(6) not null) ENGINE=heap") || die $DBI::errstr; } diff --git a/tests/mail_to_db.pl b/tests/mail_to_db.pl index 5ceda392313..e50415d96f3 100755 --- a/tests/mail_to_db.pl +++ b/tests/mail_to_db.pl @@ -253,7 +253,7 @@ CREATE TABLE my_mail KEY (message_id), KEY (in_reply_to), PRIMARY KEY (mail_from, date, hash)) - TYPE=MyISAM COMMENT='' + ENGINE=MyISAM COMMENT='' EOF $sth = $dbh->prepare($query) or die $DBI::errstr; $sth->execute() or die "Couldn't create table: $DBI::errstr\n"; diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 63137bdba93..9d61d6edd3e 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -32,6 +32,7 @@ #include <errmsg.h> #include <my_getopt.h> #include <m_string.h> +#include <mysqld_error.h> #define VER "2.1" #define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */ @@ -82,6 +83,7 @@ struct my_tests_st }; #define myheader(str) \ +DBUG_PRINT("test", ("name: %s", str)); \ if (opt_silent < 2) \ { \ fprintf(stdout, "\n\n#####################################\n"); \ @@ -89,7 +91,9 @@ if (opt_silent < 2) \ opt_count, str); \ fprintf(stdout, " \n#####################################\n"); \ } + #define myheader_r(str) \ +DBUG_PRINT("test", ("name: %s", str)); \ if (!opt_silent) \ { \ fprintf(stdout, "\n\n#####################################\n"); \ @@ -99,7 +103,7 @@ if (!opt_silent) \ static void print_error(const char *msg); static void print_st_error(MYSQL_STMT *stmt, const char *msg); -static void client_disconnect(void); +static void client_disconnect(MYSQL* mysql, my_bool drop_db); /* @@ -175,8 +179,8 @@ if (stmt == 0) \ DIE_UNLESS(stmt == 0);\ } -#define mytest(x) if (!x) {myerror(NULL);DIE_UNLESS(FALSE);} -#define mytest_r(x) if (x) {myerror(NULL);DIE_UNLESS(FALSE);} +#define mytest(x) if (!(x)) {myerror(NULL);DIE_UNLESS(FALSE);} +#define mytest_r(x) if ((x)) {myerror(NULL);DIE_UNLESS(FALSE);} /* A workaround for Sun Forte 5.6 on Solaris x86 */ @@ -267,10 +271,20 @@ mysql_simple_prepare(MYSQL *mysql_arg, const char *query) } -/* Connect to the server */ - -static void client_connect(ulong flag) +/** + Connect to the server with options given by arguments to this application, + stored in global variables opt_host, opt_user, opt_password, opt_db, + opt_port and opt_unix_socket. + + @param flag[in] client_flag passed on to mysql_real_connect + @param protocol[in] MYSQL_PROTOCOL_* to use for this connection + @param auto_reconnect[in] set to 1 for auto reconnect + + @return pointer to initialized and connected MYSQL object +*/ +static MYSQL* client_connect(ulong flag, uint protocol, my_bool auto_reconnect) { + MYSQL* mysql; int rc; static char query[MAX_TEST_QUERY_LENGTH]; myheader_r("client_connect"); @@ -285,6 +299,9 @@ static void client_connect(ulong flag) myerror("mysql_init() failed"); exit(1); } + /* enable local infile, in non-binary builds often disabled by default */ + mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, 0); + mysql_options(mysql, MYSQL_OPT_PROTOCOL, &protocol); if (!(mysql_real_connect(mysql, opt_host, opt_user, opt_password, opt_db ? opt_db:"test", opt_port, @@ -296,10 +313,10 @@ static void client_connect(ulong flag) fprintf(stdout, "\n Check the connection options using --help or -?\n"); exit(1); } - mysql->reconnect= 1; + mysql->reconnect= auto_reconnect; if (!opt_silent) - fprintf(stdout, " OK"); + fprintf(stdout, "OK"); /* set AUTOCOMMIT to ON*/ mysql_autocommit(mysql, TRUE); @@ -322,13 +339,15 @@ static void client_connect(ulong flag) have_innodb= check_have_innodb(mysql); if (!opt_silent) - fprintf(stdout, " OK"); + fprintf(stdout, "OK"); + + return mysql; } /* Close the connection */ -static void client_disconnect() +static void client_disconnect(MYSQL* mysql, my_bool drop_db) { static char query[MAX_TEST_QUERY_LENGTH]; @@ -336,18 +355,22 @@ static void client_disconnect() if (mysql) { - if (!opt_silent) - fprintf(stdout, "\n dropping the test database '%s' ...", current_db); - strxmov(query, "DROP DATABASE IF EXISTS ", current_db, NullS); + if (drop_db) + { + if (!opt_silent) + fprintf(stdout, "\n dropping the test database '%s' ...", current_db); + strxmov(query, "DROP DATABASE IF EXISTS ", current_db, NullS); - mysql_query(mysql, query); - if (!opt_silent) - fprintf(stdout, " OK"); + mysql_query(mysql, query); + if (!opt_silent) + fprintf(stdout, "OK"); + } if (!opt_silent) fprintf(stdout, "\n closing the connection ..."); mysql_close(mysql); - fprintf(stdout, " OK\n"); + if (!opt_silent) + fprintf(stdout, "OK\n"); } } @@ -438,7 +461,7 @@ static void my_print_result_metadata(MYSQL_RES *result) for(i= 0; i< field_count; i++) { field= mysql_fetch_field(result); - j= (uint) strlen(field->name); + j= strlen(field->name); if (j < field->max_length) j= field->max_length; if (j < 4 && !IS_NOT_NULL(field->flags)) @@ -964,7 +987,7 @@ void stmt_fetch_init(Stmt_fetch *fetch, unsigned stmt_no_arg, fetch->handle= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(fetch->handle, fetch->query, (uint) strlen(fetch->query)); + rc= mysql_stmt_prepare(fetch->handle, fetch->query, strlen(fetch->query)); check_execute(fetch->handle, rc); /* @@ -1074,7 +1097,7 @@ my_bool fetch_n(const char **query_list, unsigned query_count, for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) { /* Init will exit(1) in case of error */ - stmt_fetch_init(fetch, (uint) (fetch - fetch_array), + stmt_fetch_init(fetch, fetch - fetch_array, query_list[fetch - fetch_array]); } @@ -1223,7 +1246,7 @@ static void test_tran_bdb() /* create the table 'mytran_demo' of type BDB' or 'InnoDB' */ rc= mysql_query(mysql, "CREATE TABLE my_demo_transaction( " - "col1 int , col2 varchar(30)) TYPE= BDB"); + "col1 int , col2 varchar(30)) ENGINE= BDB"); myquery(rc); /* insert a row and commit the transaction */ @@ -1296,7 +1319,7 @@ static void test_tran_innodb() /* create the table 'mytran_demo' of type BDB' or 'InnoDB' */ rc= mysql_query(mysql, "CREATE TABLE my_demo_transaction(col1 int, " - "col2 varchar(30)) TYPE= InnoDB"); + "col2 varchar(30)) ENGINE= InnoDB"); myquery(rc); /* insert a row and commit the transaction */ @@ -2346,7 +2369,7 @@ static void test_ps_conj_select() int_data= 1; strmov(str_data, "hh"); - str_length= (uint) strlen(str_data); + str_length= strlen(str_data); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -2358,6 +2381,274 @@ static void test_ps_conj_select() } +/* reads Qcache_hits from server and returns its value */ +static uint query_cache_hits(MYSQL *conn) +{ + MYSQL_RES *res; + MYSQL_ROW row; + int rc; + uint result; + + rc= mysql_query(conn, "show status like 'qcache_hits'"); + myquery(rc); + res= mysql_use_result(conn); + DIE_UNLESS(res); + + row= mysql_fetch_row(res); + DIE_UNLESS(row); + + result= atoi(row[1]); + mysql_free_result(res); + return result; +} + + +/* + utility for the next test; expects 3 rows in the result from a SELECT, + compares each row/field with an expected value. + */ +#define test_ps_query_cache_result(i1,s1,l1,i2,s2,l2,i3,s3,l3) \ + r_metadata= mysql_stmt_result_metadata(stmt); \ + DIE_UNLESS(r_metadata != NULL); \ + rc= mysql_stmt_fetch(stmt); \ + check_execute(stmt, rc); \ + if (!opt_silent) \ + fprintf(stdout, "\n row 1: %d, %s(%lu)", r_int_data, \ + r_str_data, r_str_length); \ + DIE_UNLESS((r_int_data == i1) && (r_str_length == l1) && \ + (strcmp(r_str_data, s1) == 0)); \ + rc= mysql_stmt_fetch(stmt); \ + check_execute(stmt, rc); \ + if (!opt_silent) \ + fprintf(stdout, "\n row 2: %d, %s(%lu)", r_int_data, \ + r_str_data, r_str_length); \ + DIE_UNLESS((r_int_data == i2) && (r_str_length == l2) && \ + (strcmp(r_str_data, s2) == 0)); \ + rc= mysql_stmt_fetch(stmt); \ + check_execute(stmt, rc); \ + if (!opt_silent) \ + fprintf(stdout, "\n row 3: %d, %s(%lu)", r_int_data, \ + r_str_data, r_str_length); \ + DIE_UNLESS((r_int_data == i3) && (r_str_length == l3) && \ + (strcmp(r_str_data, s3) == 0)); \ + rc= mysql_stmt_fetch(stmt); \ + DIE_UNLESS(rc == MYSQL_NO_DATA); \ + mysql_free_result(r_metadata); + + +/* + Test that prepared statements make use of the query cache just as normal + statements (BUG#735). +*/ +static void test_ps_query_cache() +{ + MYSQL *lmysql= mysql; + MYSQL_STMT *stmt; + int rc; + MYSQL_BIND p_bind[2],r_bind[2]; /* p: param bind; r: result bind */ + int32 p_int_data, r_int_data; + char p_str_data[32], r_str_data[32]; + unsigned long p_str_length, r_str_length; + MYSQL_RES *r_metadata; + char query[MAX_TEST_QUERY_LENGTH]; + uint hits1, hits2; + enum enum_test_ps_query_cache + { + /* + We iterate the same prepare/executes block, but have iterations where + we vary the query cache conditions. + */ + /* the query cache is enabled for the duration of prep&execs: */ + TEST_QCACHE_ON= 0, + /* + same but using a new connection (to see if qcache serves results from + the previous connection as it should): + */ + TEST_QCACHE_ON_WITH_OTHER_CONN, + /* + First border case: disables the query cache before prepare and + re-enables it before execution (to test if we have no bug then): + */ + TEST_QCACHE_OFF_ON, + /* + Second border case: enables the query cache before prepare and + disables it before execution: + */ + TEST_QCACHE_ON_OFF + }; + enum enum_test_ps_query_cache iteration; + + myheader("test_ps_query_cache"); + + rc= mysql_query(mysql, "SET SQL_MODE=''"); + myquery(rc); + + /* prepare the table */ + + rc= mysql_query(mysql, "drop table if exists t1"); + myquery(rc); + + rc= mysql_query(mysql, "create table t1 (id1 int(11) NOT NULL default '0', " + "value2 varchar(100), value1 varchar(100))"); + myquery(rc); + + rc= mysql_query(mysql, "insert into t1 values (1, 'hh', 'hh'), " + "(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')"); + myquery(rc); + + for (iteration= TEST_QCACHE_ON; iteration <= TEST_QCACHE_ON_OFF; iteration++) + { + + switch (iteration) { + case TEST_QCACHE_ON: + case TEST_QCACHE_ON_OFF: + rc= mysql_query(lmysql, "set global query_cache_size=1000000"); + myquery(rc); + break; + case TEST_QCACHE_OFF_ON: + rc= mysql_query(lmysql, "set global query_cache_size=0"); + myquery(rc); + break; + case TEST_QCACHE_ON_WITH_OTHER_CONN: + if (!opt_silent) + fprintf(stdout, "\n Establishing a test connection ..."); + if (!(lmysql= mysql_init(NULL))) + { + printf("mysql_init() failed"); + DIE_UNLESS(0); + } + if (!(mysql_real_connect(lmysql, opt_host, opt_user, + opt_password, current_db, opt_port, + opt_unix_socket, 0))) + { + printf("connection failed"); + mysql_close(lmysql); + DIE_UNLESS(0); + } + rc= mysql_query(lmysql, "SET SQL_MODE=''"); + myquery(rc); + + if (!opt_silent) + fprintf(stdout, "OK"); + } + + strmov(query, "select id1, value1 from t1 where id1= ? or " + "CONVERT(value1 USING utf8)= ?"); + stmt= mysql_simple_prepare(lmysql, query); + check_stmt(stmt); + + verify_param_count(stmt, 2); + + switch (iteration) { + case TEST_QCACHE_OFF_ON: + rc= mysql_query(lmysql, "set global query_cache_size=1000000"); + myquery(rc); + break; + case TEST_QCACHE_ON_OFF: + rc= mysql_query(lmysql, "set global query_cache_size=0"); + myquery(rc); + default: + break; + } + + bzero((char*) p_bind, sizeof(p_bind)); + p_bind[0].buffer_type= MYSQL_TYPE_LONG; + p_bind[0].buffer= (void *)&p_int_data; + p_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING; + p_bind[1].buffer= (void *)p_str_data; + p_bind[1].buffer_length= array_elements(p_str_data); + p_bind[1].length= &p_str_length; + + rc= mysql_stmt_bind_param(stmt, p_bind); + check_execute(stmt, rc); + + p_int_data= 1; + strmov(p_str_data, "hh"); + p_str_length= strlen(p_str_data); + + bzero((char*) r_bind, sizeof(r_bind)); + r_bind[0].buffer_type= MYSQL_TYPE_LONG; + r_bind[0].buffer= (void *)&r_int_data; + r_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING; + r_bind[1].buffer= (void *)r_str_data; + r_bind[1].buffer_length= array_elements(r_str_data); + r_bind[1].length= &r_str_length; + + rc= mysql_stmt_bind_result(stmt, r_bind); + check_execute(stmt, rc); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + test_ps_query_cache_result(1, "hh", 2, 2, "hh", 2, 1, "ii", 2); + + /* now retry with the same parameter values and see qcache hits */ + hits1= query_cache_hits(lmysql); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + test_ps_query_cache_result(1, "hh", 2, 2, "hh", 2, 1, "ii", 2); + hits2= query_cache_hits(lmysql); + switch(iteration) { + case TEST_QCACHE_ON_WITH_OTHER_CONN: + case TEST_QCACHE_ON: /* should have hit */ + DIE_UNLESS(hits2-hits1 == 1); + break; + case TEST_QCACHE_OFF_ON: + case TEST_QCACHE_ON_OFF: /* should not have hit */ + DIE_UNLESS(hits2-hits1 == 0); + break; + } + + /* now modify parameter values and see qcache hits */ + strmov(p_str_data, "ii"); + p_str_length= strlen(p_str_data); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + test_ps_query_cache_result(1, "hh", 2, 1, "ii", 2, 2, "ii", 2); + hits1= query_cache_hits(lmysql); + + switch(iteration) { + case TEST_QCACHE_ON: + case TEST_QCACHE_OFF_ON: + case TEST_QCACHE_ON_OFF: /* should not have hit */ + DIE_UNLESS(hits2-hits1 == 0); + break; + case TEST_QCACHE_ON_WITH_OTHER_CONN: /* should have hit */ + DIE_UNLESS(hits1-hits2 == 1); + break; + } + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + test_ps_query_cache_result(1, "hh", 2, 1, "ii", 2, 2, "ii", 2); + hits2= query_cache_hits(lmysql); + + mysql_stmt_close(stmt); + + switch(iteration) { + case TEST_QCACHE_ON: /* should have hit */ + DIE_UNLESS(hits2-hits1 == 1); + break; + case TEST_QCACHE_OFF_ON: + case TEST_QCACHE_ON_OFF: /* should not have hit */ + DIE_UNLESS(hits2-hits1 == 0); + break; + case TEST_QCACHE_ON_WITH_OTHER_CONN: /* should have hit */ + DIE_UNLESS(hits2-hits1 == 1); + break; + } + + } /* for(iteration=...) */ + + if (lmysql != mysql) + mysql_close(lmysql); + + rc= mysql_query(mysql, "set global query_cache_size=0"); + myquery(rc); +} + + /* Test BUG#1115 (incorrect string parameter value allocation) */ static void test_bug1115() @@ -2857,9 +3148,9 @@ static void test_long_data() data= (char *)"Michael"; /* supply data in pieces */ - rc= mysql_stmt_send_long_data(stmt, 1, data, (uint) strlen(data)); + rc= mysql_stmt_send_long_data(stmt, 1, data, strlen(data)); data= (char *)" 'Monty' Widenius"; - rc= mysql_stmt_send_long_data(stmt, 1, data, (uint) strlen(data)); + rc= mysql_stmt_send_long_data(stmt, 1, data, strlen(data)); check_execute(stmt, rc); rc= mysql_stmt_send_long_data(stmt, 2, "Venu (venu@mysql.com)", 4); check_execute(stmt, rc); @@ -4683,7 +4974,7 @@ static void test_stmt_close() } lmysql->reconnect= 1; if (!opt_silent) - fprintf(stdout, " OK"); + fprintf(stdout, "OK"); /* set AUTOCOMMIT to ON*/ @@ -4733,7 +5024,7 @@ static void test_stmt_close() close statements by hand once mysql_close() had been called. Now mysql_close() doesn't free any statements, so this test doesn't serve its original designation any more. - Here we free stmt2 and stmt3 by hande to avoid memory leaks. + Here we free stmt2 and stmt3 by hand to avoid memory leaks. */ mysql_stmt_close(stmt2); mysql_stmt_close(stmt3); @@ -6409,10 +6700,10 @@ static void test_pure_coverage() check_execute_r(stmt, rc); /* unsupported buffer type */ rc= mysql_stmt_store_result(stmt); - check_execute(stmt, rc); + DIE_UNLESS(rc); rc= mysql_stmt_store_result(stmt); - check_execute_r(stmt, rc); /* commands out of sync */ + DIE_UNLESS(rc); /* Old error must be reset first */ mysql_stmt_close(stmt); @@ -6942,9 +7233,6 @@ static void test_field_misc() { MYSQL_STMT *stmt; MYSQL_RES *result; - MYSQL_BIND my_bind[1]; - char table_type[NAME_LEN]; - ulong type_length; int rc; myheader("test_field_misc"); @@ -6987,53 +7275,6 @@ static void test_field_misc() mysql_free_result(result); mysql_stmt_close(stmt); - stmt= mysql_simple_prepare(mysql, "SELECT @@table_type"); - check_stmt(stmt); - - rc= mysql_stmt_execute(stmt); - check_execute(stmt, rc); - - bzero((char*) my_bind, sizeof(my_bind)); - my_bind[0].buffer_type= MYSQL_TYPE_STRING; - my_bind[0].buffer= table_type; - my_bind[0].length= &type_length; - my_bind[0].buffer_length= NAME_LEN; - - rc= mysql_stmt_bind_result(stmt, my_bind); - check_execute(stmt, rc); - - rc= mysql_stmt_fetch(stmt); - check_execute(stmt, rc); - if (!opt_silent) - fprintf(stdout, "\n default table type: %s(%ld)", table_type, type_length); - - rc= mysql_stmt_fetch(stmt); - DIE_UNLESS(rc == MYSQL_NO_DATA); - - mysql_stmt_close(stmt); - - stmt= mysql_simple_prepare(mysql, "SELECT @@table_type"); - check_stmt(stmt); - - result= mysql_stmt_result_metadata(stmt); - mytest(result); - DIE_UNLESS(mysql_stmt_field_count(stmt) == mysql_num_fields(result)); - - rc= mysql_stmt_execute(stmt); - check_execute(stmt, rc); - - DIE_UNLESS(1 == my_process_stmt_result(stmt)); - - verify_prepare_field(result, 0, - "@@table_type", "", /* field and its org name */ - mysql_get_server_version(mysql) <= 50000 ? - MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, - "", "", /* table and its org name */ - "", type_length, 0); /* db name, length */ - - mysql_free_result(result); - mysql_stmt_close(stmt); - stmt= mysql_simple_prepare(mysql, "SELECT @@max_error_count"); check_stmt(stmt); @@ -7050,7 +7291,8 @@ static void test_field_misc() "@@max_error_count", "", /* field and its org name */ MYSQL_TYPE_LONGLONG, /* field type */ "", "", /* table and its org name */ - "", 10, 0); /* db name, length */ + /* db name, length */ + "", MY_INT64_NUM_DECIMAL_DIGITS , 0); mysql_free_result(result); mysql_stmt_close(stmt); @@ -7070,7 +7312,8 @@ static void test_field_misc() "@@max_allowed_packet", "", /* field and its org name */ MYSQL_TYPE_LONGLONG, /* field type */ "", "", /* table and its org name */ - "", 10, 0); /* db name, length */ + /* db name, length */ + "", MY_INT64_NUM_DECIMAL_DIGITS, 0); mysql_free_result(result); mysql_stmt_close(stmt); @@ -7231,7 +7474,7 @@ static void test_prepare_grant() } lmysql->reconnect= 1; if (!opt_silent) - fprintf(stdout, " OK"); + fprintf(stdout, "OK"); mysql= lmysql; rc= mysql_query(mysql, "INSERT INTO test_grant VALUES(NULL)"); @@ -7542,7 +7785,7 @@ static void test_explain_bug() verify_prepare_field(result, 5, "Extra", "EXTRA", mysql_get_server_version(mysql) <= 50000 ? MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, - 0, 0, "", 20, 0); + 0, 0, "", 27, 0); mysql_free_result(result); mysql_stmt_close(stmt); @@ -7571,16 +7814,16 @@ static void test_explain_bug() "", "", "", 19, 0); verify_prepare_field(result, 2, "table", "", MYSQL_TYPE_VAR_STRING, - "", "", "", NAME_LEN, 0); + "", "", "", NAME_CHAR_LEN, 0); verify_prepare_field(result, 3, "type", "", MYSQL_TYPE_VAR_STRING, "", "", "", 10, 0); verify_prepare_field(result, 4, "possible_keys", "", MYSQL_TYPE_VAR_STRING, - "", "", "", NAME_LEN*MAX_KEY, 0); + "", "", "", NAME_CHAR_LEN*MAX_KEY, 0); verify_prepare_field(result, 5, "key", "", MYSQL_TYPE_VAR_STRING, - "", "", "", NAME_LEN, 0); + "", "", "", NAME_CHAR_LEN, 0); if (mysql_get_server_version(mysql) <= 50000) { @@ -7590,11 +7833,11 @@ static void test_explain_bug() else { verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_VAR_STRING, "", - "", "", NAME_LEN*MAX_KEY, 0); + "", "", NAME_CHAR_LEN*MAX_KEY, 0); } verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_VAR_STRING, - "", "", "", NAME_LEN*16, 0); + "", "", "", NAME_CHAR_LEN*16, 0); verify_prepare_field(result, 8, "rows", "", MYSQL_TYPE_LONGLONG, "", "", "", 10, 0); @@ -7692,7 +7935,7 @@ static void test_drop_temp() } lmysql->reconnect= 1; if (!opt_silent) - fprintf(stdout, " OK"); + fprintf(stdout, "OK"); mysql= lmysql; rc= mysql_query(mysql, "INSERT INTO t1 VALUES(10, 'C')"); @@ -8164,6 +8407,9 @@ static void test_fetch_offset() rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0); check_execute_r(stmt, rc); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + rc= mysql_stmt_bind_result(stmt, my_bind); check_execute(stmt, rc); @@ -8442,7 +8688,7 @@ static void test_mem_overun() sprintf(field, "c%d int", i); strxmov(buffer, buffer, field, ", ", NullS); } - length= (uint) strlen(buffer); + length= strlen(buffer); buffer[length-2]= ')'; buffer[--length]= '\0'; @@ -8454,7 +8700,7 @@ static void test_mem_overun() { strxmov(buffer, buffer, "1, ", NullS); } - length= (uint) strlen(buffer); + length= strlen(buffer); buffer[length-2]= ')'; buffer[--length]= '\0'; @@ -8723,7 +8969,8 @@ static void test_sqlmode() if (!opt_silent) fprintf(stdout, "\n query: %s", query); stmt= mysql_simple_prepare(mysql, query); - check_stmt_r(stmt); + check_stmt(stmt); + mysql_stmt_close(stmt); /* ANSI */ strmov(query, "SET SQL_MODE= \"ANSI\""); @@ -8982,7 +9229,7 @@ static void test_bug1500() data= "Dogs"; my_bind[0].buffer_type= MYSQL_TYPE_STRING; my_bind[0].buffer= (void *) data; - my_bind[0].buffer_length= (uint) strlen(data); + my_bind[0].buffer_length= strlen(data); my_bind[0].is_null= 0; my_bind[0].length= 0; @@ -9007,7 +9254,7 @@ static void test_bug1500() data= "Grave"; my_bind[0].buffer_type= MYSQL_TYPE_STRING; my_bind[0].buffer= (void *) data; - my_bind[0].buffer_length= (uint) strlen(data); + my_bind[0].buffer_length= strlen(data); rc= mysql_stmt_bind_param(stmt, my_bind); check_execute(stmt, rc); @@ -9038,7 +9285,7 @@ static void test_bug1946() stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); - rc= mysql_real_query(mysql, query, (uint) strlen(query)); + rc= mysql_real_query(mysql, query, strlen(query)); DIE_UNLESS(rc != 0); if (!opt_silent) fprintf(stdout, "Got error (as expected):\n"); @@ -9641,7 +9888,7 @@ static void test_rename() MYSQL_STMT *stmt; const char *query= "rename table t1 to t2, t3 to t4"; int rc; - myheader("test_table_manipulation"); + myheader("test_table_rename"); rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2, t3, t4"); myquery(rc); @@ -9921,7 +10168,7 @@ static void test_derived() myquery(rc); rc= mysql_query(mysql, "create table t1 (id int(8), primary key (id)) \ -TYPE=InnoDB DEFAULT CHARSET=utf8"); +ENGINE=InnoDB DEFAULT CHARSET=utf8"); myquery(rc); rc= mysql_query(mysql, "insert into t1 values (1)"); @@ -9969,16 +10216,16 @@ static void test_xjoin() rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2, t3, t4"); myquery(rc); - rc= mysql_query(mysql, "create table t3 (id int(8), param1_id int(8), param2_id int(8)) TYPE=InnoDB DEFAULT CHARSET=utf8"); + rc= mysql_query(mysql, "create table t3 (id int(8), param1_id int(8), param2_id int(8)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); myquery(rc); - rc= mysql_query(mysql, "create table t1 ( id int(8), name_id int(8), value varchar(10)) TYPE=InnoDB DEFAULT CHARSET=utf8"); + rc= mysql_query(mysql, "create table t1 ( id int(8), name_id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); myquery(rc); - rc= mysql_query(mysql, "create table t2 (id int(8), name_id int(8), value varchar(10)) TYPE=InnoDB DEFAULT CHARSET=utf8;"); + rc= mysql_query(mysql, "create table t2 (id int(8), name_id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); myquery(rc); - rc= mysql_query(mysql, "create table t4(id int(8), value varchar(10)) TYPE=InnoDB DEFAULT CHARSET=utf8"); + rc= mysql_query(mysql, "create table t4(id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); myquery(rc); rc= mysql_query(mysql, "insert into t3 values (1, 1, 1), (2, 2, null)"); @@ -10054,7 +10301,7 @@ static void test_bug3035() myheader("test_bug3035"); stmt_text= "DROP TABLE IF EXISTS t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "CREATE TABLE t1 (i8 TINYINT, ui8 TINYINT UNSIGNED, " @@ -10062,7 +10309,7 @@ static void test_bug3035() "i32 INT, ui32 INT UNSIGNED, " "i64 BIGINT, ui64 BIGINT UNSIGNED, " "id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); bzero((char*) bind_array, sizeof(bind_array)); @@ -10103,7 +10350,7 @@ static void test_bug3035() stmt_text= "INSERT INTO t1 (i8, ui8, i16, ui16, i32, ui32, i64, ui64) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); mysql_stmt_bind_param(stmt, bind_array); @@ -10136,7 +10383,7 @@ static void test_bug3035() "cast(ui64 as signed), ui64, cast(ui64 as signed)" "FROM t1 ORDER BY id ASC"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); @@ -10206,7 +10453,7 @@ static void test_bug3035() mysql_stmt_close(stmt); stmt_text= "DROP TABLE t1"; - mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + mysql_real_query(mysql, stmt_text, strlen(stmt_text)); } @@ -10269,7 +10516,7 @@ static void test_bug1664() stmt= mysql_stmt_init(mysql); check_stmt(stmt); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); verify_param_count(stmt, 2); @@ -10278,7 +10525,7 @@ static void test_bug1664() my_bind[0].buffer_type= MYSQL_TYPE_STRING; my_bind[0].buffer= (void *)str_data; - my_bind[0].buffer_length= (uint) strlen(str_data); + my_bind[0].buffer_length= strlen(str_data); my_bind[1].buffer= (void *)&int_data; my_bind[1].buffer_type= MYSQL_TYPE_LONG; @@ -10293,7 +10540,7 @@ static void test_bug1664() not break following execution. */ data= ""; - rc= mysql_stmt_send_long_data(stmt, 0, data, (uint) strlen(data)); + rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); @@ -10307,7 +10554,7 @@ static void test_bug1664() /* This should pass OK */ data= (char *)"Data"; - rc= mysql_stmt_send_long_data(stmt, 0, data, (uint) strlen(data)); + rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); @@ -10344,7 +10591,7 @@ static void test_bug1664() */ data= (char *)"SomeOtherData"; - rc= mysql_stmt_send_long_data(stmt, 0, data, (uint) strlen(data)); + rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); @@ -10362,13 +10609,13 @@ static void test_bug1664() /* Now let us test how mysql_stmt_reset works. */ stmt= mysql_stmt_init(mysql); check_stmt(stmt); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); rc= mysql_stmt_bind_param(stmt, my_bind); check_execute(stmt, rc); data= (char *)"SomeData"; - rc= mysql_stmt_send_long_data(stmt, 0, data, (uint) strlen(data)); + rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data)); check_execute(stmt, rc); rc= mysql_stmt_reset(stmt); @@ -10494,7 +10741,7 @@ static void test_ps_i18n() myheader("test_ps_i18n"); stmt_text= "DROP TABLE IF EXISTS t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); /* @@ -10505,37 +10752,37 @@ static void test_ps_i18n() stmt_text= "CREATE TABLE t1 (c1 VARBINARY(255), c2 VARBINARY(255))"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "SET CHARACTER_SET_CLIENT=koi8r, " "CHARACTER_SET_CONNECTION=cp1251, " "CHARACTER_SET_RESULTS=koi8r"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); bzero((char*) bind_array, sizeof(bind_array)); bind_array[0].buffer_type= MYSQL_TYPE_STRING; bind_array[0].buffer= (void *) koi8; - bind_array[0].buffer_length= (uint) strlen(koi8); + bind_array[0].buffer_length= strlen(koi8); bind_array[1].buffer_type= MYSQL_TYPE_STRING; bind_array[1].buffer= (void *) koi8; - bind_array[1].buffer_length= (uint) strlen(koi8); + bind_array[1].buffer_length= strlen(koi8); stmt= mysql_stmt_init(mysql); check_stmt(stmt); stmt_text= "INSERT INTO t1 (c1, c2) VALUES (?, ?)"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); mysql_stmt_bind_param(stmt, bind_array); - mysql_stmt_send_long_data(stmt, 0, koi8, (uint) strlen(koi8)); + mysql_stmt_send_long_data(stmt, 0, koi8, strlen(koi8)); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -10543,7 +10790,7 @@ static void test_ps_i18n() stmt_text= "SELECT c1, c2 FROM t1"; /* c1 and c2 are binary so no conversion will be done on select */ - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); @@ -10571,7 +10818,7 @@ static void test_ps_i18n() DIE_UNLESS(rc == MYSQL_NO_DATA); stmt_text= "DROP TABLE IF EXISTS t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); /* @@ -10584,26 +10831,26 @@ static void test_ps_i18n() stmt_text= "CREATE TABLE t1 (c1 VARCHAR(255) CHARACTER SET cp1251, " "c2 VARCHAR(255) CHARACTER SET cp1251)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "INSERT INTO t1 (c1, c2) VALUES (?, ?)"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); /* this data must be converted */ bind_array[0].buffer_type= MYSQL_TYPE_STRING; bind_array[0].buffer= (void *) koi8; - bind_array[0].buffer_length= (uint) strlen(koi8); + bind_array[0].buffer_length= strlen(koi8); bind_array[1].buffer_type= MYSQL_TYPE_STRING; bind_array[1].buffer= (void *) koi8; - bind_array[1].buffer_length= (uint) strlen(koi8); + bind_array[1].buffer_length= strlen(koi8); mysql_stmt_bind_param(stmt, bind_array); - mysql_stmt_send_long_data(stmt, 0, koi8, (uint) strlen(koi8)); + mysql_stmt_send_long_data(stmt, 0, koi8, strlen(koi8)); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -10611,15 +10858,15 @@ static void test_ps_i18n() /* this data must not be converted */ bind_array[0].buffer_type= MYSQL_TYPE_BLOB; bind_array[0].buffer= (void *) cp1251; - bind_array[0].buffer_length= (uint) strlen(cp1251); + bind_array[0].buffer_length= strlen(cp1251); bind_array[1].buffer_type= MYSQL_TYPE_BLOB; bind_array[1].buffer= (void *) cp1251; - bind_array[1].buffer_length= (uint) strlen(cp1251); + bind_array[1].buffer_length= strlen(cp1251); mysql_stmt_bind_param(stmt, bind_array); - mysql_stmt_send_long_data(stmt, 0, cp1251, (uint) strlen(cp1251)); + mysql_stmt_send_long_data(stmt, 0, cp1251, strlen(cp1251)); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -10629,7 +10876,7 @@ static void test_ps_i18n() stmt_text= "SELECT c1, c2 FROM t1"; /* c1 and c2 are binary so no conversion will be done on select */ - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); @@ -10656,10 +10903,10 @@ static void test_ps_i18n() mysql_stmt_close(stmt); stmt_text= "DROP TABLE t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "SET NAMES DEFAULT"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); } @@ -10680,22 +10927,22 @@ static void test_bug3796() /* Create and fill test table */ stmt_text= "DROP TABLE IF EXISTS t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "CREATE TABLE t1 (a INT, b VARCHAR(30))"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "INSERT INTO t1 VALUES(1, 'ONE'), (2, 'TWO')"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); /* Create statement handle and prepare it with select */ stmt= mysql_stmt_init(mysql); stmt_text= "SELECT concat(?, b) FROM t1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); /* Bind input buffers */ @@ -10703,7 +10950,7 @@ static void test_bug3796() my_bind[0].buffer_type= MYSQL_TYPE_STRING; my_bind[0].buffer= (void *) concat_arg0; - my_bind[0].buffer_length= (uint) strlen(concat_arg0); + my_bind[0].buffer_length= strlen(concat_arg0); mysql_stmt_bind_param(stmt, my_bind); @@ -10740,7 +10987,7 @@ static void test_bug3796() mysql_stmt_close(stmt); stmt_text= "DROP TABLE IF EXISTS t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); } @@ -10762,7 +11009,7 @@ static void test_bug4026() stmt= mysql_stmt_init(mysql); stmt_text= "SELECT ?, ?"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); /* Bind input buffers */ @@ -10840,7 +11087,7 @@ static void test_bug4079() stmt= mysql_stmt_init(mysql); stmt_text= "SELECT 1 < (SELECT a FROM t1)"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); /* Execute the select statement */ @@ -10872,14 +11119,14 @@ static void test_bug4236() int rc; MYSQL_STMT backup; - myheader("test_bug4296"); + myheader("test_bug4236"); stmt= mysql_stmt_init(mysql); /* mysql_stmt_execute() of statement with statement id= 0 crashed server */ stmt_text= "SELECT 1"; /* We need to prepare statement to pass by possible check in libmysql */ - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); /* Hack to check that server works OK if statement wasn't found */ backup.stmt_id= stmt->stmt_id; @@ -10911,7 +11158,7 @@ static void test_bug4030() stmt= mysql_stmt_init(mysql); stmt_text= "SELECT '23:59:59.123456', '2003-12-31', " "'2003-12-31 23:59:59.123456'"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -11022,12 +11269,12 @@ static void test_view() myquery(rc); stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); strmov(str_data, "TEST"); bzero((char*) my_bind, sizeof(my_bind)); - my_bind[0].buffer_type= FIELD_TYPE_STRING; + my_bind[0].buffer_type= MYSQL_TYPE_STRING; my_bind[0].buffer= (char *)&str_data; my_bind[0].buffer_length= 50; my_bind[0].length= &length; @@ -11076,7 +11323,7 @@ static void test_view_where() myquery(rc); stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); for (i= 0; i < 3; i++) @@ -11158,7 +11405,7 @@ static void test_view_2where() length[i] = 1; } stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); rc= mysql_stmt_bind_param(stmt, my_bind); @@ -11209,7 +11456,7 @@ static void test_view_star() } stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); rc= mysql_stmt_bind_param(stmt, my_bind); @@ -11257,15 +11504,15 @@ static void test_view_insert() myquery(rc); insert_stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(insert_stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(insert_stmt, query, strlen(query)); check_execute(insert_stmt, rc); query= "select * from t1"; select_stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(select_stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(select_stmt, query, strlen(query)); check_execute(select_stmt, rc); bzero((char*) my_bind, sizeof(my_bind)); - my_bind[0].buffer_type = FIELD_TYPE_LONG; + my_bind[0].buffer_type = MYSQL_TYPE_LONG; my_bind[0].buffer = (char *)&my_val; my_bind[0].length = &my_length; my_bind[0].is_null = (char*)&my_null; @@ -11316,7 +11563,7 @@ static void test_left_join_view() rc= mysql_query(mysql,"create view v1 (x) as select a from t1 where a > 1"); myquery(rc); stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); for (i= 0; i < 3; i++) @@ -11384,7 +11631,7 @@ static void test_view_insert_fields() my_bind[i].length= &l[i]; } stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); rc= mysql_stmt_bind_param(stmt, my_bind); check_execute(stmt, rc); @@ -11395,7 +11642,7 @@ static void test_view_insert_fields() query= "select * from t1"; stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -11421,20 +11668,20 @@ static void test_bug5126() myheader("test_bug5126"); stmt_text= "DROP TABLE IF EXISTS t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "CREATE TABLE t1 (a mediumint, b int)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "INSERT INTO t1 VALUES (8386608, 1)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt= mysql_stmt_init(mysql); stmt_text= "SELECT a, b FROM t1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -11469,20 +11716,20 @@ static void test_bug4231() myheader("test_bug4231"); stmt_text= "DROP TABLE IF EXISTS t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "CREATE TABLE t1 (a int)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "INSERT INTO t1 VALUES (1)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt= mysql_stmt_init(mysql); stmt_text= "SELECT a FROM t1 WHERE ? = ?"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); /* Bind input buffers */ @@ -11526,7 +11773,7 @@ static void test_bug4231() mysql_stmt_close(stmt); stmt_text= "DROP TABLE t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); } @@ -11555,7 +11802,7 @@ static void test_bug5399() { sprintf(buff, "select %d", (int) (stmt - stmt_list)); *stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(*stmt, buff, (uint) strlen(buff)); + rc= mysql_stmt_prepare(*stmt, buff, strlen(buff)); check_execute(*stmt, rc); mysql_stmt_bind_result(*stmt, my_bind); } @@ -11632,7 +11879,7 @@ static void test_bug5194() myheader("test_bug5194"); stmt_text= "drop table if exists t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); stmt_text= "create table if not exists t1" "(c1 float, c2 float, c3 float, c4 float, c5 float, c6 float, " @@ -11677,7 +11924,7 @@ static void test_bug5194() "c235 float, c236 float, c237 float, c238 float, c239 float, c240 float, " "c241 float, c242 float, c243 float, c244 float, c245 float, c246 float, " "c247 float, c248 float, c249 float, c250 float)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); my_bind= (MYSQL_BIND*) malloc(MAX_PARAM_COUNT * sizeof(MYSQL_BIND)); @@ -11704,7 +11951,7 @@ static void test_bug5194() for (i= 1; i < COLUMN_COUNT; ++i) strcat(param_str, "?, "); strcat(param_str, "?)"); - param_str_length= (uint) strlen(param_str); + param_str_length= strlen(param_str); /* setup bind array */ bzero((char*) my_bind, MAX_PARAM_COUNT * sizeof(MYSQL_BIND)); @@ -11735,7 +11982,7 @@ static void test_bug5194() } *query_ptr= '\0'; - rc= mysql_stmt_prepare(stmt, query, (uint) (query_ptr - query)); + rc= mysql_stmt_prepare(stmt, query, query_ptr - query); if (rc && nrows * COLUMN_COUNT > uint16_max) { if (!opt_silent) @@ -11764,7 +12011,7 @@ static void test_bug5194() free(query); free(param_str); stmt_text= "drop table t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); } @@ -11779,20 +12026,28 @@ static void test_bug5315() stmt_text= "SELECT 1"; stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); DIE_UNLESS(rc == 0); + if (!opt_silent) + printf("Excuting mysql_change_user\n"); mysql_change_user(mysql, opt_user, opt_password, current_db); + if (!opt_silent) + printf("Excuting mysql_stmt_execute\n"); rc= mysql_stmt_execute(stmt); DIE_UNLESS(rc != 0); if (rc) { if (!opt_silent) - printf("Got error (as expected):\n%s", mysql_stmt_error(stmt)); + printf("Got error (as expected): '%s'\n", mysql_stmt_error(stmt)); } /* check that connection is OK */ + if (!opt_silent) + printf("Excuting mysql_stmt_close\n"); mysql_stmt_close(stmt); + if (!opt_silent) + printf("Excuting mysql_stmt_init\n"); stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); DIE_UNLESS(rc == 0); rc= mysql_stmt_execute(stmt); DIE_UNLESS(rc == 0); @@ -11815,13 +12070,13 @@ static void test_bug6049() stmt_text= "SELECT MAKETIME(-25, 12, 12)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); res= mysql_store_result(mysql); row= mysql_fetch_row(res); stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -11867,13 +12122,13 @@ static void test_bug6058() stmt_text= "SELECT CAST('0000-00-00' AS DATE)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); res= mysql_store_result(mysql); row= mysql_fetch_row(res); stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -11911,7 +12166,7 @@ static void test_bug6059() stmt_text= "SELECT 'foo' INTO OUTFILE 'x.3'"; stmt= mysql_stmt_init(mysql); - (void) mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + (void) mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); DIE_UNLESS(mysql_stmt_field_count(stmt) == 0); mysql_stmt_close(stmt); } @@ -11928,13 +12183,13 @@ static void test_bug6046() myheader("test_bug6046"); stmt_text= "DROP TABLE IF EXISTS t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "CREATE TABLE t1 (a int, b int)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "INSERT INTO t1 VALUES (1,1),(2,2),(3,1),(4,2)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt= mysql_stmt_init(mysql); @@ -11942,7 +12197,7 @@ static void test_bug6046() stmt_text= "SELECT t1.a FROM t1 NATURAL JOIN t1 as X1 " "WHERE t1.b > ? ORDER BY t1.a"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); b= 1; @@ -12046,16 +12301,24 @@ static void test_bug6081() int rc; myheader("test_bug6081"); - rc= simple_command(mysql, COM_DROP_DB, current_db, + rc= simple_command(mysql, COM_DROP_DB, (uchar*) current_db, (ulong)strlen(current_db), 0); - myquery(rc); - rc= simple_command(mysql, COM_DROP_DB, current_db, + if (rc == 0 && mysql_errno(mysql) != ER_UNKNOWN_COM_ERROR) + { + myerror(NULL); /* purecov: inspected */ + die(__FILE__, __LINE__, "COM_DROP_DB failed"); /* purecov: inspected */ + } + rc= simple_command(mysql, COM_DROP_DB, (uchar*) current_db, (ulong)strlen(current_db), 0); myquery_r(rc); - rc= simple_command(mysql, COM_CREATE_DB, current_db, + rc= simple_command(mysql, COM_CREATE_DB, (uchar*) current_db, (ulong)strlen(current_db), 0); - myquery(rc); - rc= simple_command(mysql, COM_CREATE_DB, current_db, + if (rc == 0 && mysql_errno(mysql) != ER_UNKNOWN_COM_ERROR) + { + myerror(NULL); /* purecov: inspected */ + die(__FILE__, __LINE__, "COM_CREATE_DB failed"); /* purecov: inspected */ + } + rc= simple_command(mysql, COM_CREATE_DB, (uchar*) current_db, (ulong)strlen(current_db), 0); myquery_r(rc); rc= mysql_select_db(mysql, current_db); @@ -12063,27 +12326,6 @@ static void test_bug6081() } -/* - Verify that bogus database names are handled properly with - COM_CREATE_DB and COM_DROP_DB, i.e., cannot cause SIGSEGV through - the use of printf specifiers in the database name. -*/ -static void test_bug45790() -{ - const char* bogus_db = "%s%s%s%s%s%s%s"; - int rc; - - myheader("test_bug45790"); - rc= simple_command(mysql, COM_CREATE_DB, bogus_db, - (ulong)strlen(bogus_db), 0); - myquery(rc); - - rc= simple_command(mysql, COM_DROP_DB, bogus_db, - (ulong)strlen(bogus_db), 0); - myquery(rc); -} - - static void test_bug6096() { MYSQL_STMT *stmt; @@ -12099,7 +12341,7 @@ static void test_bug6096() myheader("test_bug6096"); stmt_text= "drop table if exists t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); mysql_query(mysql, "set sql_mode=''"); @@ -12109,24 +12351,24 @@ static void test_bug6096() " c_double double, c_varchar varchar(20), " " c_char char(20), c_time time, c_date date, " " c_datetime datetime)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "insert into t1 values (-100, -20000, 30000000, 4, 8, 1.0, " "2.0, 'abc', 'def', now(), now(), now())"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "select * from t1"; /* Run select in prepared and non-prepared mode and compare metadata */ - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); query_result= mysql_store_result(mysql); query_field_list= mysql_fetch_fields(query_result); query_field_count= mysql_num_fields(query_result); stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -12183,7 +12425,7 @@ static void test_bug6096() mysql_free_result(query_result); mysql_free_result(stmt_metadata); stmt_text= "drop table t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); } @@ -12204,12 +12446,12 @@ static void test_datetime_ranges() myheader("test_datetime_ranges"); stmt_text= "drop table if exists t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "create table t1 (year datetime, month datetime, day datetime, " "hour datetime, min datetime, sec datetime)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt= mysql_simple_prepare(mysql, @@ -12248,7 +12490,7 @@ static void test_datetime_ranges() mysql_stmt_close(stmt); stmt_text= "delete from t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt= mysql_simple_prepare(mysql, "INSERT INTO t1 (year, month, day) " @@ -12276,11 +12518,11 @@ static void test_datetime_ranges() mysql_stmt_close(stmt); stmt_text= "drop table t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "create table t1 (day_ovfl time, day time, hour time, min time, sec time)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt= mysql_simple_prepare(mysql, @@ -12317,7 +12559,7 @@ static void test_datetime_ranges() mysql_stmt_close(stmt); stmt_text= "drop table t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); } @@ -12343,7 +12585,7 @@ static void test_bug4172() stmt= mysql_stmt_init(mysql); stmt_text= "SELECT f, d, e FROM t1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -12368,7 +12610,7 @@ static void test_bug4172() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); res= mysql_store_result(mysql); row= mysql_fetch_row(res); @@ -12399,20 +12641,20 @@ static void test_conversion() myheader("test_conversion"); stmt_text= "DROP TABLE IF EXISTS t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "CREATE TABLE t1 (a TEXT) DEFAULT CHARSET latin1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "SET character_set_connection=utf8, character_set_client=utf8, " " character_set_results=latin1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt= mysql_stmt_init(mysql); stmt_text= "INSERT INTO t1 (a) VALUES (?)"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); bzero((char*) my_bind, sizeof(my_bind)); @@ -12430,7 +12672,7 @@ static void test_conversion() check_execute(stmt, rc); stmt_text= "SELECT a FROM t1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -12447,10 +12689,10 @@ static void test_conversion() mysql_stmt_close(stmt); stmt_text= "DROP TABLE t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "SET NAMES DEFAULT"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); } @@ -12466,16 +12708,16 @@ static void test_rewind(void) myheader("test_rewind"); stmt_text= "CREATE TABLE t1 (a int)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "INSERT INTO t1 VALUES(2),(3),(4)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt= mysql_stmt_init(mysql); stmt_text= "SELECT * FROM t1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); bzero((char*) &my_bind, sizeof(MYSQL_BIND)); @@ -12495,6 +12737,7 @@ static void test_rewind(void) /* retreive all result sets till we are at the end */ while(!mysql_stmt_fetch(stmt)) + if (!opt_silent) printf("fetched result:%ld\n", Data); DIE_UNLESS(rc != MYSQL_NO_DATA); @@ -12505,12 +12748,13 @@ static void test_rewind(void) /* now we should be able to fetch the results again */ /* but mysql_stmt_fetch returns MYSQL_NO_DATA */ while(!(rc= mysql_stmt_fetch(stmt))) + if (!opt_silent) printf("fetched result after seek:%ld\n", Data); DIE_UNLESS(rc == MYSQL_NO_DATA); stmt_text= "DROP TABLE t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); rc= mysql_stmt_free_result(stmt); rc= mysql_stmt_close(stmt); @@ -12538,7 +12782,7 @@ static void test_truncation() "d double, d_1 double, ch char(30), ch_1 char(30), " "tx text, tx_1 text, ch_2 char(30) " ")"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "insert into t1 VALUES (" "-10, " /* i8 */ @@ -12556,7 +12800,7 @@ static void test_truncation() "'12345.67 ', " /* tx_1 */ "'12345.67abc'" /* ch_2 */ ")"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "select i8 c1, i8 c2, ui8 c3, i16_1 c4, ui16 c5, " @@ -12566,7 +12810,7 @@ static void test_truncation() "from t1"; stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -12774,7 +13018,7 @@ static void test_truncation_option() stmt_text= "select -1"; stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -12820,7 +13064,7 @@ static void test_bug6761(void) myheader("test_bug6761"); stmt_text= "CREATE TABLE t1 (a int, b char(255), c decimal)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); res= mysql_list_fields(mysql, "t1", "%"); @@ -12828,7 +13072,7 @@ static void test_bug6761(void) mysql_free_result(res); stmt_text= "DROP TABLE t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); } @@ -12848,17 +13092,17 @@ static void test_bug8330() stmt_text= "drop table if exists t1"; /* in case some previos test failed */ - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "create table t1 (a int, b int)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); bzero((char*) my_bind, sizeof(my_bind)); for (i=0; i < 2; i++) { stmt[i]= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt[i], query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt[i], query, strlen(query)); check_execute(stmt[i], rc); my_bind[i].buffer_type= MYSQL_TYPE_LONG; @@ -12879,7 +13123,7 @@ static void test_bug8330() mysql_stmt_close(stmt[1]); stmt_text= "drop table t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); } @@ -12979,6 +13223,40 @@ static void test_bug15518() } +static void disable_general_log() +{ + int rc; + rc= mysql_query(mysql, "set @@global.general_log=off"); + myquery(rc); +} + + +static void enable_general_log(int truncate) +{ + int rc; + + rc= mysql_query(mysql, "set @save_global_general_log=@@global.general_log"); + myquery(rc); + + rc= mysql_query(mysql, "set @@global.general_log=on"); + myquery(rc); + + if (truncate) + { + rc= mysql_query(mysql, "truncate mysql.general_log"); + myquery(rc); + } +} + + +static void restore_general_log() +{ + int rc; + rc= mysql_query(mysql, "set @@global.general_log=@save_global_general_log"); + myquery(rc); +} + + static void test_view_sp_list_fields() { int rc; @@ -13055,7 +13333,7 @@ static void test_bug8378() exit(1); } if (!opt_silent) - fprintf(stdout, " OK"); + fprintf(stdout, "OK"); rc= mysql_query(lmysql, "SET SQL_MODE=''"); myquery(rc); @@ -13067,7 +13345,7 @@ static void test_bug8378() sprintf(buf, "SELECT '%s'", out); - rc=mysql_real_query(lmysql, buf, (uint) strlen(buf)); + rc=mysql_real_query(lmysql, buf, strlen(buf)); myquery(rc); mysql_close(lmysql); @@ -13084,19 +13362,19 @@ static void test_bug8722() myheader("test_bug8722"); /* Prepare test data */ stmt_text= "drop table if exists t1, v1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "CREATE TABLE t1 (c1 varchar(10), c2 varchar(10), c3 varchar(10)," " c4 varchar(10), c5 varchar(10), c6 varchar(10)," " c7 varchar(10), c8 varchar(10), c9 varchar(10)," "c10 varchar(10))"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "INSERT INTO t1 VALUES (1,2,3,4,5,6,7,8,9,10)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "CREATE VIEW v1 AS SELECT * FROM t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); /* Note: if you uncomment following block everything works fine */ /* @@ -13107,11 +13385,11 @@ static void test_bug8722() stmt= mysql_stmt_init(mysql); stmt_text= "select * from v1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); mysql_stmt_close(stmt); stmt_text= "drop table if exists t1, v1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); } @@ -13122,7 +13400,7 @@ MYSQL_STMT *open_cursor(const char *query) const ulong type= (ulong)CURSOR_TYPE_READ_ONLY; MYSQL_STMT *stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); @@ -13173,7 +13451,7 @@ static void test_bug9159() myquery(rc); stmt= mysql_stmt_init(mysql); - mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void *)&type); mysql_stmt_execute(stmt); @@ -13225,7 +13503,8 @@ static void test_bug9520() DIE_UNLESS(rc == MYSQL_NO_DATA); - printf("Fetched %d rows\n", row_count); + if (!opt_silent) + printf("Fetched %d rows\n", row_count); DBUG_ASSERT(row_count == 3); mysql_stmt_close(stmt); @@ -13298,10 +13577,11 @@ static void test_bug9478() { char buff[8]; - /* Fill in the fethc packet */ + /* Fill in the fetch packet */ int4store(buff, stmt->stmt_id); buff[4]= 1; /* prefetch rows */ - rc= ((*mysql->methods->advanced_command)(mysql, COM_STMT_FETCH, buff, + rc= ((*mysql->methods->advanced_command)(mysql, COM_STMT_FETCH, + (uchar*) buff, sizeof(buff), 0,0,1,NULL) || (*mysql->methods->read_query_result)(mysql)); DIE_UNLESS(rc); @@ -13415,7 +13695,7 @@ static void test_bug9643() (void*) &prefetch_rows); check_execute(stmt, rc); stmt_text= "select * from t1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); bzero((char*) my_bind, sizeof(my_bind)); @@ -13471,14 +13751,14 @@ static void test_bug11111() stmt= mysql_stmt_init(mysql); - mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + mysql_stmt_prepare(stmt, query, strlen(query)); mysql_stmt_execute(stmt); bzero((char*) my_bind, sizeof(my_bind)); for (i=0; i < 2; i++) { my_bind[i].buffer_type= MYSQL_TYPE_STRING; - my_bind[i].buffer= (gptr *)&buf[i]; + my_bind[i].buffer= (uchar* *)&buf[i]; my_bind[i].buffer_length= 20; my_bind[i].length= &len[i]; } @@ -13529,7 +13809,7 @@ static void test_bug10729() rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); check_execute(stmt, rc); stmt_text= "select name from t1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); bzero((char*) my_bind, sizeof(my_bind)); @@ -13639,7 +13919,7 @@ static void test_bug10736() rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); check_execute(stmt, rc); stmt_text= "select name from t1 where name=(select name from t1 where id=2)"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); bzero((char*) my_bind, sizeof(my_bind)); @@ -13689,7 +13969,7 @@ static void test_bug10794() "name varchar(20) not null)"); stmt= mysql_stmt_init(mysql); stmt_text= "insert into t1 (id, name) values (?, ?)"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); bzero((char*) my_bind, sizeof(my_bind)); my_bind[0].buffer_type= MYSQL_TYPE_LONG; @@ -13703,12 +13983,12 @@ static void test_bug10794() { id_val= (i+1)*10; sprintf(a, "a%d", i); - a_len= (uint) strlen(a); /* safety against broken sprintf */ + a_len= strlen(a); /* safety against broken sprintf */ rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); } stmt_text= "select name from t1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); type= (ulong) CURSOR_TYPE_READ_ONLY; mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); stmt1= mysql_stmt_init(mysql); @@ -13730,7 +14010,7 @@ static void test_bug10794() mysql_stmt_free_result(stmt); mysql_stmt_reset(stmt); stmt_text= "select name from t1 where id=10"; - rc= mysql_stmt_prepare(stmt1, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt1, stmt_text, strlen(stmt_text)); check_execute(stmt1, rc); rc= mysql_stmt_bind_result(stmt1, my_bind); check_execute(stmt1, rc); @@ -13780,7 +14060,7 @@ static void test_bug11172() myquery(rc); stmt= mysql_stmt_init(mysql); stmt_text= "SELECT id, hired FROM t1 WHERE hired=?"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); type= (ulong) CURSOR_TYPE_READ_ONLY; @@ -13852,7 +14132,7 @@ static void test_bug11656() stmt_text= "select distinct test_kind, test_id from t1 " "where server in (?, ?)"; stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); type= (ulong) CURSOR_TYPE_READ_ONLY; mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); @@ -13863,8 +14143,8 @@ static void test_bug11656() for (i=0; i < 2; i++) { my_bind[i].buffer_type= MYSQL_TYPE_STRING; - my_bind[i].buffer= (gptr *)&buf[i]; - my_bind[i].buffer_length= (uint) strlen(buf[i]); + my_bind[i].buffer= (uchar* *)&buf[i]; + my_bind[i].buffer_length= strlen(buf[i]); } mysql_stmt_bind_param(stmt, my_bind); @@ -13969,7 +14249,7 @@ static void test_bug11183() stmt= mysql_stmt_init(mysql); DIE_UNLESS(stmt != 0); - rc= mysql_stmt_prepare(stmt, bug_statement, (uint) strlen(bug_statement)); + rc= mysql_stmt_prepare(stmt, bug_statement, strlen(bug_statement)); check_execute(stmt, rc); rc= mysql_query(mysql, "drop table t1"); @@ -14015,7 +14295,7 @@ static void test_bug11037() stmt_text= "select id FROM t1"; stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); /* expected error */ rc = mysql_stmt_fetch(stmt); @@ -14083,7 +14363,7 @@ static void test_bug10760() con1: insert into t1 (id) values (1) */ stmt_text= "select id from t1 order by 1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -14116,7 +14396,7 @@ static void test_bug10760() else { stmt_text= "select id from t1 order by 1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_query(mysql, "alter table t1 engine=InnoDB"); @@ -14219,7 +14499,7 @@ static void test_bug11909() myheader("test_bug11909"); stmt_text= "drop table if exists t1"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "create table t1 (" @@ -14228,7 +14508,7 @@ static void test_bug11909() " workdept varchar(6) not null, salary double not null," " bonus float not null, primary key (empno)" ") default charset=latin1 collate=latin1_bin"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "insert into t1 values " @@ -14237,7 +14517,7 @@ static void test_bug11909() "(30, 'SALLY', 'A', 'KWAN', 'C01', 38250, 800)," "(50, 'JOHN', 'B', 'GEYER', 'E01', 40175, 800), " "(60, 'IRVING', 'F', 'STERN', 'D11', 32250, 500)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); /* ****** Begin of trace ****** */ @@ -14335,7 +14615,7 @@ static void test_bug11901() myheader("test_bug11901"); stmt_text= "drop table if exists t1, t2"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "create table t1 (" @@ -14345,7 +14625,7 @@ static void test_bug11901() " bonus float not null, primary key (empno), " " unique key (workdept, empno) " ") default charset=latin1 collate=latin1_bin"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "insert into t1 values " @@ -14382,7 +14662,7 @@ static void test_bug11901() "(330, 'WING', '', 'LEE', 'E21', 25370, 500), " "(340, 'JASON', 'R', 'GOUNOT', 'E21', 23840, 500)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "create table t2 (" @@ -14391,7 +14671,7 @@ static void test_bug11901() " admrdept varchar(6) not null, refcntd int(11) not null," " refcntu int(11) not null, primary key (deptno)" ") default charset=latin1 collate=latin1_bin"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt_text= "insert into t2 values " @@ -14404,7 +14684,7 @@ static void test_bug11901() "('E01', 'SUPPORT SERVICES', 50, '', 'A00', 0, 0), " "('E11', 'OPERATIONS', 90, '', 'E01', 0, 0), " "('E21', 'SOFTWARE SUPPORT', 100,'', 'E01', 0, 0)"; - rc= mysql_real_query(mysql, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); /* ****** Begin of trace ****** */ @@ -14474,7 +14754,7 @@ static void test_bug11904() stmt_text= "SELECT id, MIN(name) FROM bug11904b GROUP BY id"; - rc= mysql_stmt_prepare(stmt1, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt1, stmt_text, strlen(stmt_text)); check_execute(stmt1, rc); memset(my_bind, 0, sizeof(my_bind)); @@ -14550,14 +14830,14 @@ static void test_bug12243() stmt_text= "select a from t1"; - rc= mysql_stmt_prepare(stmt1, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt1, stmt_text, strlen(stmt_text)); check_execute(stmt1, rc); rc= mysql_stmt_execute(stmt1); check_execute(stmt1, rc); rc= mysql_stmt_fetch(stmt1); check_execute(stmt1, rc); - rc= mysql_stmt_prepare(stmt2, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt2, stmt_text, strlen(stmt_text)); check_execute(stmt2, rc); rc= mysql_stmt_execute(stmt2); check_execute(stmt2, rc); @@ -14646,7 +14926,7 @@ static void test_bug14210() itself is not InnoDB related. In case the table is MyISAM this test is harmless. */ - mysql_query(mysql, "create table t1 (a varchar(255)) type=InnoDB"); + mysql_query(mysql, "create table t1 (a varchar(255)) engine=InnoDB"); rc= mysql_query(mysql, "insert into t1 (a) values (repeat('a', 256))"); myquery(rc); rc= mysql_query(mysql, "set @@session.max_heap_table_size=16384"); @@ -14663,7 +14943,7 @@ static void test_bug14210() stmt_text= "select a from t1"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); while ((rc= mysql_stmt_fetch(stmt)) == 0) @@ -14717,7 +14997,7 @@ static void test_bug13488() rc= mysql_stmt_attr_set(stmt1,STMT_ATTR_CURSOR_TYPE, (const void *)&type); check_execute(stmt1, rc); - rc= mysql_stmt_prepare(stmt1, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt1, query, strlen(query)); check_execute(stmt1, rc); rc= mysql_stmt_execute(stmt1); @@ -14772,7 +15052,7 @@ static void test_bug13524() rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); check_execute(stmt, rc); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); @@ -14831,7 +15111,7 @@ static void test_bug14845() rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); check_execute(stmt, rc); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); @@ -14867,7 +15147,7 @@ static void test_bug15510() stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); @@ -15007,6 +15287,24 @@ static void test_bug16143() } +/* Bug #16144: mysql_stmt_attr_get type error */ + +static void test_bug16144() +{ + const my_bool flag_orig= (my_bool) 0xde; + my_bool flag= flag_orig; + MYSQL_STMT *stmt; + myheader("test_bug16144"); + + /* Check that attr_get returns correct data on little and big endian CPUs */ + stmt= mysql_stmt_init(mysql); + mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (const void*) &flag); + mysql_stmt_attr_get(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*) &flag); + DIE_UNLESS(flag == flag_orig); + + mysql_stmt_close(stmt); +} + /* Bug #15613: "libmysqlclient API function mysql_stmt_prepare returns wrong field length" @@ -15039,7 +15337,7 @@ static void test_bug15613() /* II. Check SELECT metadata */ stmt_text= ("select t, tt, mt, lt, vl, vb, vu from t1"); - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); metadata= mysql_stmt_result_metadata(stmt); field= mysql_fetch_fields(metadata); if (!opt_silent) @@ -15107,8 +15405,30 @@ static void test_bug17667() myheader("test_bug17667"); + master_log_filename = (char *) malloc(strlen(opt_vardir) + strlen("/log/master.log") + 1); + strxmov(master_log_filename, opt_vardir, "/log/master.log", NullS); + if (!opt_silent) + printf("Opening '%s'\n", master_log_filename); + log_file= my_fopen(master_log_filename, (int) (O_RDONLY | O_BINARY), MYF(0)); + free(master_log_filename); + + if (log_file == NULL) + { + if (!opt_silent) + { + printf("Could not find the log file, VARDIR/log/master.log, so " + "test_bug17667 is not run.\n" + "Run test from the mysql-test/mysql-test-run* program to set up " + "correct environment for this test.\n\n"); + } + return; + } + + enable_general_log(1); + for (statement_cursor= statements; statement_cursor->buffer != NULL; - statement_cursor++) { + statement_cursor++) + { if (statement_cursor->qt == QT_NORMAL) { /* Run statement as normal query */ @@ -15119,10 +15439,10 @@ static void test_bug17667() else if (statement_cursor->qt == QT_PREPARED) { /* - Run as prepared statement + Run as prepared statement - NOTE! All these queries should be in the log twice, - one time for prepare and one time for execute + NOTE! All these queries should be in the log twice, + one time for prepare and one time for execute */ stmt= mysql_stmt_init(mysql); @@ -15145,66 +15465,51 @@ static void test_bug17667() rc= mysql_query(mysql, "flush logs"); myquery(rc); - master_log_filename = (char *) malloc(strlen(opt_vardir) + strlen("/log/master.log") + 1); - strcpy(master_log_filename, opt_vardir); - strcat(master_log_filename, "/log/master.log"); - printf("Opening '%s'\n", master_log_filename); - log_file= my_fopen(master_log_filename, (int) (O_RDONLY | O_BINARY), MYF(MY_WME)); - free(master_log_filename); + for (statement_cursor= statements; statement_cursor->buffer != NULL; + statement_cursor++) + { + int expected_hits= 1, hits= 0; + char line_buffer[MAX_TEST_QUERY_LENGTH*2]; + /* more than enough room for the query and some marginalia. */ + + /* Prepared statments always occurs twice in log */ + if (statement_cursor->qt == QT_PREPARED) + expected_hits++; - if (log_file != NULL) { + /* Loop until we found expected number of log entries */ + do { + /* Loop until statement is found in log */ + do { + memset(line_buffer, '/', MAX_TEST_QUERY_LENGTH*2); - for (statement_cursor= statements; statement_cursor->buffer != NULL; - statement_cursor++) { - int expected_hits= 1, hits= 0; - char line_buffer[MAX_TEST_QUERY_LENGTH*2]; - /* more than enough room for the query and some marginalia. */ + if(fgets(line_buffer, MAX_TEST_QUERY_LENGTH*2, log_file) == NULL) + { + /* If fgets returned NULL, it indicates either error or EOF */ + if (feof(log_file)) + DIE("Found EOF before all statements where found"); - /* Prepared statments always occurs twice in log */ - if (statement_cursor->qt == QT_PREPARED) - expected_hits++; + fprintf(stderr, "Got error %d while reading from file\n", + ferror(log_file)); + DIE("Read error"); + } - /* Loop until we found expected number of log entries */ - do { - /* Loop until statement is found in log */ - do { - memset(line_buffer, '/', MAX_TEST_QUERY_LENGTH*2); - - if(fgets(line_buffer, MAX_TEST_QUERY_LENGTH*2, log_file) == NULL) - { - /* If fgets returned NULL, it indicates either error or EOF */ - if (feof(log_file)) - DIE("Found EOF before all statements where found"); - - fprintf(stderr, "Got error %d while reading from file\n", - ferror(log_file)); - DIE("Read error"); - } - - } while (my_memmem(line_buffer, MAX_TEST_QUERY_LENGTH*2, - statement_cursor->buffer, - statement_cursor->length) == NULL); - hits++; - } while (hits < expected_hits); + } while (my_memmem(line_buffer, MAX_TEST_QUERY_LENGTH*2, + statement_cursor->buffer, + statement_cursor->length) == NULL); + hits++; + } while (hits < expected_hits); + if (!opt_silent) printf("Found statement starting with \"%s\"\n", statement_cursor->buffer); - } - - printf("success. All queries found intact in the log.\n"); - - } - else - { - fprintf(stderr, "Could not find the log file, VARDIR/log/master.log, so " - "test_bug17667 is \ninconclusive. Run test from the " - "mysql-test/mysql-test-run* program \nto set up the correct " - "environment for this test.\n\n"); } - if (log_file != NULL) - my_fclose(log_file, MYF(0)); + restore_general_log(); + + if (!opt_silent) + printf("success. All queries found intact in the log.\n"); + my_fclose(log_file, MYF(0)); } @@ -15233,7 +15538,7 @@ static void test_bug14169() myquery(rc); stmt= mysql_stmt_init(mysql); stmt_text= "select f2,group_concat(f1) from t1 group by f2"; - rc= mysql_stmt_prepare(stmt, stmt_text, (uint) strlen(stmt_text)); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); myquery(rc); res= mysql_stmt_result_metadata(stmt); field= mysql_fetch_fields(res); @@ -15248,7 +15553,6 @@ static void test_bug14169() myquery(rc); } - /* Test that mysql_insert_id() behaves as documented in our manual */ @@ -15406,13 +15710,17 @@ static void test_mysql_insert_id() rc= mysql_query(mysql, "insert ignore into t2 values (null,'e'),(12,'c'),(null,'d')"); myquery(rc); res= mysql_insert_id(mysql); - DIE_UNLESS(res == 3); + /* + Behaviour change: old code returned 3 (first autogenerated, even if it + fails); we now return first successful autogenerated. + */ + DIE_UNLESS(res == 13); /* UPDATE may update mysql_insert_id() if it uses LAST_INSERT_ID(#) */ rc= mysql_query(mysql, "update t2 set f1=14 where f1=12"); myquery(rc); res= mysql_insert_id(mysql); DIE_UNLESS(res == 0); - rc= mysql_query(mysql, "update t2 set f1=NULL where f1=14"); + rc= mysql_query(mysql, "update t2 set f1=0 where f1=14"); myquery(rc); res= mysql_insert_id(mysql); DIE_UNLESS(res == 0); @@ -15444,7 +15752,6 @@ static void test_mysql_insert_id() myquery(rc); } - /* Bug#20152: mysql_stmt_execute() writes to MYSQL_TYPE_DATE buffer */ @@ -15476,7 +15783,7 @@ static void test_bug20152() myquery(rc); stmt= mysql_stmt_init(mysql); - rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_execute(stmt, rc); rc= mysql_stmt_bind_param(stmt, my_bind); check_execute(stmt, rc); @@ -15521,11 +15828,11 @@ static void test_bug15752() printf("Unable connect to MySQL server: %s\n", mysql_error(&mysql_local)); DIE_UNLESS(0); } - rc= mysql_real_query(&mysql_local, query, (uint) strlen(query)); + rc= mysql_real_query(&mysql_local, query, strlen(query)); myquery(rc); mysql_free_result(mysql_store_result(&mysql_local)); - rc= mysql_real_query(&mysql_local, query, (uint) strlen(query)); + rc= mysql_real_query(&mysql_local, query, strlen(query)); DIE_UNLESS(rc && mysql_errno(&mysql_local) == CR_COMMANDS_OUT_OF_SYNC); if (! opt_silent) @@ -15540,7 +15847,7 @@ static void test_bug15752() /* The second problem is not reproducible: add the test case */ for (i = 0; i < ITERATION_COUNT; i++) { - if (mysql_real_query(&mysql_local, query, (uint) strlen(query))) + if (mysql_real_query(&mysql_local, query, strlen(query))) { printf("\ni=%d %s failed: %s\n", i, query, mysql_error(&mysql_local)); break; @@ -15587,7 +15894,7 @@ static void test_bug21206() for (fetch= fetch_array; fetch < fetch_array + cursor_count; ++fetch) { /* Init will exit(1) in case of error */ - stmt_fetch_init(fetch, (uint) (fetch - fetch_array), query); + stmt_fetch_init(fetch, fetch - fetch_array, query); } for (fetch= fetch_array; fetch < fetch_array + cursor_count; ++fetch) @@ -15599,11 +15906,31 @@ static void test_bug21206() } /* + Ensure we execute the status code while testing +*/ + +static void test_status() +{ + const char *status; + DBUG_ENTER("test_status"); + myheader("test_status"); + + if (!(status= mysql_stat(mysql))) + { + myerror("mysql_stat failed"); /* purecov: inspected */ + die(__FILE__, __LINE__, "mysql_stat failed"); /* purecov: inspected */ + } + DBUG_VOID_RETURN; +} + +/* 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). + select_query added to test for bug + #26921 Problem in mysql_insert_id() Embedded C API function */ static void test_bug21726() { @@ -15616,6 +15943,8 @@ static void test_bug21726() const char *update_query= "UPDATE t1 SET i= LAST_INSERT_ID(i + 1)"; int rc; my_ulonglong insert_id; + const char *select_query= "SELECT * FROM t1"; + MYSQL_RES *result; DBUG_ENTER("test_bug21726"); myheader("test_bug21726"); @@ -15632,6 +15961,13 @@ static void test_bug21726() insert_id= mysql_insert_id(mysql); DIE_UNLESS(insert_id == 3); + rc= mysql_query(mysql, select_query); + myquery(rc); + insert_id= mysql_insert_id(mysql); + DIE_UNLESS(insert_id == 3); + result= mysql_store_result(mysql); + mysql_free_result(result); + DBUG_VOID_RETURN; } @@ -15682,7 +16018,7 @@ static void test_bug23383() stmt= mysql_stmt_init(mysql); DIE_UNLESS(stmt != 0); - rc= mysql_stmt_prepare(stmt, insert_query, (uint) strlen(insert_query)); + rc= mysql_stmt_prepare(stmt, insert_query, strlen(insert_query)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); @@ -15695,7 +16031,7 @@ static void test_bug23383() row_count= mysql_stmt_affected_rows(stmt); DIE_UNLESS(row_count == (my_ulonglong)-1); - rc= mysql_stmt_prepare(stmt, update_query, (uint) strlen(update_query)); + rc= mysql_stmt_prepare(stmt, update_query, strlen(update_query)); check_execute(stmt, rc); rc= mysql_stmt_execute(stmt); @@ -15761,23 +16097,27 @@ static void test_bug21635() rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)"); myquery(rc); - rc= mysql_real_query(mysql, query, (uint) (query_end - query)); + rc= mysql_real_query(mysql, query, query_end - query); myquery(rc); result= mysql_use_result(mysql); DIE_UNLESS(result); - field_count= mysql_field_count(mysql); - for (i= 0; i < field_count; ++i) - { - field= mysql_fetch_field_direct(result, i); - printf("%s -> %s ... ", expr[i * 2], field->name); - fflush(stdout); - DIE_UNLESS(field->db[0] == 0 && field->org_table[0] == 0 && - field->table[0] == 0 && field->org_name[0] == 0); - DIE_UNLESS(strcmp(field->name, expr[i * 2 + 1]) == 0); - puts("OK"); - } + field_count= mysql_field_count(mysql); + for (i= 0; i < field_count; ++i) + { + field= mysql_fetch_field_direct(result, i); + if (!opt_silent) + if (!opt_silent) + printf("%s -> %s ... ", expr[i * 2], field->name); + fflush(stdout); + DIE_UNLESS(field->db[0] == 0 && field->org_table[0] == 0 && + field->table[0] == 0 && field->org_name[0] == 0); + DIE_UNLESS(strcmp(field->name, expr[i * 2 + 1]) == 0); + if (!opt_silent) + if (!opt_silent) + puts("OK"); + } mysql_free_result(result); } @@ -15816,15 +16156,129 @@ static void test_bug24179() } +/** + Bug#32265 Server returns different metadata if prepared statement is used +*/ + +static void test_bug32265() +{ + int rc; + MYSQL_STMT *stmt; + MYSQL_FIELD *field; + MYSQL_RES *metadata; + + DBUG_ENTER("test_bug32265"); + myheader("test_bug32265"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + myquery(rc); + rc= mysql_query(mysql, "CREATE TABLE t1 (a INTEGER)"); + myquery(rc); + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)"); + myquery(rc); + rc= mysql_query(mysql, "CREATE VIEW v1 AS SELECT * FROM t1"); + myquery(rc); + + stmt= open_cursor("SELECT * FROM t1"); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + metadata= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_field(metadata); + DIE_UNLESS(field); + DIE_UNLESS(strcmp(field->table, "t1") == 0); + DIE_UNLESS(strcmp(field->org_table, "t1") == 0); + DIE_UNLESS(strcmp(field->db, "client_test_db") == 0); + mysql_free_result(metadata); + mysql_stmt_close(stmt); + + stmt= open_cursor("SELECT a '' FROM t1 ``"); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + metadata= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_field(metadata); + DIE_UNLESS(strcmp(field->table, "") == 0); + DIE_UNLESS(strcmp(field->org_table, "t1") == 0); + DIE_UNLESS(strcmp(field->db, "client_test_db") == 0); + mysql_free_result(metadata); + mysql_stmt_close(stmt); + + stmt= open_cursor("SELECT a '' FROM t1 ``"); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + metadata= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_field(metadata); + DIE_UNLESS(strcmp(field->table, "") == 0); + DIE_UNLESS(strcmp(field->org_table, "t1") == 0); + DIE_UNLESS(strcmp(field->db, "client_test_db") == 0); + mysql_free_result(metadata); + mysql_stmt_close(stmt); + + stmt= open_cursor("SELECT * FROM v1"); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + metadata= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_field(metadata); + DIE_UNLESS(strcmp(field->table, "v1") == 0); + DIE_UNLESS(strcmp(field->org_table, "v1") == 0); + DIE_UNLESS(strcmp(field->db, "client_test_db") == 0); + mysql_free_result(metadata); + mysql_stmt_close(stmt); + + stmt= open_cursor("SELECT * FROM v1 /* SIC */ GROUP BY 1"); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + metadata= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_field(metadata); + DIE_UNLESS(strcmp(field->table, "v1") == 0); + DIE_UNLESS(strcmp(field->org_table, "v1") == 0); + DIE_UNLESS(strcmp(field->db, "client_test_db") == 0); + mysql_free_result(metadata); + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP VIEW v1"); + myquery(rc); + rc= mysql_query(mysql, "DROP TABLE t1"); + myquery(rc); + + DBUG_VOID_RETURN; +} + +/* + Bug#28075 "COM_DEBUG crashes mysqld" +*/ + +static void test_bug28075() +{ + int rc; + + DBUG_ENTER("test_bug28075"); + myheader("test_bug28075"); + + rc= mysql_dump_debug_info(mysql); + DIE_UNLESS(rc == 0); + + rc= mysql_ping(mysql); + DIE_UNLESS(rc == 0); + + DBUG_VOID_RETURN; +} + + /* Bug#27876 (SF with cyrillic variable name fails during execution (regression)) */ + static void test_bug27876() { int rc; MYSQL_RES *result; - unsigned char utf8_func[] = + uchar utf8_func[] = { 0xd1, 0x84, 0xd1, 0x83, 0xd0, 0xbd, 0xd0, 0xba, 0xd1, 0x86, 0xd0, 0xb8, 0xd0, 0xb9, 0xd0, 0xba, @@ -15832,7 +16286,7 @@ static void test_bug27876() 0x00 }; - unsigned char utf8_param[] = + uchar utf8_param[] = { 0xd0, 0xbf, 0xd0, 0xb0, 0xd1, 0x80, 0xd0, 0xb0, 0xd0, 0xbc, 0xd0, 0xb5, 0xd1, 0x82, 0xd1, 0x8a, @@ -15855,24 +16309,24 @@ static void test_bug27876() mytest(result); mysql_free_result(result); - sprintf(query, "DROP FUNCTION IF EXISTS %s", utf8_func); + sprintf(query, "DROP FUNCTION IF EXISTS %s", (char*) utf8_func); rc= mysql_query(mysql, query); myquery(rc); sprintf(query, "CREATE FUNCTION %s( %s VARCHAR(25))" " RETURNS VARCHAR(25) DETERMINISTIC RETURN %s", - utf8_func, utf8_param, utf8_param); + (char*) utf8_func, (char*) utf8_param, (char*) utf8_param); rc= mysql_query(mysql, query); myquery(rc); - sprintf(query, "SELECT %s(VERSION())", utf8_func); + sprintf(query, "SELECT %s(VERSION())", (char*) utf8_func); rc= mysql_query(mysql, query); myquery(rc); result= mysql_store_result(mysql); mytest(result); mysql_free_result(result); - sprintf(query, "DROP FUNCTION %s", utf8_func); + sprintf(query, "DROP FUNCTION %s", (char*) utf8_func); rc= mysql_query(mysql, query); myquery(rc); @@ -15937,6 +16391,227 @@ static void test_bug28934() myquery(mysql_query(mysql, "drop table t1")); } +/* + Test mysql_change_user() C API and COM_CHANGE_USER +*/ + +static void test_change_user() +{ + char buff[256]; + const char *user_pw= "mysqltest_pw"; + const char *user_no_pw= "mysqltest_no_pw"; + const char *pw= "password"; + const char *db= "mysqltest_user_test_database"; + int rc; + + DBUG_ENTER("test_change_user"); + myheader("test_change_user"); + + /* Prepare environment */ + sprintf(buff, "drop database if exists %s", db); + rc= mysql_query(mysql, buff); + myquery(rc); + + sprintf(buff, "create database %s", db); + rc= mysql_query(mysql, buff); + myquery(rc); + + sprintf(buff, + "grant select on %s.* to %s@'%%' identified by '%s'", + db, + user_pw, + pw); + rc= mysql_query(mysql, buff); + myquery(rc); + + sprintf(buff, + "grant select on %s.* to %s@'localhost' identified by '%s'", + db, + user_pw, + pw); + rc= mysql_query(mysql, buff); + myquery(rc); + + sprintf(buff, + "grant select on %s.* to %s@'%%'", + db, + user_no_pw); + rc= mysql_query(mysql, buff); + myquery(rc); + + sprintf(buff, + "grant select on %s.* to %s@'localhost'", + db, + user_no_pw); + rc= mysql_query(mysql, buff); + myquery(rc); + + + /* Try some combinations */ + rc= mysql_change_user(mysql, NULL, NULL, NULL); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + + rc= mysql_change_user(mysql, "", NULL, NULL); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, "", "", NULL); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, "", "", ""); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, NULL, "", ""); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + + rc= mysql_change_user(mysql, NULL, NULL, ""); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, "", NULL, ""); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, user_pw, NULL, ""); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, user_pw, "", ""); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, user_pw, "", NULL); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, user_pw, NULL, NULL); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, user_pw, "", db); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, user_pw, NULL, db); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, user_pw, pw, db); + myquery(rc); + + rc= mysql_change_user(mysql, user_pw, pw, NULL); + myquery(rc); + + rc= mysql_change_user(mysql, user_pw, pw, ""); + myquery(rc); + + rc= mysql_change_user(mysql, user_no_pw, pw, db); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, user_no_pw, pw, ""); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, user_no_pw, pw, NULL); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, user_no_pw, "", NULL); + myquery(rc); + + rc= mysql_change_user(mysql, user_no_pw, "", ""); + myquery(rc); + + rc= mysql_change_user(mysql, user_no_pw, "", db); + myquery(rc); + + rc= mysql_change_user(mysql, user_no_pw, NULL, db); + myquery(rc); + + rc= mysql_change_user(mysql, "", pw, db); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, "", pw, ""); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, "", pw, NULL); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, NULL, pw, NULL); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, NULL, NULL, db); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, NULL, "", db); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + rc= mysql_change_user(mysql, "", "", db); + DIE_UNLESS(rc); + if (! opt_silent) + printf("Got error (as expected): %s\n", mysql_error(mysql)); + + /* Cleanup the environment */ + + mysql_change_user(mysql, opt_user, opt_password, current_db); + + sprintf(buff, "drop database %s", db); + rc= mysql_query(mysql, buff); + myquery(rc); + + sprintf(buff, "drop user %s@'%%'", user_pw); + rc= mysql_query(mysql, buff); + myquery(rc); + + sprintf(buff, "drop user %s@'%%'", user_no_pw); + rc= mysql_query(mysql, buff); + myquery(rc); + + sprintf(buff, "drop user %s@'localhost'", user_pw); + rc= mysql_query(mysql, buff); + myquery(rc); + + sprintf(buff, "drop user %s@'localhost'", user_no_pw); + rc= mysql_query(mysql, buff); + myquery(rc); + + DBUG_VOID_RETURN; +} /* Bug#27592 (stack overrun when storing datetime value using prepared statements) @@ -15990,6 +16665,67 @@ static void test_bug27592() DBUG_VOID_RETURN; } +/* + Bug#29687 mysql_stmt_store_result memory leak in libmysqld +*/ + +static void test_bug29687() +{ + const int NUM_ITERATIONS= 40; + int i; + int rc; + MYSQL_STMT *stmt= NULL; + + DBUG_ENTER("test_bug29687"); + myheader("test_bug29687"); + + stmt= mysql_simple_prepare(mysql, "SELECT 1 FROM dual WHERE 0=2"); + DIE_UNLESS(stmt); + + for (i= 0; i < NUM_ITERATIONS; i++) + { + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + mysql_stmt_store_result(stmt); + while (mysql_stmt_fetch(stmt)==0); + mysql_stmt_free_result(stmt); + } + + mysql_stmt_close(stmt); + DBUG_VOID_RETURN; +} + + +/* + Bug #29692 Single row inserts can incorrectly report a huge number of + row insertions +*/ + +static void test_bug29692() +{ + MYSQL* conn; + + if (!(conn= mysql_init(NULL))) + { + myerror("test_bug29692 init failed"); + exit(1); + } + + if (!(mysql_real_connect(conn, opt_host, opt_user, + opt_password, opt_db ? opt_db:"test", opt_port, + opt_unix_socket, CLIENT_FOUND_ROWS))) + { + myerror("test_bug29692 connection failed"); + mysql_close(mysql); + exit(1); + } + myquery(mysql_query(conn, "drop table if exists t1")); + myquery(mysql_query(conn, "create table t1(f1 int)")); + myquery(mysql_query(conn, "insert into t1 values(1)")); + DIE_UNLESS(1 == mysql_affected_rows(conn)); + myquery(mysql_query(conn, "drop table t1")); + mysql_close(conn); +} /** Bug#29306 Truncated data in MS Access with decimal (3,1) columns in a VIEW @@ -16039,227 +16775,172 @@ static void test_bug29306() DBUG_VOID_RETURN; } - - -/** - Bug#31669 Buffer overflow in mysql_change_user() +/* + Bug#30472: libmysql doesn't reset charset, insert_id after succ. + mysql_change_user() call row insertions. */ -#define LARGE_BUFFER_SIZE 2048 - -static void test_bug31669() +static void bug30472_retrieve_charset_info(MYSQL *con, + char *character_set_name, + char *character_set_client, + char *character_set_results, + char *collation_connection) { - int rc; - static char buff[LARGE_BUFFER_SIZE+1]; -#ifndef EMBEDDED_LIBRARY - static char user[USERNAME_LENGTH+1]; - static char db[NAME_LEN+1]; - static char query[LARGE_BUFFER_SIZE*2]; -#endif - - DBUG_ENTER("test_bug31669"); - myheader("test_bug31669"); - - rc= mysql_change_user(mysql, NULL, NULL, NULL); - DIE_UNLESS(rc); - - rc= mysql_change_user(mysql, "", "", ""); - DIE_UNLESS(rc); - - memset(buff, 'a', sizeof(buff)); + MYSQL_RES *rs; + MYSQL_ROW row; - rc= mysql_change_user(mysql, buff, buff, buff); - DIE_UNLESS(rc); + /* Get the cached client character set name. */ - rc = mysql_change_user(mysql, opt_user, opt_password, current_db); - DIE_UNLESS(!rc); + strcpy(character_set_name, mysql_character_set_name(con)); -#ifndef EMBEDDED_LIBRARY - memset(db, 'a', sizeof(db)); - db[NAME_LEN]= 0; - strxmov(query, "CREATE DATABASE IF NOT EXISTS ", db, NullS); - rc= mysql_query(mysql, query); - myquery(rc); - - memset(user, 'b', sizeof(user)); - user[USERNAME_LENGTH]= 0; - memset(buff, 'c', sizeof(buff)); - buff[LARGE_BUFFER_SIZE]= 0; - strxmov(query, "GRANT ALL PRIVILEGES ON *.* TO '", user, "'@'%' IDENTIFIED BY " - "'", buff, "' WITH GRANT OPTION", NullS); - rc= mysql_query(mysql, query); - myquery(rc); + /* Retrieve server character set information. */ - strxmov(query, "GRANT ALL PRIVILEGES ON *.* TO '", user, "'@'localhost' IDENTIFIED BY " - "'", buff, "' WITH GRANT OPTION", NullS); - rc= mysql_query(mysql, query); - myquery(rc); + DIE_IF(mysql_query(con, "SHOW VARIABLES LIKE 'character_set_client'")); + DIE_UNLESS(rs= mysql_store_result(con)); + DIE_UNLESS(row= mysql_fetch_row(rs)); + strcpy(character_set_client, row[1]); + mysql_free_result(rs); - rc= mysql_query(mysql, "FLUSH PRIVILEGES"); - myquery(rc); + DIE_IF(mysql_query(con, "SHOW VARIABLES LIKE 'character_set_results'")); + DIE_UNLESS(rs= mysql_store_result(con)); + DIE_UNLESS(row= mysql_fetch_row(rs)); + strcpy(character_set_results, row[1]); + mysql_free_result(rs); - rc= mysql_change_user(mysql, user, buff, db); - DIE_UNLESS(!rc); + DIE_IF(mysql_query(con, "SHOW VARIABLES LIKE 'collation_connection'")); + DIE_UNLESS(rs= mysql_store_result(con)); + DIE_UNLESS(row= mysql_fetch_row(rs)); + strcpy(collation_connection, row[1]); + mysql_free_result(rs); +} - user[USERNAME_LENGTH-1]= 'a'; - rc= mysql_change_user(mysql, user, buff, db); - DIE_UNLESS(rc); +static void test_bug30472() +{ + MYSQL con; - user[USERNAME_LENGTH-1]= 'b'; - buff[LARGE_BUFFER_SIZE-1]= 'd'; - rc= mysql_change_user(mysql, user, buff, db); - DIE_UNLESS(rc); + char character_set_name_1[MY_CS_NAME_SIZE]; + char character_set_client_1[MY_CS_NAME_SIZE]; + char character_set_results_1[MY_CS_NAME_SIZE]; + char collation_connnection_1[MY_CS_NAME_SIZE]; - buff[LARGE_BUFFER_SIZE-1]= 'c'; - db[NAME_LEN-1]= 'e'; - rc= mysql_change_user(mysql, user, buff, db); - DIE_UNLESS(rc); + char character_set_name_2[MY_CS_NAME_SIZE]; + char character_set_client_2[MY_CS_NAME_SIZE]; + char character_set_results_2[MY_CS_NAME_SIZE]; + char collation_connnection_2[MY_CS_NAME_SIZE]; - db[NAME_LEN-1]= 'a'; - rc= mysql_change_user(mysql, user, buff, db); - DIE_UNLESS(!rc); + char character_set_name_3[MY_CS_NAME_SIZE]; + char character_set_client_3[MY_CS_NAME_SIZE]; + char character_set_results_3[MY_CS_NAME_SIZE]; + char collation_connnection_3[MY_CS_NAME_SIZE]; - rc= mysql_change_user(mysql, user + 1, buff + 1, db + 1); - DIE_UNLESS(rc); + char character_set_name_4[MY_CS_NAME_SIZE]; + char character_set_client_4[MY_CS_NAME_SIZE]; + char character_set_results_4[MY_CS_NAME_SIZE]; + char collation_connnection_4[MY_CS_NAME_SIZE]; - rc = mysql_change_user(mysql, opt_user, opt_password, current_db); - DIE_UNLESS(!rc); + /* Create a new connection. */ - strxmov(query, "DROP DATABASE ", db, NullS); - rc= mysql_query(mysql, query); - myquery(rc); + DIE_UNLESS(mysql_init(&con)); - strxmov(query, "DELETE FROM mysql.user WHERE User='", user, "'", NullS); - rc= mysql_query(mysql, query); - myquery(rc); - DIE_UNLESS(mysql_affected_rows(mysql) == 2); -#endif + DIE_UNLESS(mysql_real_connect(&con, + opt_host, + opt_user, + opt_password, + opt_db ? opt_db : "test", + opt_port, + opt_unix_socket, + CLIENT_FOUND_ROWS)); - DBUG_VOID_RETURN; -} + /* Retrieve character set information. */ + bug30472_retrieve_charset_info(&con, + character_set_name_1, + character_set_client_1, + character_set_results_1, + collation_connnection_1); -/** - Bug#32265 Server returns different metadata if prepared statement is used -*/ + /* Switch client character set. */ -static void test_bug32265() -{ - int rc; - MYSQL_STMT *stmt; - MYSQL_FIELD *field; - MYSQL_RES *metadata; + DIE_IF(mysql_set_character_set(&con, "utf8")); - DBUG_ENTER("test_bug32265"); - myheader("test_bug32265"); + /* Retrieve character set information. */ - rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); - myquery(rc); - rc= mysql_query(mysql, "CREATE TABLE t1 (a INTEGER)"); - myquery(rc); - rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)"); - myquery(rc); - rc= mysql_query(mysql, "CREATE VIEW v1 AS SELECT * FROM t1"); - myquery(rc); + bug30472_retrieve_charset_info(&con, + character_set_name_2, + character_set_client_2, + character_set_results_2, + collation_connnection_2); - stmt= open_cursor("SELECT * FROM t1"); - rc= mysql_stmt_execute(stmt); - check_execute(stmt, rc); + /* + Check that + 1) character set has been switched and + 2) new character set is different from the original one. + */ - metadata= mysql_stmt_result_metadata(stmt); - field= mysql_fetch_field(metadata); - DIE_UNLESS(field); - DIE_UNLESS(strcmp(field->table, "t1") == 0); - DIE_UNLESS(strcmp(field->org_table, "t1") == 0); - DIE_UNLESS(strcmp(field->db, "client_test_db") == 0); - mysql_free_result(metadata); - mysql_stmt_close(stmt); + DIE_UNLESS(strcmp(character_set_name_2, "utf8") == 0); + DIE_UNLESS(strcmp(character_set_client_2, "utf8") == 0); + DIE_UNLESS(strcmp(character_set_results_2, "utf8") == 0); + DIE_UNLESS(strcmp(collation_connnection_2, "utf8_general_ci") == 0); - stmt= open_cursor("SELECT a '' FROM t1 ``"); - rc= mysql_stmt_execute(stmt); - check_execute(stmt, rc); + DIE_UNLESS(strcmp(character_set_name_1, character_set_name_2) != 0); + DIE_UNLESS(strcmp(character_set_client_1, character_set_client_2) != 0); + DIE_UNLESS(strcmp(character_set_results_1, character_set_results_2) != 0); + DIE_UNLESS(strcmp(collation_connnection_1, collation_connnection_2) != 0); - metadata= mysql_stmt_result_metadata(stmt); - field= mysql_fetch_field(metadata); - DIE_UNLESS(strcmp(field->table, "") == 0); - DIE_UNLESS(strcmp(field->org_table, "t1") == 0); - DIE_UNLESS(strcmp(field->db, "client_test_db") == 0); - mysql_free_result(metadata); - mysql_stmt_close(stmt); + /* Call mysql_change_user() with the same username, password, database. */ - stmt= open_cursor("SELECT a '' FROM t1 ``"); - rc= mysql_stmt_execute(stmt); - check_execute(stmt, rc); + DIE_IF(mysql_change_user(&con, + opt_user, + opt_password, + opt_db ? opt_db : "test")); - metadata= mysql_stmt_result_metadata(stmt); - field= mysql_fetch_field(metadata); - DIE_UNLESS(strcmp(field->table, "") == 0); - DIE_UNLESS(strcmp(field->org_table, "t1") == 0); - DIE_UNLESS(strcmp(field->db, "client_test_db") == 0); - mysql_free_result(metadata); - mysql_stmt_close(stmt); + /* Retrieve character set information. */ - stmt= open_cursor("SELECT * FROM v1"); - rc= mysql_stmt_execute(stmt); - check_execute(stmt, rc); + bug30472_retrieve_charset_info(&con, + character_set_name_3, + character_set_client_3, + character_set_results_3, + collation_connnection_3); - metadata= mysql_stmt_result_metadata(stmt); - field= mysql_fetch_field(metadata); - DIE_UNLESS(strcmp(field->table, "v1") == 0); - DIE_UNLESS(strcmp(field->org_table, "v1") == 0); - DIE_UNLESS(strcmp(field->db, "client_test_db") == 0); - mysql_free_result(metadata); - mysql_stmt_close(stmt); + /* Check that character set information has been reset. */ - stmt= open_cursor("SELECT * FROM v1 /* SIC */ GROUP BY 1"); - rc= mysql_stmt_execute(stmt); - check_execute(stmt, rc); + DIE_UNLESS(strcmp(character_set_name_1, character_set_name_3) == 0); + DIE_UNLESS(strcmp(character_set_client_1, character_set_client_3) == 0); + DIE_UNLESS(strcmp(character_set_results_1, character_set_results_3) == 0); + DIE_UNLESS(strcmp(collation_connnection_1, collation_connnection_3) == 0); - metadata= mysql_stmt_result_metadata(stmt); - field= mysql_fetch_field(metadata); - DIE_UNLESS(strcmp(field->table, "v1") == 0); - DIE_UNLESS(strcmp(field->org_table, "v1") == 0); - DIE_UNLESS(strcmp(field->db, "client_test_db") == 0); - mysql_free_result(metadata); - mysql_stmt_close(stmt); + /* Change connection-default character set in the client. */ - rc= mysql_query(mysql, "DROP VIEW v1"); - myquery(rc); - rc= mysql_query(mysql, "DROP TABLE t1"); - myquery(rc); + mysql_options(&con, MYSQL_SET_CHARSET_NAME, "utf8"); - DBUG_VOID_RETURN; -} + /* + Call mysql_change_user() in order to check that new connection will + have UTF8 character set on the client and on the server. + */ + DIE_IF(mysql_change_user(&con, + opt_user, + opt_password, + opt_db ? opt_db : "test")); -/** - Bug#38486 Crash when using cursor protocol -*/ + /* Retrieve character set information. */ -static void test_bug38486(void) -{ - MYSQL_STMT *stmt; - const char *stmt_text; - unsigned long type= CURSOR_TYPE_READ_ONLY; + bug30472_retrieve_charset_info(&con, + character_set_name_4, + character_set_client_4, + character_set_results_4, + collation_connnection_4); - DBUG_ENTER("test_bug38486"); - myheader("test_bug38486"); + /* Check that we have UTF8 on the server and on the client. */ - stmt= mysql_stmt_init(mysql); - mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*)&type); - stmt_text= "CREATE TABLE t1 (a INT)"; - mysql_stmt_prepare(stmt, stmt_text, (ulong) strlen(stmt_text)); - mysql_stmt_execute(stmt); - mysql_stmt_close(stmt); + DIE_UNLESS(strcmp(character_set_name_4, "utf8") == 0); + DIE_UNLESS(strcmp(character_set_client_4, "utf8") == 0); + DIE_UNLESS(strcmp(character_set_results_4, "utf8") == 0); + DIE_UNLESS(strcmp(collation_connnection_4, "utf8_general_ci") == 0); - stmt= mysql_stmt_init(mysql); - mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*)&type); - stmt_text= "INSERT INTO t1 VALUES (1)"; - mysql_stmt_prepare(stmt, stmt_text, (ulong) strlen(stmt_text)); - mysql_stmt_execute(stmt); - mysql_stmt_close(stmt); + /* That's it. Cleanup. */ - DBUG_VOID_RETURN; + mysql_close(&con); } static void bug20023_change_user(MYSQL *con) @@ -16270,33 +16951,46 @@ static void bug20023_change_user(MYSQL *con) opt_db ? opt_db : "test")); } -static void bug20023_query_str_variable(MYSQL *con, - const char *var_name, - char *str, - size_t len) +static my_bool query_str_variable(MYSQL *con, + const char *var_name, + char *str, + size_t len) { MYSQL_RES *rs; MYSQL_ROW row; char query_buffer[MAX_TEST_QUERY_LENGTH]; + my_bool is_null; + my_snprintf(query_buffer, sizeof (query_buffer), - "SELECT @@%s", var_name); + "SELECT %s", var_name); DIE_IF(mysql_query(con, query_buffer)); DIE_UNLESS(rs= mysql_store_result(con)); DIE_UNLESS(row= mysql_fetch_row(rs)); - my_snprintf(str, len, "%s", row[0]); + + is_null= row[0] == NULL; + + if (!is_null) + my_snprintf(str, len, "%s", row[0]); + mysql_free_result(rs); + + return is_null; } -static void bug20023_query_int_variable(MYSQL *con, - const char *var_name, - int *var_value) +static my_bool query_int_variable(MYSQL *con, + const char *var_name, + int *var_value) { char str[32]; - bug20023_query_str_variable(con, var_name, str, sizeof(str)); - *var_value= atoi(str); + my_bool is_null= query_str_variable(con, var_name, str, sizeof(str)); + + if (!is_null) + *var_value= atoi(str); + + return is_null; } static void test_bug20023() @@ -16332,20 +17026,20 @@ static void test_bug20023() CLIENT_FOUND_ROWS)); /*********************************************************************** - Remember original SQL_BIG_SELECTS, MAX_JOIN_SIZE values. + Remember original SQL_BIG_SELECTS, MAX_JOIN_SIZE values. ***********************************************************************/ - bug20023_query_int_variable(&con, - "session.sql_big_selects", - &sql_big_selects_orig); + query_int_variable(&con, + "@@session.sql_big_selects", + &sql_big_selects_orig); - bug20023_query_str_variable(&con, - "global.max_join_size", - max_join_size_orig, - sizeof(max_join_size_orig)); + query_str_variable(&con, + "@@global.max_join_size", + max_join_size_orig, + sizeof(max_join_size_orig)); /*********************************************************************** - Test that COM_CHANGE_USER resets the SQL_BIG_SELECTS to the initial value. + Test that COM_CHANGE_USER resets the SQL_BIG_SELECTS to the initial value. ***********************************************************************/ /* Issue COM_CHANGE_USER. */ @@ -16354,17 +17048,17 @@ static void test_bug20023() /* Query SQL_BIG_SELECTS. */ - bug20023_query_int_variable(&con, - "session.sql_big_selects", - &sql_big_selects_2); + query_int_variable(&con, + "@@session.sql_big_selects", + &sql_big_selects_2); /* Check that SQL_BIG_SELECTS is reset properly. */ DIE_UNLESS(sql_big_selects_orig == sql_big_selects_2); /*********************************************************************** - Test that if MAX_JOIN_SIZE set to non-default value, - SQL_BIG_SELECTS will be 0. + Test that if MAX_JOIN_SIZE set to non-default value, + SQL_BIG_SELECTS will be 0. ***********************************************************************/ /* Set MAX_JOIN_SIZE to some non-default value. */ @@ -16378,17 +17072,17 @@ static void test_bug20023() /* Query SQL_BIG_SELECTS. */ - bug20023_query_int_variable(&con, - "session.sql_big_selects", - &sql_big_selects_3); + query_int_variable(&con, + "@@session.sql_big_selects", + &sql_big_selects_3); /* Check that SQL_BIG_SELECTS is 0. */ DIE_UNLESS(sql_big_selects_3 == 0); /*********************************************************************** - Test that if MAX_JOIN_SIZE set to default value, - SQL_BIG_SELECTS will be 1. + Test that if MAX_JOIN_SIZE set to default value, + SQL_BIG_SELECTS will be 1. ***********************************************************************/ /* Set MAX_JOIN_SIZE to the default value (-1). */ @@ -16402,17 +17096,17 @@ static void test_bug20023() /* Query SQL_BIG_SELECTS. */ - bug20023_query_int_variable(&con, - "session.sql_big_selects", - &sql_big_selects_4); + query_int_variable(&con, + "@@session.sql_big_selects", + &sql_big_selects_4); /* Check that SQL_BIG_SELECTS is 1. */ DIE_UNLESS(sql_big_selects_4 == 1); /*********************************************************************** - Restore MAX_JOIN_SIZE. - Check that SQL_BIG_SELECTS will be the original one. + Restore MAX_JOIN_SIZE. + Check that SQL_BIG_SELECTS will be the original one. ***********************************************************************/ /* Restore MAX_JOIN_SIZE. */ @@ -16423,6 +17117,8 @@ static void test_bug20023() max_join_size_orig); DIE_IF(mysql_query(&con, query_buffer)); + + DIE_IF(mysql_query(&con, "SET @@global.max_join_size = -1")); DIE_IF(mysql_query(&con, "SET @@session.max_join_size = default")); /* Issue COM_CHANGE_USER. */ @@ -16431,21 +17127,531 @@ static void test_bug20023() /* Query SQL_BIG_SELECTS. */ - bug20023_query_int_variable(&con, - "session.sql_big_selects", - &sql_big_selects_5); + query_int_variable(&con, + "@@session.sql_big_selects", + &sql_big_selects_5); /* Check that SQL_BIG_SELECTS is 1. */ DIE_UNLESS(sql_big_selects_5 == sql_big_selects_orig); /*********************************************************************** + That's it. Cleanup. + ***********************************************************************/ + + mysql_close(&con); +} + +static void bug31418_impl() +{ + MYSQL con; + + my_bool is_null; + int rc; + + /* Create a new connection. */ + + DIE_UNLESS(mysql_init(&con)); + + DIE_UNLESS(mysql_real_connect(&con, + opt_host, + opt_user, + opt_password, + opt_db ? opt_db : "test", + opt_port, + opt_unix_socket, + CLIENT_FOUND_ROWS)); + + /*********************************************************************** + Check that lock is free: + - IS_FREE_LOCK() should return 1; + - IS_USED_LOCK() should return NULL; + ***********************************************************************/ + + is_null= query_int_variable(&con, + "IS_FREE_LOCK('bug31418')", + &rc); + DIE_UNLESS(!is_null && rc); + + is_null= query_int_variable(&con, + "IS_USED_LOCK('bug31418')", + &rc); + DIE_UNLESS(is_null); + + /*********************************************************************** + Acquire lock and check the lock status (the lock must be in use): + - IS_FREE_LOCK() should return 0; + - IS_USED_LOCK() should return non-zero thread id; + ***********************************************************************/ + + query_int_variable(&con, "GET_LOCK('bug31418', 1)", &rc); + DIE_UNLESS(rc); + + is_null= query_int_variable(&con, + "IS_FREE_LOCK('bug31418')", + &rc); + DIE_UNLESS(!is_null && !rc); + + is_null= query_int_variable(&con, + "IS_USED_LOCK('bug31418')", + &rc); + DIE_UNLESS(!is_null && rc); + + /*********************************************************************** + Issue COM_CHANGE_USER command and check the lock status + (the lock must be free): + - IS_FREE_LOCK() should return 1; + - IS_USED_LOCK() should return NULL; + **********************************************************************/ + + bug20023_change_user(&con); + + is_null= query_int_variable(&con, + "IS_FREE_LOCK('bug31418')", + &rc); + DIE_UNLESS(!is_null && rc); + + is_null= query_int_variable(&con, + "IS_USED_LOCK('bug31418')", + &rc); + DIE_UNLESS(is_null); + + /*********************************************************************** That's it. Cleanup. ***********************************************************************/ mysql_close(&con); } +static void test_bug31418() +{ + /* Run test case for BUG#31418 for three different connections. */ + + bug31418_impl(); + + bug31418_impl(); + + bug31418_impl(); +} + + + +/** + Bug#31669 Buffer overflow in mysql_change_user() +*/ + +#define LARGE_BUFFER_SIZE 2048 + +static void test_bug31669() +{ + int rc; + static char buff[LARGE_BUFFER_SIZE+1]; +#ifndef EMBEDDED_LIBRARY + static char user[USERNAME_CHAR_LENGTH+1]; + static char db[NAME_CHAR_LEN+1]; + static char query[LARGE_BUFFER_SIZE*2]; +#endif + + DBUG_ENTER("test_bug31669"); + myheader("test_bug31669"); + + rc= mysql_change_user(mysql, NULL, NULL, NULL); + DIE_UNLESS(rc); + + rc= mysql_change_user(mysql, "", "", ""); + DIE_UNLESS(rc); + + memset(buff, 'a', sizeof(buff)); + + rc= mysql_change_user(mysql, buff, buff, buff); + DIE_UNLESS(rc); + + rc = mysql_change_user(mysql, opt_user, opt_password, current_db); + DIE_UNLESS(!rc); + +#ifndef EMBEDDED_LIBRARY + memset(db, 'a', sizeof(db)); + db[NAME_CHAR_LEN]= 0; + strxmov(query, "CREATE DATABASE IF NOT EXISTS ", db, NullS); + rc= mysql_query(mysql, query); + myquery(rc); + + memset(user, 'b', sizeof(user)); + user[USERNAME_CHAR_LENGTH]= 0; + memset(buff, 'c', sizeof(buff)); + buff[LARGE_BUFFER_SIZE]= 0; + strxmov(query, "GRANT ALL PRIVILEGES ON *.* TO '", user, "'@'%' IDENTIFIED BY " + "'", buff, "' WITH GRANT OPTION", NullS); + rc= mysql_query(mysql, query); + myquery(rc); + + strxmov(query, "GRANT ALL PRIVILEGES ON *.* TO '", user, "'@'localhost' IDENTIFIED BY " + "'", buff, "' WITH GRANT OPTION", NullS); + rc= mysql_query(mysql, query); + myquery(rc); + + rc= mysql_query(mysql, "FLUSH PRIVILEGES"); + myquery(rc); + + rc= mysql_change_user(mysql, user, buff, db); + DIE_UNLESS(!rc); + + user[USERNAME_CHAR_LENGTH-1]= 'a'; + rc= mysql_change_user(mysql, user, buff, db); + DIE_UNLESS(rc); + + user[USERNAME_CHAR_LENGTH-1]= 'b'; + buff[LARGE_BUFFER_SIZE-1]= 'd'; + rc= mysql_change_user(mysql, user, buff, db); + DIE_UNLESS(rc); + + buff[LARGE_BUFFER_SIZE-1]= 'c'; + db[NAME_CHAR_LEN-1]= 'e'; + rc= mysql_change_user(mysql, user, buff, db); + DIE_UNLESS(rc); + + db[NAME_CHAR_LEN-1]= 'a'; + rc= mysql_change_user(mysql, user, buff, db); + DIE_UNLESS(!rc); + + rc= mysql_change_user(mysql, user + 1, buff + 1, db + 1); + DIE_UNLESS(rc); + + rc = mysql_change_user(mysql, opt_user, opt_password, current_db); + DIE_UNLESS(!rc); + + strxmov(query, "DROP DATABASE ", db, NullS); + rc= mysql_query(mysql, query); + myquery(rc); + + strxmov(query, "DELETE FROM mysql.user WHERE User='", user, "'", NullS); + rc= mysql_query(mysql, query); + myquery(rc); + DIE_UNLESS(mysql_affected_rows(mysql) == 2); +#endif + + DBUG_VOID_RETURN; +} + + +/** + Bug#28386 the general log is incomplete +*/ + +static void test_bug28386() +{ + int rc; + MYSQL_STMT *stmt; + MYSQL_RES *result; + MYSQL_ROW row; + MYSQL_BIND bind; + const char hello[]= "hello world!"; + + DBUG_ENTER("test_bug28386"); + myheader("test_bug28386"); + + rc= mysql_query(mysql, "select @@global.log_output"); + myquery(rc); + + result= mysql_store_result(mysql); + DIE_UNLESS(result); + + row= mysql_fetch_row(result); + if (! strstr(row[0], "TABLE")) + { + mysql_free_result(result); + if (! opt_silent) + printf("Skipping the test since logging to tables is not enabled\n"); + /* Log output is not to tables */ + return; + } + mysql_free_result(result); + + enable_general_log(1); + + stmt= mysql_simple_prepare(mysql, "SELECT ?"); + check_stmt(stmt); + + memset(&bind, 0, sizeof(bind)); + + bind.buffer_type= MYSQL_TYPE_STRING; + bind.buffer= (void *) hello; + bind.buffer_length= sizeof(hello); + + mysql_stmt_bind_param(stmt, &bind); + mysql_stmt_send_long_data(stmt, 0, hello, sizeof(hello)); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); + + rc= mysql_stmt_reset(stmt); + check_execute(stmt, rc); + + rc= mysql_stmt_close(stmt); + DIE_UNLESS(!rc); + + rc= mysql_query(mysql, "select * from mysql.general_log where " + "command_type='Close stmt' or " + "command_type='Reset stmt' or " + "command_type='Long Data'"); + myquery(rc); + + result= mysql_store_result(mysql); + mytest(result); + + DIE_UNLESS(mysql_num_rows(result) == 3); + + mysql_free_result(result); + + restore_general_log(); + + DBUG_VOID_RETURN; +} + +static void test_wl4166_1() +{ + MYSQL_STMT *stmt; + int int_data; + char str_data[50]; + char tiny_data; + short small_data; + longlong big_data; + float real_data; + double double_data; + ulong length[7]; + my_bool is_null[7]; + MYSQL_BIND my_bind[7]; + int rc; + int i; + + myheader("test_wl4166_1"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS table_4166"); + myquery(rc); + + rc= mysql_query(mysql, "CREATE TABLE table_4166(col1 tinyint NOT NULL, " + "col2 varchar(15), col3 int, " + "col4 smallint, col5 bigint, " + "col6 float, col7 double, " + "colX varchar(10) default NULL)"); + myquery(rc); + + stmt= mysql_simple_prepare(mysql, + "INSERT INTO table_4166(col1, col2, col3, col4, col5, col6, col7) " + "VALUES(?, ?, ?, ?, ?, ?, ?)"); + check_stmt(stmt); + + verify_param_count(stmt, 7); + + bzero(my_bind, sizeof(my_bind)); + /* tinyint */ + my_bind[0].buffer_type= MYSQL_TYPE_TINY; + my_bind[0].buffer= (void *)&tiny_data; + /* string */ + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (void *)str_data; + my_bind[1].buffer_length= 1000; /* Max string length */ + /* integer */ + my_bind[2].buffer_type= MYSQL_TYPE_LONG; + my_bind[2].buffer= (void *)&int_data; + /* short */ + my_bind[3].buffer_type= MYSQL_TYPE_SHORT; + my_bind[3].buffer= (void *)&small_data; + /* bigint */ + my_bind[4].buffer_type= MYSQL_TYPE_LONGLONG; + my_bind[4].buffer= (void *)&big_data; + /* float */ + my_bind[5].buffer_type= MYSQL_TYPE_FLOAT; + my_bind[5].buffer= (void *)&real_data; + /* double */ + my_bind[6].buffer_type= MYSQL_TYPE_DOUBLE; + my_bind[6].buffer= (void *)&double_data; + + for (i= 0; i < (int) array_elements(my_bind); i++) + { + my_bind[i].length= &length[i]; + my_bind[i].is_null= &is_null[i]; + is_null[i]= 0; + } + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_execute(stmt, rc); + + int_data= 320; + small_data= 1867; + big_data= 1000; + real_data= 2; + double_data= 6578.001; + + /* now, execute the prepared statement to insert 10 records.. */ + for (tiny_data= 0; tiny_data < 10; tiny_data++) + { + length[1]= my_sprintf(str_data, (str_data, "MySQL%d", int_data)); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + int_data += 25; + small_data += 10; + big_data += 100; + real_data += 1; + double_data += 10.09; + } + + /* force a re-prepare with some DDL */ + + rc= mysql_query(mysql, + "ALTER TABLE table_4166 change colX colX varchar(20) default NULL"); + myquery(rc); + + /* + execute the prepared statement again, + without changing the types of parameters already bound. + */ + + for (tiny_data= 50; tiny_data < 60; tiny_data++) + { + length[1]= my_sprintf(str_data, (str_data, "MySQL%d", int_data)); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + int_data += 25; + small_data += 10; + big_data += 100; + real_data += 1; + double_data += 10.09; + } + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE table_4166"); + myquery(rc); +} + + +static void test_wl4166_2() +{ + MYSQL_STMT *stmt; + int c_int; + MYSQL_TIME d_date; + MYSQL_BIND bind_out[2]; + int rc; + + myheader("test_wl4166_2"); + + rc= mysql_query(mysql, "SET SQL_MODE=''"); + myquery(rc); + + rc= mysql_query(mysql, "drop table if exists t1"); + myquery(rc); + rc= mysql_query(mysql, "create table t1 (c_int int, d_date date)"); + myquery(rc); + rc= mysql_query(mysql, + "insert into t1 (c_int, d_date) values (42, '1948-05-15')"); + myquery(rc); + + stmt= mysql_simple_prepare(mysql, "select * from t1"); + check_stmt(stmt); + + bzero(bind_out, sizeof(bind_out)); + bind_out[0].buffer_type= MYSQL_TYPE_LONG; + bind_out[0].buffer= (void*) &c_int; + + bind_out[1].buffer_type= MYSQL_TYPE_DATE; + bind_out[1].buffer= (void*) &d_date; + + rc= mysql_stmt_bind_result(stmt, bind_out); + check_execute(stmt, rc); + + /* int -> varchar transition */ + + rc= mysql_query(mysql, + "alter table t1 change column c_int c_int varchar(11)"); + myquery(rc); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + rc= mysql_stmt_fetch(stmt); + check_execute(stmt, rc); + + DIE_UNLESS(c_int == 42); + DIE_UNLESS(d_date.year == 1948); + DIE_UNLESS(d_date.month == 5); + DIE_UNLESS(d_date.day == 15); + + rc= mysql_stmt_fetch(stmt); + DIE_UNLESS(rc == MYSQL_NO_DATA); + + /* varchar to int retrieval with truncation */ + + rc= mysql_query(mysql, "update t1 set c_int='abcde'"); + myquery(rc); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + rc= mysql_stmt_fetch(stmt); + check_execute_r(stmt, rc); + + DIE_UNLESS(c_int == 0); + + rc= mysql_stmt_fetch(stmt); + DIE_UNLESS(rc == MYSQL_NO_DATA); + + /* alter table and increase the number of columns */ + rc= mysql_query(mysql, "alter table t1 add column d_int int"); + myquery(rc); + + rc= mysql_stmt_execute(stmt); + check_execute_r(stmt, rc); + + rc= mysql_stmt_reset(stmt); + check_execute(stmt, rc); + + /* decrease the number of columns */ + rc= mysql_query(mysql, "alter table t1 drop d_date, drop d_int"); + myquery(rc); + + rc= mysql_stmt_execute(stmt); + check_execute_r(stmt, rc); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); + myquery(rc); + +} + +/** + Bug#38486 Crash when using cursor protocol +*/ + +static void test_bug38486(void) +{ + MYSQL_STMT *stmt; + const char *stmt_text; + unsigned long type= CURSOR_TYPE_READ_ONLY; + + DBUG_ENTER("test_bug38486"); + myheader("test_bug38486"); + + stmt= mysql_stmt_init(mysql); + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*)&type); + stmt_text= "CREATE TABLE t1 (a INT)"; + mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); + mysql_stmt_execute(stmt); + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*)&type); + stmt_text= "INSERT INTO t1 VALUES (1)"; + mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); + mysql_stmt_execute(stmt); + mysql_stmt_close(stmt); + + DBUG_VOID_RETURN; +} + static void test_bug40365(void) { uint rc, i; @@ -16530,6 +17736,100 @@ static void test_bug40365(void) /** + Subtest for Bug#43560. Verifies that a loss of connection on the server side + is handled well by the mysql_stmt_execute() call, i.e., no SIGSEGV due to + a vio socket that is cleared upon closed connection. + + Assumes the presence of the close_conn_after_stmt_execute debug feature in + the server. Verifies that it is connected to a debug server before proceeding + with the test. + */ +static void test_bug43560(void) +{ + MYSQL* conn; + uint rc; + MYSQL_STMT *stmt= 0; + MYSQL_BIND bind; + my_bool is_null= 0; + char buffer[256]; + const uint BUFSIZE= sizeof(buffer); + const char* values[] = {"eins", "zwei", "drei", "viele", NULL}; + const char insert_str[] = "INSERT INTO t1 (c2) VALUES (?)"; + unsigned long length; + + DBUG_ENTER("test_bug43560"); + myheader("test_bug43560"); + + /* Make sure we only run against a debug server. */ + if (!strstr(mysql->server_version, "debug")) + { + fprintf(stdout, "Skipping test_bug43560: server not DEBUG version\n"); + DBUG_VOID_RETURN; + } + + /* + Set up a separate connection for this test to avoid messing up the + general MYSQL object used in other subtests. Use TCP protocol to avoid + problems with the buffer semantics of AF_UNIX, and turn off auto reconnect. + */ + conn= client_connect(0, MYSQL_PROTOCOL_TCP, 0); + + rc= mysql_query(conn, "DROP TABLE IF EXISTS t1"); + myquery(rc); + rc= mysql_query(conn, + "CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 CHAR(10))"); + myquery(rc); + + stmt= mysql_stmt_init(conn); + check_stmt(stmt); + rc= mysql_stmt_prepare(stmt, insert_str, strlen(insert_str)); + check_execute(stmt, rc); + + bind.buffer_type= MYSQL_TYPE_STRING; + bind.buffer_length= BUFSIZE; + bind.buffer= buffer; + bind.is_null= &is_null; + bind.length= &length; + rc= mysql_stmt_bind_param(stmt, &bind); + check_execute(stmt, rc); + + /* First execute; should succeed. */ + strncpy(buffer, values[0], BUFSIZE); + length= strlen(buffer); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + /* + Set up the server to close this session's server-side socket after + next execution of prep statement. + */ + rc= mysql_query(conn,"SET SESSION debug='+d,close_conn_after_stmt_execute'"); + myquery(rc); + + /* Second execute; should fail due to socket closed during execution. */ + strncpy(buffer, values[1], BUFSIZE); + length= strlen(buffer); + rc= mysql_stmt_execute(stmt); + DIE_UNLESS(rc && mysql_stmt_errno(stmt) == CR_SERVER_LOST); + + /* + Third execute; should fail (connection already closed), or SIGSEGV in + case of a Bug#43560 type regression in which case the whole test fails. + */ + strncpy(buffer, values[2], BUFSIZE); + length= strlen(buffer); + rc= mysql_stmt_execute(stmt); + DIE_UNLESS(rc && mysql_stmt_errno(stmt) == CR_SERVER_LOST); + + client_disconnect(conn, 0); + rc= mysql_query(mysql, "DROP TABLE t1"); + myquery(rc); + + DBUG_VOID_RETURN; +} + + +/** Bug#36326: nested transaction and select */ @@ -16647,11 +17947,9 @@ static void test_bug41078(void) DBUG_VOID_RETURN; } - /** Bug#45010: invalid memory reads during parsing some strange statements */ - static void test_bug45010() { int rc; @@ -16678,6 +17976,55 @@ static void test_bug45010() DBUG_VOID_RETURN; } +/** + Bug#44495: Prepared Statement: + CALL p(<x>) - `thd->protocol == &thd->protocol_text' failed +*/ + +static void test_bug44495() +{ + int rc; + MYSQL con; + MYSQL_STMT *stmt; + + DBUG_ENTER("test_bug44495"); + myheader("test_44495"); + + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + myquery(rc); + + rc= mysql_query(mysql, "CREATE PROCEDURE p1(IN arg VARCHAR(25))" + " BEGIN SET @stmt = CONCAT('SELECT \"', arg, '\"');" + " PREPARE ps1 FROM @stmt;" + " EXECUTE ps1;" + " DROP PREPARE ps1;" + "END;"); + myquery(rc); + + DIE_UNLESS(mysql_init(&con)); + + DIE_UNLESS(mysql_real_connect(&con, opt_host, opt_user, opt_password, + current_db, opt_port, opt_unix_socket, + CLIENT_MULTI_RESULTS)); + + stmt= mysql_simple_prepare(&con, "CALL p1('abc')"); + check_stmt(stmt); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); + + mysql_stmt_close(stmt); + + mysql_close(&con); + + rc= mysql_query(mysql, "DROP PROCEDURE p1"); + myquery(rc); + + DBUG_VOID_RETURN; +} /* Read and parse arguments and MySQL options from my.cnf @@ -16688,17 +18035,17 @@ static char **defaults_argv; static struct my_option client_test_long_options[] = { - {"basedir", 'b', "Basedir for tests.", (gptr*) &opt_basedir, - (gptr*) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"count", 't', "Number of times test to be executed", (char **) &opt_count, - (char **) &opt_count, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0}, - {"database", 'D', "Database to use", (char **) &opt_db, (char **) &opt_db, + {"basedir", 'b', "Basedir for tests.", (uchar**) &opt_basedir, + (uchar**) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"count", 't', "Number of times test to be executed", (uchar **) &opt_count, + (uchar **) &opt_count, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0}, + {"database", 'D', "Database to use", (uchar **) &opt_db, (uchar **) &opt_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"debug", '#', "Output debug log", (gptr*) &default_dbug_option, - (gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, + {"debug", '#', "Output debug log", (uchar**) &default_dbug_option, + (uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"host", 'h', "Connect to host", (char **) &opt_host, (char **) &opt_host, + {"host", 'h', "Connect to host", (uchar **) &opt_host, (uchar **) &opt_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"password", 'p', "Password to use when connecting to server. If password is not given it's asked from the tty.", @@ -16709,8 +18056,8 @@ static struct my_option client_test_long_options[] = "/etc/services, " #endif "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").", - (char **) &opt_port, - (char **) &opt_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + (uchar **) &opt_port, + (uchar **) &opt_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"server-arg", 'A', "Send embedded server this as a parameter.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"show-tests", 'T', "Show all tests' names", 0, 0, 0, GET_NO_ARG, NO_ARG, @@ -16718,19 +18065,19 @@ static struct my_option client_test_long_options[] = {"silent", 's', "Be more silent", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"socket", 'S', "Socket file to use for connection", - (char **) &opt_unix_socket, (char **) &opt_unix_socket, 0, GET_STR, + (uchar **) &opt_unix_socket, (uchar **) &opt_unix_socket, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"testcase", 'c', "May disable some code when runs as mysql-test-run testcase.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifndef DONT_ALLOW_USER_CHANGE - {"user", 'u', "User for login if not current user", (char **) &opt_user, - (char **) &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"user", 'u', "User for login if not current user", (uchar **) &opt_user, + (uchar **) &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif - {"vardir", 'v', "Data dir for tests.", (gptr*) &opt_vardir, - (gptr*) &opt_vardir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"vardir", 'v', "Data dir for tests.", (uchar**) &opt_vardir, + (uchar**) &opt_vardir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"getopt-ll-test", 'g', "Option for testing bug in getopt library", - (char **) &opt_getopt_ll_test, (char **) &opt_getopt_ll_test, 0, + (uchar **) &opt_getopt_ll_test, (uchar **) &opt_getopt_ll_test, 0, GET_LL, REQUIRED_ARG, 0, 0, LONGLONG_MAX, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -16755,7 +18102,8 @@ and you are welcome to modify and redistribute it under the GPL license\n"); static struct my_tests_st my_tests[]= { - { "test_view_sp_list_fields", test_view_sp_list_fields}, + { "disable_general_log", disable_general_log }, + { "test_view_sp_list_fields", test_view_sp_list_fields }, { "client_query", client_query }, { "test_prepare_insert_update", test_prepare_insert_update}, #if NOT_YET_WORKING @@ -16896,7 +18244,6 @@ static struct my_tests_st my_tests[]= { { "test_bug6059", test_bug6059 }, { "test_bug6046", test_bug6046 }, { "test_bug6081", test_bug6081 }, - { "test_bug45790",test_bug45790 }, { "test_bug6096", test_bug6096 }, { "test_datetime_ranges", test_datetime_ranges }, { "test_bug4172", test_bug4172 }, @@ -16948,40 +18295,54 @@ static struct my_tests_st my_tests[]= { { "test_bug13488", test_bug13488 }, { "test_bug13524", test_bug13524 }, { "test_bug14845", test_bug14845 }, - { "test_bug15510", test_bug15510 }, { "test_opt_reconnect", test_opt_reconnect }, + { "test_bug15510", test_bug15510}, #ifndef EMBEDDED_LIBRARY { "test_bug12744", test_bug12744 }, #endif { "test_bug16143", test_bug16143 }, + { "test_bug16144", test_bug16144 }, { "test_bug15613", test_bug15613 }, { "test_bug20152", test_bug20152 }, { "test_bug14169", test_bug14169 }, { "test_bug17667", test_bug17667 }, - { "test_bug19671", test_bug19671 }, { "test_bug15752", test_bug15752 }, { "test_mysql_insert_id", test_mysql_insert_id }, + { "test_bug19671", test_bug19671 }, { "test_bug21206", test_bug21206 }, { "test_bug21726", test_bug21726 }, { "test_bug15518", test_bug15518 }, { "test_bug23383", test_bug23383 }, + { "test_bug32265", test_bug32265 }, { "test_bug21635", test_bug21635 }, + { "test_status", test_status }, { "test_bug24179", test_bug24179 }, + { "test_ps_query_cache", test_ps_query_cache }, + { "test_bug28075", test_bug28075 }, { "test_bug27876", test_bug27876 }, { "test_bug28505", test_bug28505 }, { "test_bug28934", test_bug28934 }, { "test_bug27592", test_bug27592 }, + { "test_bug29687", test_bug29687 }, + { "test_bug29692", test_bug29692 }, { "test_bug29306", test_bug29306 }, + { "test_change_user", test_change_user }, + { "test_bug30472", test_bug30472 }, + { "test_bug20023", test_bug20023 }, + { "test_bug45010", test_bug45010 }, + { "test_bug31418", test_bug31418 }, { "test_bug31669", test_bug31669 }, - { "test_bug32265", test_bug32265 }, + { "test_bug28386", test_bug28386 }, + { "test_wl4166_1", test_wl4166_1 }, + { "test_wl4166_2", test_wl4166_2 }, { "test_bug38486", test_bug38486 }, { "test_bug40365", test_bug40365 }, + { "test_bug43560", test_bug43560 }, #ifdef HAVE_QUERY_CACHE { "test_bug36326", test_bug36326 }, #endif { "test_bug41078", test_bug41078 }, - { "test_bug20023", test_bug20023 }, - { "test_bug45010", test_bug45010 }, + { "test_bug44495", test_bug44495 }, { 0, 0 } }; @@ -17106,7 +18467,8 @@ int main(int argc, char **argv) (char**) embedded_server_groups)) DIE("Can't initialize MySQL server"); - client_connect(0); /* connect to server */ + /* connect to server with no flags, default protocol, auto reconnect true */ + mysql= client_connect(0, MYSQL_PROTOCOL_DEFAULT, 1); total_time= 0; for (iter_count= 1; iter_count <= opt_count; iter_count++) @@ -17136,7 +18498,7 @@ int main(int argc, char **argv) fprintf(stderr, "\n\nGiven test not found: '%s'\n", *argv); fprintf(stderr, "See legal test names with %s -T\n\nAborting!\n", my_progname); - client_disconnect(); + client_disconnect(mysql, 1); free_defaults(defaults_argv); exit(1); } @@ -17149,7 +18511,7 @@ int main(int argc, char **argv) /* End of tests */ } - client_disconnect(); /* disconnect from server */ + client_disconnect(mysql, 1); /* disconnect from server */ free_defaults(defaults_argv); print_test_output(); diff --git a/tests/thread_test.c b/tests/thread_test.c index 0ba03694893..8e1c58ebbec 100644 --- a/tests/thread_test.c +++ b/tests/thread_test.c @@ -88,36 +88,36 @@ static struct my_option my_long_options[] = { {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"database", 'D', "Database to use", (gptr*) &database, (gptr*) &database, + {"database", 'D', "Database to use", (uchar**) &database, (uchar**) &database, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"host", 'h', "Connect to host", (gptr*) &host, (gptr*) &host, 0, GET_STR, + {"host", 'h', "Connect to host", (uchar**) &host, (uchar**) &host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"password", 'p', "Password to use when connecting to server. If password is not given it's asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, - {"user", 'u', "User for login if not current user", (gptr*) &user, - (gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"user", 'u', "User for login if not current user", (uchar**) &user, + (uchar**) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"version", 'V', "Output version information and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"verbose", 'v', "Write some progress indicators", (gptr*) &verbose, - (gptr*) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"query", 'Q', "Query to execute in each threads", (gptr*) &query, - (gptr*) &query, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"verbose", 'v', "Write some progress indicators", (uchar**) &verbose, + (uchar**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"query", 'Q', "Query to execute in each threads", (uchar**) &query, + (uchar**) &query, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"port", 'P', "Port number to use for connection or 0 for default to, in " "order of preference, my.cnf, $MYSQL_TCP_PORT, " #if MYSQL_PORT_DEFAULT == 0 "/etc/services, " #endif "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").", - (gptr*) &tcp_port, - (gptr*) &tcp_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0, 0}, - {"socket", 'S', "Socket file to use for connection", (gptr*) &unix_socket, - (gptr*) &unix_socket, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + (uchar**) &tcp_port, + (uchar**) &tcp_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0, 0}, + {"socket", 'S', "Socket file to use for connection", (uchar**) &unix_socket, + (uchar**) &unix_socket, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"test-count", 'c', "Run test count times (default %d)", - (gptr*) &number_of_tests, (gptr*) &number_of_tests, 0, GET_UINT, + (uchar**) &number_of_tests, (uchar**) &number_of_tests, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0}, {"thread-count", 't', "Number of threads to start", - (gptr*) &number_of_threads, (gptr*) &number_of_threads, 0, GET_UINT, + (uchar**) &number_of_threads, (uchar**) &number_of_threads, 0, GET_UINT, REQUIRED_ARG, 2, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; |