diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 9 | ||||
-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 | 2230 | ||||
-rw-r--r-- | tests/thread_test.c | 28 |
7 files changed, 1828 insertions, 448 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 1c39a3630dd..fbd58b88b9c 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\ 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 e873336dac9..32f2d76ff20 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"); \ @@ -115,6 +119,8 @@ static void client_disconnect(void); #define DIE_UNLESS(expr) \ ((void) ((expr) ? 0 : (die(__FILE__, __LINE__, #expr), 0))) +#define DIE_IF(expr) \ + ((void) ((expr) ? (die(__FILE__, __LINE__, #expr), 0) : 0)) #define DIE(expr) \ die(__FILE__, __LINE__, #expr) @@ -173,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 */ @@ -283,6 +289,8 @@ 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); if (!(mysql_real_connect(mysql, opt_host, opt_user, opt_password, opt_db ? opt_db:"test", opt_port, @@ -297,7 +305,7 @@ static void client_connect(ulong flag) mysql->reconnect= 1; if (!opt_silent) - fprintf(stdout, " OK"); + fprintf(stdout, "OK"); /* set AUTOCOMMIT to ON*/ mysql_autocommit(mysql, TRUE); @@ -320,7 +328,7 @@ static void client_connect(ulong flag) have_innodb= check_have_innodb(mysql); if (!opt_silent) - fprintf(stdout, " OK"); + fprintf(stdout, "OK"); } @@ -340,12 +348,13 @@ static void client_disconnect() mysql_query(mysql, query); if (!opt_silent) - fprintf(stdout, " OK"); + 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"); } } @@ -436,7 +445,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)) @@ -959,7 +968,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); /* @@ -1069,7 +1078,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]); } @@ -1218,7 +1227,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 */ @@ -1291,7 +1300,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 */ @@ -2341,7 +2350,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); @@ -2353,6 +2362,268 @@ 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"); + + /* 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); + } + 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() @@ -2852,9 +3123,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); @@ -4674,7 +4945,7 @@ static void test_stmt_close() } lmysql->reconnect= 1; if (!opt_silent) - fprintf(stdout, " OK"); + fprintf(stdout, "OK"); /* set AUTOCOMMIT to ON*/ @@ -4721,7 +4992,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); @@ -6397,10 +6668,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); @@ -6930,9 +7201,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"); @@ -6975,53 +7243,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); @@ -7038,7 +7259,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); @@ -7058,7 +7280,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); @@ -7219,7 +7442,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)"); @@ -7530,7 +7753,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); @@ -7559,16 +7782,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) { @@ -7578,11 +7801,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); @@ -7680,7 +7903,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')"); @@ -8152,6 +8375,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); @@ -8430,7 +8656,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'; @@ -8442,7 +8668,7 @@ static void test_mem_overun() { strxmov(buffer, buffer, "1, ", NullS); } - length= (uint) strlen(buffer); + length= strlen(buffer); buffer[length-2]= ')'; buffer[--length]= '\0'; @@ -8711,7 +8937,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\""); @@ -8970,7 +9197,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; @@ -8995,7 +9222,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); @@ -9026,7 +9253,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"); @@ -9629,7 +9856,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); @@ -9909,7 +10136,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)"); @@ -9957,16 +10184,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)"); @@ -10042,7 +10269,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, " @@ -10050,7 +10277,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)); @@ -10091,7 +10318,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); @@ -10124,7 +10351,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); @@ -10194,7 +10421,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)); } @@ -10257,7 +10484,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); @@ -10266,7 +10493,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; @@ -10281,7 +10508,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); @@ -10295,7 +10522,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); @@ -10332,7 +10559,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); @@ -10350,13 +10577,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); @@ -10482,7 +10709,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); /* @@ -10493,37 +10720,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); @@ -10531,7 +10758,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); @@ -10559,7 +10786,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); /* @@ -10572,26 +10799,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); @@ -10599,15 +10826,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); @@ -10617,7 +10844,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); @@ -10644,10 +10871,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); } @@ -10668,22 +10895,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 */ @@ -10691,7 +10918,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); @@ -10728,7 +10955,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); } @@ -10750,7 +10977,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 */ @@ -10828,7 +11055,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 */ @@ -10860,14 +11087,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; @@ -10899,7 +11126,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); @@ -11010,12 +11237,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; @@ -11064,7 +11291,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++) @@ -11146,7 +11373,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); @@ -11197,7 +11424,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); @@ -11245,15 +11472,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; @@ -11304,7 +11531,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++) @@ -11372,7 +11599,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); @@ -11383,7 +11610,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); @@ -11409,20 +11636,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); @@ -11457,20 +11684,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 */ @@ -11514,7 +11741,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); } @@ -11543,7 +11770,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); } @@ -11620,7 +11847,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, " @@ -11665,7 +11892,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)); @@ -11692,7 +11919,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)); @@ -11723,7 +11950,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) @@ -11752,7 +11979,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); } @@ -11767,20 +11994,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); @@ -11803,13 +12038,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); @@ -11852,13 +12087,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); @@ -11896,7 +12131,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); } @@ -11913,13 +12148,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); @@ -11927,7 +12162,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; @@ -12031,16 +12266,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,7 +12306,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=''"); @@ -12073,24 +12316,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); @@ -12147,7 +12390,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); } @@ -12168,12 +12411,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, @@ -12212,7 +12455,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) " @@ -12240,11 +12483,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, @@ -12281,7 +12524,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); } @@ -12307,7 +12550,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); @@ -12332,7 +12575,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); @@ -12363,20 +12606,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)); @@ -12394,7 +12637,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); @@ -12411,10 +12654,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); } @@ -12430,16 +12673,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)); @@ -12459,6 +12702,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); @@ -12469,12 +12713,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); @@ -12502,7 +12747,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 */ @@ -12520,7 +12765,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, " @@ -12530,7 +12775,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); @@ -12738,7 +12983,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); @@ -12784,7 +13029,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", "%"); @@ -12792,7 +13037,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); } @@ -12812,17 +13057,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; @@ -12843,7 +13088,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); } @@ -12943,6 +13188,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; @@ -13019,7 +13298,7 @@ static void test_bug8378() exit(1); } if (!opt_silent) - fprintf(stdout, " OK"); + fprintf(stdout, "OK"); len= mysql_real_escape_string(lmysql, out, TEST_BUG8378_IN, 4); @@ -13028,7 +13307,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); @@ -13045,19 +13324,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 */ /* @@ -13068,11 +13347,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); } @@ -13083,7 +13362,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); @@ -13134,7 +13413,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); @@ -13186,7 +13465,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); @@ -13259,10 +13539,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); @@ -13376,7 +13657,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)); @@ -13432,14 +13713,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]; } @@ -13490,7 +13771,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)); @@ -13600,7 +13881,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)); @@ -13650,7 +13931,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; @@ -13664,12 +13945,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); @@ -13691,7 +13972,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); @@ -13741,7 +14022,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; @@ -13813,7 +14094,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); @@ -13824,8 +14105,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); @@ -13930,7 +14211,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"); @@ -13976,7 +14257,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); @@ -14044,7 +14325,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); @@ -14077,7 +14358,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"); @@ -14180,7 +14461,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 (" @@ -14189,7 +14470,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 " @@ -14198,7 +14479,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 ****** */ @@ -14296,7 +14577,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 (" @@ -14306,7 +14587,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 " @@ -14343,7 +14624,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 (" @@ -14352,7 +14633,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 " @@ -14365,7 +14646,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 ****** */ @@ -14435,7 +14716,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)); @@ -14511,14 +14792,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); @@ -14607,7 +14888,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"); @@ -14624,7 +14905,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) @@ -14678,7 +14959,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); @@ -14733,7 +15014,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); @@ -14792,7 +15073,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); @@ -14828,7 +15109,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); @@ -14968,6 +15249,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" @@ -15000,7 +15299,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) @@ -15068,8 +15367,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 */ @@ -15080,10 +15401,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); @@ -15106,66 +15427,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. */ - if (log_file != NULL) { + /* Prepared statments always occurs twice in log */ + if (statement_cursor->qt == QT_PREPARED) + expected_hits++; - 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. */ + /* 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); - /* Prepared statments always occurs twice in log */ - if (statement_cursor->qt == QT_PREPARED) - expected_hits++; + 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"); - /* 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); + 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); + + 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)); } @@ -15194,7 +15500,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); @@ -15209,7 +15515,6 @@ static void test_bug14169() myquery(rc); } - /* Test that mysql_insert_id() behaves as documented in our manual */ @@ -15367,13 +15672,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); @@ -15405,7 +15714,6 @@ static void test_mysql_insert_id() myquery(rc); } - /* Bug#20152: mysql_stmt_execute() writes to MYSQL_TYPE_DATE buffer */ @@ -15437,7 +15745,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); @@ -15482,11 +15790,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) @@ -15501,7 +15809,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; @@ -15548,7 +15856,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) @@ -15560,11 +15868,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() { @@ -15577,6 +15905,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"); @@ -15593,6 +15923,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; } @@ -15643,7 +15980,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); @@ -15656,7 +15993,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); @@ -15722,23 +16059,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); } @@ -15777,15 +16118,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, @@ -15793,7 +16248,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, @@ -15816,24 +16271,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); @@ -15898,6 +16353,204 @@ 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@'%%'", + 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); + + DBUG_VOID_RETURN; +} #ifdef HAVE_SPATIAL /** @@ -16006,6 +16659,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 @@ -16055,6 +16769,458 @@ static void test_bug29306() DBUG_VOID_RETURN; } +/* + Bug#30472: libmysql doesn't reset charset, insert_id after succ. + mysql_change_user() call row insertions. +*/ + +static void bug30472_retrieve_charset_info(MYSQL *con, + char *character_set_name, + char *character_set_client, + char *character_set_results, + char *collation_connection) +{ + MYSQL_RES *rs; + MYSQL_ROW row; + + /* Get the cached client character set name. */ + + strcpy(character_set_name, mysql_character_set_name(con)); + + /* Retrieve server character set information. */ + + 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); + + 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); + + 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); +} + +static void test_bug30472() +{ + MYSQL con; + + 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]; + + 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]; + + 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]; + + 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]; + + /* 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)); + + /* Retrieve character set information. */ + + bug30472_retrieve_charset_info(&con, + character_set_name_1, + character_set_client_1, + character_set_results_1, + collation_connnection_1); + + /* Switch client character set. */ + + DIE_IF(mysql_set_character_set(&con, "utf8")); + + /* Retrieve character set information. */ + + bug30472_retrieve_charset_info(&con, + character_set_name_2, + character_set_client_2, + character_set_results_2, + collation_connnection_2); + + /* + Check that + 1) character set has been switched and + 2) new character set is different from the original one. + */ + + 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); + + 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); + + /* Call mysql_change_user() with the same username, password, database. */ + + DIE_IF(mysql_change_user(&con, + opt_user, + opt_password, + opt_db ? opt_db : "test")); + + /* Retrieve character set information. */ + + bug30472_retrieve_charset_info(&con, + character_set_name_3, + character_set_client_3, + character_set_results_3, + collation_connnection_3); + + /* Check that character set information has been reset. */ + + 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); + + /* Change connection-default character set in the client. */ + + mysql_options(&con, MYSQL_SET_CHARSET_NAME, "utf8"); + + /* + 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")); + + /* Retrieve character set information. */ + + bug30472_retrieve_charset_info(&con, + character_set_name_4, + character_set_client_4, + character_set_results_4, + collation_connnection_4); + + /* Check that we have UTF8 on the server and on the client. */ + + 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); + + /* That's it. Cleanup. */ + + mysql_close(&con); +} + +static void bug20023_change_user(MYSQL *con) +{ + DIE_IF(mysql_change_user(con, + opt_user, + opt_password, + opt_db ? opt_db : "test")); +} + +static my_bool query_int_variable(MYSQL *con, + const char *var_name, + int *var_value) +{ + 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", + (const char *) var_name); + + DIE_IF(mysql_query(con, query_buffer)); + DIE_UNLESS(rs= mysql_store_result(con)); + DIE_UNLESS(row= mysql_fetch_row(rs)); + + is_null= row[0] == NULL; + + if (!is_null) + *var_value= atoi(row[0]); + + mysql_free_result(rs); + + return is_null; +} + +static void test_bug20023() +{ + MYSQL con; + + int sql_big_selects_orig; + int max_join_size_orig; + + int sql_big_selects_2; + int sql_big_selects_3; + int sql_big_selects_4; + int sql_big_selects_5; + +#if NOT_USED + char query_buffer[MAX_TEST_QUERY_LENGTH]; +#endif + + /* 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)); + + /*********************************************************************** + Remember original SQL_BIG_SELECTS, MAX_JOIN_SIZE values. + ***********************************************************************/ + + query_int_variable(&con, + "@@session.sql_big_selects", + &sql_big_selects_orig); + + query_int_variable(&con, + "@@global.max_join_size", + &max_join_size_orig); + + /*********************************************************************** + Test that COM_CHANGE_USER resets the SQL_BIG_SELECTS to the initial value. + ***********************************************************************/ + + /* Issue COM_CHANGE_USER. */ + + bug20023_change_user(&con); + + /* Query SQL_BIG_SELECTS. */ + + 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. + ***********************************************************************/ + + /* Set MAX_JOIN_SIZE to some non-default value. */ + + DIE_IF(mysql_query(&con, "SET @@global.max_join_size = 10000")); + DIE_IF(mysql_query(&con, "SET @@session.max_join_size = default")); + + /* Issue COM_CHANGE_USER. */ + + bug20023_change_user(&con); + + /* Query SQL_BIG_SELECTS. */ + + 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. + ***********************************************************************/ + + /* Set MAX_JOIN_SIZE to the default value (-1). */ + + 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. */ + + bug20023_change_user(&con); + + /* Query SQL_BIG_SELECTS. */ + + 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. + ***********************************************************************/ + +#if NOT_USED + /* + max_join_size is a ulong or better. + my_snprintf() only goes up to ul. + */ + + /* Restore MAX_JOIN_SIZE. */ + + my_snprintf(query_buffer, + sizeof (query_buffer), + "SET @@global.max_join_size = %d", + (int) max_join_size_orig); + + DIE_IF(mysql_query(&con, query_buffer)); + +#else + DIE_IF(mysql_query(&con, "SET @@global.max_join_size = -1")); +#endif + + DIE_IF(mysql_query(&con, "SET @@session.max_join_size = default")); + + /* Issue COM_CHANGE_USER. */ + + bug20023_change_user(&con); + + /* Query SQL_BIG_SELECTS. */ + + 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(); +} + /** @@ -16068,8 +17234,8 @@ static void test_bug31669() 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 user[USERNAME_CHAR_LENGTH+1]; + static char db[NAME_CHAR_LEN+1]; static char query[LARGE_BUFFER_SIZE*2]; #endif @@ -16092,13 +17258,13 @@ static void test_bug31669() #ifndef EMBEDDED_LIBRARY memset(db, 'a', sizeof(db)); - db[NAME_LEN]= 0; + 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_LENGTH]= 0; + 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 " @@ -16112,21 +17278,21 @@ static void test_bug31669() rc= mysql_change_user(mysql, user, buff, db); DIE_UNLESS(!rc); - user[USERNAME_LENGTH-1]= 'a'; + user[USERNAME_CHAR_LENGTH-1]= 'a'; rc= mysql_change_user(mysql, user, buff, db); DIE_UNLESS(rc); - user[USERNAME_LENGTH-1]= 'b'; + 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_LEN-1]= 'e'; + db[NAME_CHAR_LEN-1]= 'e'; rc= mysql_change_user(mysql, user, buff, db); DIE_UNLESS(rc); - db[NAME_LEN-1]= 'a'; + db[NAME_CHAR_LEN-1]= 'a'; rc= mysql_change_user(mysql, user, buff, db); DIE_UNLESS(!rc); @@ -16151,98 +17317,290 @@ static void test_bug31669() /** - Bug#32265 Server returns different metadata if prepared statement is used + Bug#28386 the general log is incomplete */ -static void test_bug32265() +static void test_bug28386() { int rc; MYSQL_STMT *stmt; - MYSQL_FIELD *field; - MYSQL_RES *metadata; + MYSQL_RES *result; + MYSQL_ROW row; + MYSQL_BIND bind; + const char hello[]= "hello world!"; - DBUG_ENTER("test_bug32265"); - myheader("test_bug32265"); + DBUG_ENTER("test_bug28386"); + myheader("test_bug28386"); - rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + rc= mysql_query(mysql, "select @@global.log_output"); myquery(rc); - rc= mysql_query(mysql, "CREATE TABLE t1 (a INTEGER)"); + + 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); - rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)"); + + 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 VIEW v1 AS SELECT * FROM t1"); + + 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= open_cursor("SELECT * FROM t1"); - rc= mysql_stmt_execute(stmt); + 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); - 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); + 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); - stmt= open_cursor("SELECT a '' FROM t1 ``"); - rc= mysql_stmt_execute(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, "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); - 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); + /* int -> varchar transition */ + + rc= mysql_query(mysql, + "alter table t1 change column c_int c_int varchar(11)"); + myquery(rc); - 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); + 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); - 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); + 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); - stmt= open_cursor("SELECT * FROM v1 /* SIC */ GROUP BY 1"); rc= mysql_stmt_execute(stmt); - check_execute(stmt, rc); + check_execute_r(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_stmt_reset(stmt); + check_execute(stmt, rc); - rc= mysql_query(mysql, "DROP VIEW v1"); + /* decrease the number of columns */ + rc= mysql_query(mysql, "alter table t1 drop d_date, drop d_int"); myquery(rc); - rc= mysql_query(mysql, "DROP TABLE t1"); + + rc= mysql_stmt_execute(stmt); + check_execute_r(stmt, rc); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); myquery(rc); - DBUG_VOID_RETURN; } - /** Bug#38486 Crash when using cursor protocol */ @@ -16420,17 +17778,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.", @@ -16441,8 +17799,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, @@ -16450,19 +17808,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} }; @@ -16487,7 +17845,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 @@ -16679,32 +18038,45 @@ 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_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 }, #ifdef HAVE_SPATIAL 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} }; |