From d7395d613e2d2d61f75b9d88b1eeb9e8356ed5cb Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Oct 2004 14:13:42 +0300 Subject: [PATCH 01/17] correct (high level) fix for BUG#5367 to privent problems in other engines --- sql/item_subselect.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index bb2bb6319a9..5acf8242c65 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1287,7 +1287,8 @@ int subselect_uniquesubquery_engine::exec() error= table->file->index_read(table->record[0], tab->ref.key_buff, tab->ref.key_length,HA_READ_KEY_EXACT); - if (error && error != HA_ERR_KEY_NOT_FOUND) + if (error && + error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE) error= report_error(table, error); else { @@ -1339,7 +1340,8 @@ int subselect_indexsubquery_engine::exec() error= table->file->index_read(table->record[0], tab->ref.key_buff, tab->ref.key_length,HA_READ_KEY_EXACT); - if (error && error != HA_ERR_KEY_NOT_FOUND) + if (error && + error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE) error= report_error(table, error); else { From 74c254182dad379fb81153fa227f5f8e84f67d39 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 13 Oct 2004 11:29:57 +0300 Subject: [PATCH 02/17] InnoDB: correct potential overflow in trx_purge() innobase/trx/trx0purge.c: trx_purge(): avoid overflow in setting srv_dml_needed_delay --- innobase/trx/trx0purge.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/innobase/trx/trx0purge.c b/innobase/trx/trx0purge.c index 1a4ef6a2e99..5c62640e011 100644 --- a/innobase/trx/trx0purge.c +++ b/innobase/trx/trx0purge.c @@ -1057,12 +1057,15 @@ trx_purge(void) && !UT_LIST_GET_LAST(trx_sys->view_list)) { float ratio = (float) trx_sys->rseg_history_len / srv_max_purge_lag; - if (ratio > 1) { + if (ratio > ULINT_MAX / 10000) { + /* Avoid overflow: maximum delay is 4295 seconds */ + srv_dml_needed_delay = ULINT_MAX; + } else if (ratio > 1) { /* If the history list length exceeds the innodb_max_purge_lag, the data manipulation statements are delayed by at least 5000 microseconds. */ - srv_dml_needed_delay = (ratio - .5) * 10000; + srv_dml_needed_delay = (ulint) ((ratio - .5) * 10000); } } From ba48e6f9aae98aea3128a7fd1695516424b53ad5 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 13 Oct 2004 19:27:07 +0400 Subject: [PATCH 03/17] tests/client_test.c: Make checks (asserts) performed in client_test.c work in non-debug builds. tests/client_test.c: Make checks (asserts) performed in client_test.c work in non-debug builds: all asserts/DBUG_ASSERTs replaced with if (!(expr)) abort(); --- tests/client_test.c | 1076 ++++++++++++++++++++++++------------------- 1 file changed, 595 insertions(+), 481 deletions(-) diff --git a/tests/client_test.c b/tests/client_test.c index ee8bc28165c..0b30cc3386d 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -26,7 +26,6 @@ #include #include #include -#include #ifdef HAVE_SYS_PARAM_H /* Include to get MAXPATHLEN */ #include @@ -78,6 +77,28 @@ static void print_error(const char *msg); static void print_st_error(MYSQL_STMT *stmt, const char *msg); static void client_disconnect(); + +/* + Abort unless given experssion is non-zero. + + SYNOPSIS + DIE_UNLESS(expr) + + DESCRIPTION + We can't use any kind of system assert as we need to + preserve tested invariants in release builds as well. +*/ + +#define DIE_UNLESS(expr) \ + ((void) ((expr) ? 0 : (die(__FILE__, __LINE__, #expr), 0))) + +void die(const char *file, int line, const char *expr) +{ + fprintf(stderr, "%s:%d: check failed: '%s'\n", file, line, expr); + abort(); +} + + #define myerror(msg) print_error(msg) #define mysterror(stmt, msg) print_st_error(stmt, msg) @@ -85,46 +106,46 @@ static void client_disconnect(); { \ if (r) \ myerror(NULL); \ - assert(r == 0); \ + DIE_UNLESS(r == 0); \ } #define myquery_r(r) \ { \ if (r) \ myerror(NULL); \ -assert(r != 0); \ +DIE_UNLESS(r != 0); \ } #define check_execute(stmt, r) \ { \ if (r) \ mysterror(stmt, NULL); \ -assert(r == 0);\ +DIE_UNLESS(r == 0);\ } #define check_execute_r(stmt, r) \ { \ if (r) \ mysterror(stmt, NULL); \ -assert(r != 0);\ +DIE_UNLESS(r != 0);\ } #define check_stmt(stmt) \ { \ if ( stmt == 0) \ myerror(NULL); \ -assert(stmt != 0); \ +DIE_UNLESS(stmt != 0); \ } #define check_stmt_r(stmt) \ { \ if (stmt == 0) \ myerror(NULL);\ -assert(stmt == 0);\ +DIE_UNLESS(stmt == 0);\ } -#define mytest(x) if (!x) {myerror(NULL);assert(TRUE);} -#define mytest_r(x) if (x) {myerror(NULL);assert(TRUE);} +#define mytest(x) if (!x) {myerror(NULL);DIE_UNLESS(FALSE);} +#define mytest_r(x) if (x) {myerror(NULL);DIE_UNLESS(FALSE);} /* Print the error message */ @@ -413,10 +434,10 @@ int my_process_result(MYSQL *mysql) #define MAX_RES_FIELDS 50 #define MAX_FIELD_DATA_SIZE 255 -uint my_process_stmt_result(MYSQL_STMT *stmt) +int my_process_stmt_result(MYSQL_STMT *stmt) { int field_count; - uint row_count= 0; + int row_count= 0; MYSQL_BIND buffer[MAX_RES_FIELDS]; MYSQL_FIELD *field; MYSQL_RES *result; @@ -492,10 +513,10 @@ uint my_process_stmt_result(MYSQL_STMT *stmt) /* Prepare statement, execute, and process result set for given query */ -uint my_stmt_result(const char *buff) +int my_stmt_result(const char *buff) { MYSQL_STMT *stmt; - uint row_count; + int row_count; int rc; fprintf(stdout, "\n\n %s", buff); @@ -543,7 +564,7 @@ static void verify_col_data(const char *table, const char *col, { fprintf(stdout, "\n obtained: `%s` (expected: `%s`)", row[field], exp_data); - assert(0); + DIE_UNLESS(FALSE); } mysql_free_result(result); } @@ -581,15 +602,15 @@ static void verify_prepare_field(MYSQL_RES *result, fprintf(stdout, "\n default :`%s`\t(expected: `%s`)", field->def ? field->def : "(null)", def ? def: "(null)"); fprintf(stdout, "\n"); - assert(strcmp(field->name, name) == 0); - assert(strcmp(field->org_name, org_name) == 0); - assert(field->type == type); - assert(strcmp(field->table, table) == 0); - assert(strcmp(field->org_table, org_table) == 0); - assert(strcmp(field->db, db) == 0); - assert(field->length == length); + DIE_UNLESS(strcmp(field->name, name) == 0); + DIE_UNLESS(strcmp(field->org_name, org_name) == 0); + DIE_UNLESS(field->type == type); + DIE_UNLESS(strcmp(field->table, table) == 0); + DIE_UNLESS(strcmp(field->org_table, org_table) == 0); + DIE_UNLESS(strcmp(field->db, db) == 0); + DIE_UNLESS(field->length == length); if (def) - assert(strcmp(field->def, def) == 0); + DIE_UNLESS(strcmp(field->def, def) == 0); } @@ -600,7 +621,7 @@ static void verify_param_count(MYSQL_STMT *stmt, long exp_count) long param_count= mysql_stmt_param_count(stmt); fprintf(stdout, "\n total parameters in stmt: `%ld` (expected: `%ld`)", param_count, exp_count); - assert(param_count == exp_count); + DIE_UNLESS(param_count == exp_count); } @@ -611,7 +632,7 @@ static void verify_st_affected_rows(MYSQL_STMT *stmt, ulonglong exp_count) ulonglong affected_rows= mysql_stmt_affected_rows(stmt); fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", affected_rows, exp_count); - assert(affected_rows == exp_count); + DIE_UNLESS(affected_rows == exp_count); } @@ -622,7 +643,7 @@ static void verify_affected_rows(ulonglong exp_count) ulonglong affected_rows= mysql_affected_rows(mysql); fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", affected_rows, exp_count); - assert(affected_rows == exp_count); + DIE_UNLESS(affected_rows == exp_count); } @@ -633,7 +654,7 @@ static void verify_field_count(MYSQL_RES *result, uint exp_count) uint field_count= mysql_num_fields(result); fprintf(stdout, "\n total fields in the result set: `%d` (expected: `%d`)", field_count, exp_count); - assert(field_count == exp_count); + DIE_UNLESS(field_count == exp_count); } @@ -655,7 +676,7 @@ static void execute_prepare_query(const char *query, ulonglong exp_count) fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", affected_rows, exp_count); - assert(affected_rows == exp_count); + DIE_UNLESS(affected_rows == exp_count); mysql_stmt_close(stmt); } @@ -676,7 +697,7 @@ static void client_store_result() result= mysql_store_result(mysql); mytest(result); - my_process_result_set(result); + (void) my_process_result_set(result); mysql_free_result(result); } @@ -696,7 +717,7 @@ static void client_use_result() result= mysql_use_result(mysql); mytest(result); - my_process_result_set(result); + (void) my_process_result_set(result); mysql_free_result(result); } @@ -767,7 +788,7 @@ static void test_debug_example() result= mysql_use_result(mysql); mytest(result); - my_process_result_set(result); + (void) my_process_result_set(result); mysql_free_result(result); rc= mysql_query(mysql, "DROP TABLE test_debug_example"); @@ -827,7 +848,7 @@ static void test_tran_bdb() result= mysql_store_result(mysql); mytest(result); - my_process_result_set(result); + (void) my_process_result_set(result); mysql_free_result(result); /* test the results now, only one row should exist */ @@ -900,7 +921,7 @@ static void test_tran_innodb() result= mysql_store_result(mysql); mytest(result); - my_process_result_set(result); + (void) my_process_result_set(result); mysql_free_result(result); /* test the results now, only one row should exist */ @@ -1167,7 +1188,8 @@ static void test_prepare() myquery(rc); /* test the results now, only one row should exist */ - assert(tiny_data == (char) my_stmt_result("SELECT * FROM my_prepare")); + rc= my_stmt_result("SELECT * FROM my_prepare"); + DIE_UNLESS(tiny_data == (char) rc); stmt= mysql_simple_prepare(mysql, "SELECT * FROM my_prepare"); check_stmt(stmt); @@ -1205,27 +1227,27 @@ static void test_prepare() fprintf(stdout, "\n\t str : %s (%lu)", str_data, length[1]); - assert(tiny_data == o_tiny_data); - assert(is_null[0] == 0); - assert(length[0] == 1); + DIE_UNLESS(tiny_data == o_tiny_data); + DIE_UNLESS(is_null[0] == 0); + DIE_UNLESS(length[0] == 1); - assert(int_data == o_int_data); - assert(length[2] == 4); + DIE_UNLESS(int_data == o_int_data); + DIE_UNLESS(length[2] == 4); - assert(small_data == o_small_data); - assert(length[3] == 2); + DIE_UNLESS(small_data == o_small_data); + DIE_UNLESS(length[3] == 2); - assert(big_data == o_big_data); - assert(length[4] == 8); + DIE_UNLESS(big_data == o_big_data); + DIE_UNLESS(length[4] == 8); - assert(real_data == o_real_data); - assert(length[5] == 4); + DIE_UNLESS(real_data == o_real_data); + DIE_UNLESS(length[5] == 4); - assert(double_data == o_double_data); - assert(length[6] == 8); + DIE_UNLESS(double_data == o_double_data); + DIE_UNLESS(length[6] == 8); - assert(strcmp(data, str_data) == 0); - assert(length[1] == len); + DIE_UNLESS(strcmp(data, str_data) == 0); + DIE_UNLESS(length[1] == len); o_int_data += 25; o_small_data += 10; @@ -1235,7 +1257,7 @@ static void test_prepare() } rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); @@ -1320,7 +1342,8 @@ static void test_double_compare() result= mysql_store_result(mysql); mytest(result); - assert((int)tiny_data == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS((int)tiny_data == rc); mysql_free_result(result); } @@ -1393,7 +1416,8 @@ static void test_null() myquery(rc); nData*= 2; - assert(nData == my_stmt_result("SELECT * FROM test_null")); + rc= my_stmt_result("SELECT * FROM test_null");; + DIE_UNLESS((int) nData == rc); /* Fetch results */ bind[0].buffer_type= MYSQL_TYPE_LONG; @@ -1416,12 +1440,12 @@ static void test_null() is_null[0]= is_null[1]= 0; while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) { - assert(is_null[0]); - assert(is_null[1]); + DIE_UNLESS(is_null[0]); + DIE_UNLESS(is_null[1]); rc++; is_null[0]= is_null[1]= 0; } - assert(rc == (int)nData); + DIE_UNLESS(rc == (int) nData); mysql_stmt_close(stmt); } @@ -1491,10 +1515,10 @@ static void test_ps_null_param() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); rc= mysql_stmt_fetch(stmt); - assert(rc != MYSQL_NO_DATA); - assert(out_is_null); + DIE_UNLESS(rc != MYSQL_NO_DATA); + DIE_UNLESS(out_is_null); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } } @@ -1544,7 +1568,8 @@ static void test_fetch_null() strmov((char *)query , "SELECT * FROM test_fetch_null"); - assert(3 == my_stmt_result(query)); + rc= my_stmt_result(query); + DIE_UNLESS(rc == 3); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -1563,14 +1588,14 @@ static void test_fetch_null() { fprintf(stdout, "\n data[%d] : %s", i, is_null[i] ? "NULL" : "NOT NULL"); - assert(is_null[i]); + DIE_UNLESS(is_null[i]); } fprintf(stdout, "\n data[%d]: %d", i, nData); - assert(nData == 1000 || nData == 88 || nData == 389789); - assert(is_null[i] == 0); - assert(length[i] == 4); + DIE_UNLESS(nData == 1000 || nData == 88 || nData == 389789); + DIE_UNLESS(is_null[i] == 0); + DIE_UNLESS(length[i] == 4); } - assert(rc == 3); + DIE_UNLESS(rc == 3); mysql_stmt_close(stmt); } @@ -1657,7 +1682,7 @@ static void test_select_direct() result= mysql_store_result(mysql); mytest(result); - my_process_result_set(result); + (void) my_process_result_set(result); mysql_free_result(result); } @@ -1693,7 +1718,8 @@ static void test_select_prepare() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); mysql_stmt_close(stmt); rc= mysql_query(mysql, "DROP TABLE test_select"); @@ -1717,7 +1743,8 @@ static void test_select_prepare() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); mysql_stmt_close(stmt); } @@ -1782,7 +1809,8 @@ static void test_select() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(my_process_stmt_result(stmt) == 1); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); mysql_stmt_close(stmt); } @@ -1841,7 +1869,8 @@ static void test_ps_conj_select() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(my_process_stmt_result(stmt) == 3); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 3); mysql_stmt_close(stmt); } @@ -1914,7 +1943,8 @@ session_id char(9) NOT NULL, \ rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(my_process_stmt_result(stmt) == 1); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); strmov(szData, (char *)"venu"); bind[0].buffer_type= MYSQL_TYPE_STRING; @@ -1930,7 +1960,8 @@ session_id char(9) NOT NULL, \ rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(my_process_stmt_result(stmt) == 0); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 0); strmov(szData, (char *)"abc"); bind[0].buffer_type= MYSQL_TYPE_STRING; @@ -1946,7 +1977,8 @@ session_id char(9) NOT NULL, \ rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(my_process_stmt_result(stmt) == 1); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); mysql_stmt_close(stmt); } @@ -1996,7 +2028,8 @@ static void test_bug1180() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(my_process_stmt_result(stmt) == 0); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 0); strmov(szData, (char *)"1111"); bind[0].buffer_type= MYSQL_TYPE_STRING; @@ -2012,7 +2045,8 @@ static void test_bug1180() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(my_process_stmt_result(stmt) == 1); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); strmov(szData, (char *)"abc"); bind[0].buffer_type= MYSQL_TYPE_STRING; @@ -2028,7 +2062,8 @@ static void test_bug1180() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(my_process_stmt_result(stmt) == 0); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 0); mysql_stmt_close(stmt); } @@ -2111,7 +2146,8 @@ static void test_bug1644() result= mysql_store_result(mysql); mytest(result); - assert(3 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 3); mysql_data_seek(result, 0); @@ -2119,19 +2155,19 @@ static void test_bug1644() mytest(row); for (i= 0 ; i < 4 ; i++) { - assert(strcmp(row[i], "22") == 0); + DIE_UNLESS(strcmp(row[i], "22") == 0); } row= mysql_fetch_row(result); mytest(row); for (i= 0 ; i < 4 ; i++) { - assert(row[i] == 0); + DIE_UNLESS(row[i] == 0); } row= mysql_fetch_row(result); mytest(row); for (i= 0 ; i < 4 ; i++) { - assert(strcmp(row[i], "88") == 0); + DIE_UNLESS(strcmp(row[i], "88") == 0); } row= mysql_fetch_row(result); mytest_r(row); @@ -2197,7 +2233,8 @@ static void test_select_show() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); mysql_stmt_close(stmt); } @@ -2275,7 +2312,8 @@ static void test_simple_update() result= mysql_store_result(mysql); mytest(result); - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); mysql_free_result(result); } @@ -2351,7 +2389,8 @@ static void test_long_data() result= mysql_store_result(mysql); mytest(result); - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); mysql_free_result(result); verify_col_data("test_long_data", "col1", "999"); @@ -2435,7 +2474,8 @@ static void test_long_data_str() result= mysql_store_result(mysql); mytest(result); - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); mysql_free_result(result); my_sprintf(data, (data, "%d", i*5)); @@ -2530,7 +2570,8 @@ static void test_long_data_str1() mytest(result); - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); mysql_free_result(result); my_sprintf(data, (data, "%ld", (long)i*length)); @@ -2554,7 +2595,7 @@ static void test_long_data_str1() field= mysql_fetch_fields(result); /* First test what happens if STMT_ATTR_UPDATE_MAX_LENGTH is not used */ - DBUG_ASSERT(field->max_length == 0); + DIE_UNLESS(field->max_length == 0); mysql_free_result(result); /* Enable updating of field->max_length */ @@ -2569,7 +2610,7 @@ static void test_long_data_str1() result= mysql_stmt_result_metadata(stmt); field= mysql_fetch_fields(result); - DBUG_ASSERT(field->max_length == max_blob_length); + DIE_UNLESS(field->max_length == max_blob_length); /* Fetch results into a data buffer that is smaller than data */ bzero((char*) bind, sizeof(*bind)); @@ -2580,9 +2621,10 @@ static void test_long_data_str1() rc= mysql_stmt_bind_result(stmt, bind); data[16]= 0; - DBUG_ASSERT((mysql_stmt_fetch(stmt) == 0)); - DBUG_ASSERT(strlen(data) == 16); - DBUG_ASSERT(blob_length == max_blob_length); + rc= mysql_stmt_fetch(stmt); + DIE_UNLESS(rc == 0); + DIE_UNLESS(strlen(data) == 16); + DIE_UNLESS(blob_length == max_blob_length); /* Fetch all data */ bzero((char*) (bind+1), sizeof(*bind)); @@ -2592,7 +2634,7 @@ static void test_long_data_str1() bind[1].length= &blob_length; bzero(data, sizeof(data)); mysql_stmt_fetch_column(stmt, bind+1, 0, 0); - DBUG_ASSERT(strlen(data) == max_blob_length); + DIE_UNLESS(strlen(data) == max_blob_length); mysql_free_result(result); mysql_stmt_close(stmt); @@ -2674,7 +2716,8 @@ static void test_long_data_bin() result= mysql_store_result(mysql); mytest(result); - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); mysql_free_result(result); } @@ -2754,7 +2797,8 @@ static void test_simple_delete() result= mysql_store_result(mysql); mytest(result); - assert(0 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 0); mysql_free_result(result); } @@ -2853,7 +2897,8 @@ static void test_update() result= mysql_store_result(mysql); mytest(result); - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); mysql_free_result(result); } @@ -2899,7 +2944,8 @@ static void test_prepare_noparam() result= mysql_store_result(mysql); mytest(result); - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); mysql_free_result(result); } @@ -2962,17 +3008,17 @@ static void test_bind_result() check_execute(stmt, rc); fprintf(stdout, "\n row 1: %d, %s(%lu)", nData, szData, length1); - assert(nData == 10); - assert(strcmp(szData, "venu") == 0); - assert(length1 == 4); + DIE_UNLESS(nData == 10); + DIE_UNLESS(strcmp(szData, "venu") == 0); + DIE_UNLESS(length1 == 4); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n row 2: %d, %s(%lu)", nData, szData, length1); - assert(nData == 20); - assert(strcmp(szData, "MySQL") == 0); - assert(length1 == 5); + DIE_UNLESS(nData == 20); + DIE_UNLESS(strcmp(szData, "MySQL") == 0); + DIE_UNLESS(length1 == 5); length= 99; rc= mysql_stmt_fetch(stmt); @@ -2980,12 +3026,12 @@ static void test_bind_result() if (is_null[0]) fprintf(stdout, "\n row 3: NULL, %s(%lu)", szData, length1); - assert(is_null[0]); - assert(strcmp(szData, "monty") == 0); - assert(length1 == 5); + DIE_UNLESS(is_null[0]); + DIE_UNLESS(strcmp(szData, "monty") == 0); + DIE_UNLESS(length1 == 5); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -3090,19 +3136,19 @@ static void test_bind_result_ext() fprintf(stdout, "\n data (bin) : %s(%lu)", bData, bLength); - assert(t_data == 19); - assert(s_data == 2999); - assert(i_data == 3999); - assert(b_data == 4999999); - /*assert(f_data == 2345.60);*/ - /*assert(d_data == 5678.89563);*/ - assert(strcmp(szData, "venu") == 0); - assert(strncmp(bData, "mysql", 5) == 0); - assert(szLength == 4); - assert(bLength == 5); + DIE_UNLESS(t_data == 19); + DIE_UNLESS(s_data == 2999); + DIE_UNLESS(i_data == 3999); + DIE_UNLESS(b_data == 4999999); + /*DIE_UNLESS(f_data == 2345.60);*/ + /*DIE_UNLESS(d_data == 5678.89563);*/ + DIE_UNLESS(strcmp(szData, "venu") == 0); + DIE_UNLESS(strncmp(bData, "mysql", 5) == 0); + DIE_UNLESS(szLength == 4); + DIE_UNLESS(bLength == 5); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -3207,23 +3253,23 @@ static void test_bind_result_ext1() fprintf(stdout, "\n data (bin) : %ld(%lu)", bData, length[6]); fprintf(stdout, "\n data (str) : %g(%lu)", szData, length[7]); - assert(strcmp(t_data, "120") == 0); - assert(i_data == 3999); - assert(f_data == 2); - assert(strcmp(d_data, "58.89") == 0); - assert(b_data == 54); + DIE_UNLESS(strcmp(t_data, "120") == 0); + DIE_UNLESS(i_data == 3999); + DIE_UNLESS(f_data == 2); + DIE_UNLESS(strcmp(d_data, "58.89") == 0); + DIE_UNLESS(b_data == 54); - assert(length[0] == 3); - assert(length[1] == 4); - assert(length[2] == 2); - assert(length[3] == 1); - assert(length[4] == 4); - assert(length[5] == 5); - assert(length[6] == 4); - assert(length[7] == 8); + DIE_UNLESS(length[0] == 3); + DIE_UNLESS(length[1] == 4); + DIE_UNLESS(length[2] == 2); + DIE_UNLESS(length[3] == 1); + DIE_UNLESS(length[4] == 4); + DIE_UNLESS(length[5] == 5); + DIE_UNLESS(length[6] == 4); + DIE_UNLESS(length[7] == 8); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -3281,11 +3327,11 @@ static void bind_fetch(int row_count) mysql_stmt_close(stmt); - assert(row_count == (int) - my_stmt_result("SELECT * FROM test_bind_fetch")); + rc= my_stmt_result("SELECT * FROM test_bind_fetch"); + DIE_UNLESS(row_count == rc); stmt= mysql_simple_prepare(mysql, "SELECT * FROM test_bind_fetch"); - myquery(rc); + check_stmt(stmt); for (i= 0; i < (int) array_elements(bind); i++) { @@ -3342,45 +3388,45 @@ static void bind_fetch(int row_count) rc= 10+row_count; /* TINY */ - assert((int) i8_data == rc); - assert(length[0] == 1); + DIE_UNLESS((int) i8_data == rc); + DIE_UNLESS(length[0] == 1); rc+= 13; /* SHORT */ - assert((int) i16_data == rc); - assert(length[1] == 2); + DIE_UNLESS((int) i16_data == rc); + DIE_UNLESS(length[1] == 2); rc+= 13; /* LONG */ - assert((int) i32_data == rc); - assert(length[2] == 4); + DIE_UNLESS((int) i32_data == rc); + DIE_UNLESS(length[2] == 4); rc+= 13; /* LONGLONG */ - assert((int) i64_data == rc); - assert(length[3] == 8); + DIE_UNLESS((int) i64_data == rc); + DIE_UNLESS(length[3] == 8); rc+= 13; /* FLOAT */ - assert((int)f_data == rc); - assert(length[4] == 4); + DIE_UNLESS((int)f_data == rc); + DIE_UNLESS(length[4] == 4); rc+= 13; /* DOUBLE */ - assert((int)d_data == rc); - assert(length[5] == 8); + DIE_UNLESS((int)d_data == rc); + DIE_UNLESS(length[5] == 8); rc+= 13; /* CHAR */ { char buff[20]; long len= my_sprintf(buff, (buff, "%d", rc)); - assert(strcmp(s_data, buff) == 0); - assert(length[6] == (ulong) len); + DIE_UNLESS(strcmp(s_data, buff) == 0); + DIE_UNLESS(length[6] == (ulong) len); } } rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -3464,7 +3510,8 @@ static void test_fetch_date() bind[6].buffer_length= sizeof(ts_6); bind[6].length= &ts6_length; - assert(1 == my_stmt_result("SELECT * FROM test_bind_result")); + rc= my_stmt_result("SELECT * FROM test_bind_result"); + DIE_UNLESS(rc == 1); stmt= mysql_simple_prepare(mysql, "SELECT * FROM test_bind_result"); check_stmt(stmt); @@ -3487,29 +3534,29 @@ static void test_fetch_date() fprintf(stdout, "\n ts(4) : %s(%lu)", ts_4, ts4_length); fprintf(stdout, "\n ts(6) : %s(%lu)", ts_6, ts6_length); - assert(strcmp(date, "2002-01-02") == 0); - assert(d_length == 10); + DIE_UNLESS(strcmp(date, "2002-01-02") == 0); + DIE_UNLESS(d_length == 10); - assert(strcmp(time, "12:49:00") == 0); - assert(t_length == 8); + DIE_UNLESS(strcmp(time, "12:49:00") == 0); + DIE_UNLESS(t_length == 8); - assert(strcmp(ts, "2002-01-02 17:46:59") == 0); - assert(ts_length == 19); + DIE_UNLESS(strcmp(ts, "2002-01-02 17:46:59") == 0); + DIE_UNLESS(ts_length == 19); - assert(year == 2010); - assert(y_length == 4); + DIE_UNLESS(year == 2010); + DIE_UNLESS(y_length == 4); - assert(strcmp(dt, "2010-07-10 00:00:00") == 0); - assert(dt_length == 19); + DIE_UNLESS(strcmp(dt, "2010-07-10 00:00:00") == 0); + DIE_UNLESS(dt_length == 19); - assert(ts_4[0] == '\0'); - assert(ts4_length == 0); + DIE_UNLESS(ts_4[0] == '\0'); + DIE_UNLESS(ts4_length == 0); - assert(strcmp(ts_6, "1999-12-29 00:00:00") == 0); - assert(ts6_length == 19); + DIE_UNLESS(strcmp(ts_6, "1999-12-29 00:00:00") == 0); + DIE_UNLESS(ts6_length == 19); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -3796,7 +3843,8 @@ static void test_prepare_ext() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(nData == (int)my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(nData == rc); mysql_stmt_close(stmt); } @@ -3831,7 +3879,8 @@ static void test_field_names() result= mysql_use_result(mysql); mytest(result); - assert(0 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 0); mysql_free_result(result); /* with table name included with TRUE column name */ @@ -3841,7 +3890,8 @@ static void test_field_names() result= mysql_use_result(mysql); mytest(result); - assert(0 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 0); mysql_free_result(result); } @@ -3867,7 +3917,8 @@ static void test_warnings() result= mysql_store_result(mysql); mytest(result); - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); mysql_free_result(result); } @@ -3892,7 +3943,7 @@ static void test_errors() result= mysql_store_result(mysql); mytest(result); - my_process_result_set(result); + (void) my_process_result_set(result); mysql_free_result(result); } @@ -3969,7 +4020,8 @@ static void test_insert() result= mysql_store_result(mysql); mytest(result); - assert((int)tiny_data == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS((int) tiny_data == rc); mysql_free_result(result); } @@ -4126,7 +4178,7 @@ static void test_stmt_close() rc= mysql_stmt_close(stmt1); fprintf(stdout, "\n mysql_close_stmt(1) returned: %d", rc); - assert(rc == 0); + DIE_UNLESS(rc == 0); /* Originally we were going to close all statements automatically in @@ -4160,7 +4212,7 @@ static void test_stmt_close() rc= mysql_stmt_close(stmt_x); fprintf(stdout, "\n mysql_close_stmt(x) returned: %d", rc); - assert( rc == 0); + DIE_UNLESS( rc == 0); rc= mysql_query(mysql, "SELECT id FROM test_stmt_close"); myquery(rc); @@ -4168,7 +4220,8 @@ static void test_stmt_close() result= mysql_store_result(mysql); mytest(result); - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); mysql_free_result(result); } @@ -4220,9 +4273,9 @@ static void test_set_variable() fprintf(stdout, "\n max_error_count(default): %d", get_count); def_count= get_count; - assert(strcmp(var, "max_error_count") == 0); + DIE_UNLESS(strcmp(var, "max_error_count") == 0); rc= mysql_stmt_fetch(stmt1); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); stmt= mysql_simple_prepare(mysql, "set max_error_count= ?"); check_stmt(stmt); @@ -4248,10 +4301,10 @@ static void test_set_variable() check_execute(stmt1, rc); fprintf(stdout, "\n max_error_count : %d", get_count); - assert(get_count == set_count); + DIE_UNLESS(get_count == set_count); rc= mysql_stmt_fetch(stmt1); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); /* restore back to default */ set_count= def_count; @@ -4265,10 +4318,10 @@ static void test_set_variable() check_execute(stmt1, rc); fprintf(stdout, "\n max_error_count(default): %d", get_count); - assert(get_count == set_count); + DIE_UNLESS(get_count == set_count); rc= mysql_stmt_fetch(stmt1); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); mysql_stmt_close(stmt1); @@ -4323,12 +4376,12 @@ static void test_insert_meta() field= mysql_fetch_field(result); mytest(field); fprintf(stdout, "\n obtained: `%s` (expected: `%s`)", field->name, "col1"); - assert(strcmp(field->name, "col1") == 0); + DIE_UNLESS(strcmp(field->name, "col1") == 0); field= mysql_fetch_field(result); mytest(field); fprintf(stdout, "\n obtained: `%s` (expected: `%s`)", field->name, "col3"); - assert(strcmp(field->name, "col3") == 0); + DIE_UNLESS(strcmp(field->name, "col3") == 0); field= mysql_fetch_field(result); mytest_r(field); @@ -4386,15 +4439,15 @@ static void test_update_meta() mytest(field); fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col1"); fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_update"); - assert(strcmp(field->name, "col1") == 0); - assert(strcmp(field->table, "test_prep_update") == 0); + DIE_UNLESS(strcmp(field->name, "col1") == 0); + DIE_UNLESS(strcmp(field->table, "test_prep_update") == 0); field= mysql_fetch_field(result); mytest(field); fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col3"); fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_update"); - assert(strcmp(field->name, "col3") == 0); - assert(strcmp(field->table, "test_prep_update") == 0); + DIE_UNLESS(strcmp(field->name, "col3") == 0); + DIE_UNLESS(strcmp(field->table, "test_prep_update") == 0); field= mysql_fetch_field(result); mytest_r(field); @@ -4450,15 +4503,15 @@ static void test_select_meta() mytest(field); fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col1"); fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_select"); - assert(strcmp(field->name, "col1") == 0); - assert(strcmp(field->table, "test_prep_select") == 0); + DIE_UNLESS(strcmp(field->name, "col1") == 0); + DIE_UNLESS(strcmp(field->table, "test_prep_select") == 0); field= mysql_fetch_field(result); mytest(field); fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col2"); fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_select"); - assert(strcmp(field->name, "col2") == 0); - assert(strcmp(field->table, "test_prep_select") == 0); + DIE_UNLESS(strcmp(field->name, "col2") == 0); + DIE_UNLESS(strcmp(field->table, "test_prep_select") == 0); field= mysql_fetch_field(result); mytest_r(field); @@ -4502,7 +4555,7 @@ static void test_func_fields() mytest(field); fprintf(stdout, "\n table name: `%s` (expected: `%s`)", field->table, "test_dateformat"); - assert(strcmp(field->table, "test_dateformat") == 0); + DIE_UNLESS(strcmp(field->table, "test_dateformat") == 0); field= mysql_fetch_field(result); mytest_r(field); /* no more fields */ @@ -4519,7 +4572,7 @@ static void test_func_fields() field= mysql_fetch_field(result); mytest(field); fprintf(stdout, "\n table name: `%s` (expected: `%s`)", field->table, ""); - assert(field->table[0] == '\0'); + DIE_UNLESS(field->table[0] == '\0'); field= mysql_fetch_field(result); mytest_r(field); /* no more fields */ @@ -4537,8 +4590,8 @@ static void test_func_fields() mytest(field); fprintf(stdout, "\n field name: `%s` (expected: `%s`)", field->name, "YEAR"); fprintf(stdout, "\n field org name: `%s` (expected: `%s`)", field->org_name, ""); - assert(strcmp(field->name, "YEAR") == 0); - assert(field->org_name[0] == '\0'); + DIE_UNLESS(strcmp(field->name, "YEAR") == 0); + DIE_UNLESS(field->org_name[0] == '\0'); field= mysql_fetch_field(result); mytest_r(field); /* no more fields */ @@ -4615,11 +4668,11 @@ static void test_multi_stmt() fprintf(stdout, "\n int_data: %lu(%lu)", (ulong) id, length[0]); fprintf(stdout, "\n str_data: %s(%lu)", name, length[1]); - assert(id == 10); - assert(strcmp(name, "mysql") == 0); + DIE_UNLESS(id == 10); + DIE_UNLESS(strcmp(name, "mysql") == 0); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); /* alter the table schema now */ stmt1= mysql_simple_prepare(mysql, "DELETE FROM test_multi_table " @@ -4644,11 +4697,11 @@ static void test_multi_stmt() fprintf(stdout, "\n int_data: %lu(%lu)", (ulong) id, length[0]); fprintf(stdout, "\n str_data: %s(%lu)", name, length[1]); - assert(id == 10); - assert(strcmp(name, "updated") == 0); + DIE_UNLESS(id == 10); + DIE_UNLESS(strcmp(name, "updated") == 0); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); rc= mysql_stmt_execute(stmt1); check_execute(stmt1, rc); @@ -4661,9 +4714,10 @@ static void test_multi_stmt() check_execute(stmt, rc); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); - assert(0 == my_stmt_result("SELECT * FROM test_multi_table")); + rc= my_stmt_result("SELECT * FROM test_multi_table"); + DIE_UNLESS(rc == 0); mysql_stmt_close(stmt); mysql_stmt_close(stmt2); @@ -4679,6 +4733,7 @@ static void test_manual_sample() MYSQL_STMT *stmt; short small_data; int int_data; + int rc; char str_data[50]; ulonglong affected_rows; MYSQL_BIND bind[3]; @@ -4814,7 +4869,8 @@ static void test_manual_sample() fprintf(stderr, "\n %s", mysql_stmt_error(stmt)); exit(1); } - assert(2 == my_stmt_result("SELECT * FROM test_table")); + rc= my_stmt_result("SELECT * FROM test_table"); + DIE_UNLESS(rc == 2); /* DROP THE TABLE */ if (mysql_query(mysql, "DROP TABLE test_table")) @@ -4879,7 +4935,8 @@ static void test_prepare_alter() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(4 == my_stmt_result("SELECT * FROM test_prep_alter")); + rc= my_stmt_result("SELECT * FROM test_prep_alter"); + DIE_UNLESS(rc == 4); mysql_stmt_close(stmt); } @@ -4919,8 +4976,10 @@ DROP TABLE IF EXISTS test_multi_tab"; rc= mysql_query(mysql, query); /* syntax error */ myquery_r(rc); - assert(-1 == mysql_next_result(mysql)); - assert(0 == mysql_more_results(mysql)); + rc= mysql_next_result(mysql); + DIE_UNLESS(rc == -1); + rc= mysql_more_results(mysql); + DIE_UNLESS(rc == 0); if (!(mysql_local= mysql_init(NULL))) { @@ -4945,7 +5004,7 @@ DROP TABLE IF EXISTS test_multi_tab"; fprintf(stdout, "\n Query %d: ", count); if ((result= mysql_store_result(mysql_local))) { - my_process_result_set(result); + (void) my_process_result_set(result); mysql_free_result(result); } else @@ -4978,8 +5037,10 @@ DROP TABLE IF EXISTS test_multi_tab"; } else { - assert(mysql_more_results(mysql_local) == 0); - assert(mysql_next_result(mysql_local) == -1); + rc= mysql_more_results(mysql_local); + DIE_UNLESS(rc == 0); + rc= mysql_next_result(mysql_local); + DIE_UNLESS(rc == -1); } } @@ -4987,16 +5048,20 @@ DROP TABLE IF EXISTS test_multi_tab"; rc= mysql_query(mysql_local, "select 1+1+a;select 1+1"); myquery_r(rc); - assert(mysql_more_results(mysql_local) == 0); - assert(mysql_next_result(mysql_local) == -1); + rc= mysql_more_results(mysql_local); + DIE_UNLESS(rc == 0); + rc= mysql_next_result(mysql_local); + DIE_UNLESS(rc == -1); rc= mysql_query(mysql_local, "select 1+1;select 1+1+a;select 1"); myquery(rc); result= mysql_store_result(mysql_local); mytest(result); mysql_free_result(result); - assert(mysql_more_results(mysql_local) == 1); - assert(mysql_next_result(mysql_local) > 0); + rc= mysql_more_results(mysql_local); + DIE_UNLESS(rc == 1); + rc= mysql_next_result(mysql_local); + DIE_UNLESS(rc > 0); /* Ensure that we can now do a simple query (this checks that the server is @@ -5006,7 +5071,7 @@ DROP TABLE IF EXISTS test_multi_tab"; myquery(rc); result= mysql_store_result(mysql_local); mytest(result); - my_process_result_set(result); + (void) my_process_result_set(result); mysql_free_result(result); mysql_close(mysql_local); @@ -5103,17 +5168,17 @@ static void test_store_result() check_execute(stmt, rc); fprintf(stdout, "\n row 1: %ld, %s(%lu)", (long) nData, szData, length1); - assert(nData == 10); - assert(strcmp(szData, "venu") == 0); - assert(length1 == 4); + DIE_UNLESS(nData == 10); + DIE_UNLESS(strcmp(szData, "venu") == 0); + DIE_UNLESS(length1 == 4); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n row 2: %ld, %s(%lu)", (long) nData, szData, length1); - assert(nData == 20); - assert(strcmp(szData, "mysql") == 0); - assert(length1 == 5); + DIE_UNLESS(nData == 20); + DIE_UNLESS(strcmp(szData, "mysql") == 0); + DIE_UNLESS(length1 == 5); length= 99; rc= mysql_stmt_fetch(stmt); @@ -5121,12 +5186,12 @@ static void test_store_result() if (is_null[0]) fprintf(stdout, "\n row 3: NULL, %s(%lu)", szData, length1); - assert(is_null[0]); - assert(strcmp(szData, "monty") == 0); - assert(length1 == 5); + DIE_UNLESS(is_null[0]); + DIE_UNLESS(strcmp(szData, "monty") == 0); + DIE_UNLESS(length1 == 5); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -5138,17 +5203,17 @@ static void test_store_result() check_execute(stmt, rc); fprintf(stdout, "\n row 1: %ld, %s(%lu)", (long) nData, szData, length1); - assert(nData == 10); - assert(strcmp(szData, "venu") == 0); - assert(length1 == 4); + DIE_UNLESS(nData == 10); + DIE_UNLESS(strcmp(szData, "venu") == 0); + DIE_UNLESS(length1 == 4); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n row 2: %ld, %s(%lu)", (long) nData, szData, length1); - assert(nData == 20); - assert(strcmp(szData, "mysql") == 0); - assert(length1 == 5); + DIE_UNLESS(nData == 20); + DIE_UNLESS(strcmp(szData, "mysql") == 0); + DIE_UNLESS(length1 == 5); length= 99; rc= mysql_stmt_fetch(stmt); @@ -5156,12 +5221,12 @@ static void test_store_result() if (is_null[0]) fprintf(stdout, "\n row 3: NULL, %s(%lu)", szData, length1); - assert(is_null[0]); - assert(strcmp(szData, "monty") == 0); - assert(length1 == 5); + DIE_UNLESS(is_null[0]); + DIE_UNLESS(strcmp(szData, "monty") == 0); + DIE_UNLESS(length1 == 5); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -5204,7 +5269,7 @@ static void test_store_result1() while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) rc++; fprintf(stdout, "\n total rows: %d", rc); - assert(rc == 3); + DIE_UNLESS(rc == 3); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); @@ -5216,7 +5281,7 @@ static void test_store_result1() while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) rc++; fprintf(stdout, "\n total rows: %d", rc); - assert(rc == 3); + DIE_UNLESS(rc == 3); mysql_stmt_close(stmt); } @@ -5282,10 +5347,10 @@ static void test_store_result2() check_execute(stmt, rc); fprintf(stdout, "\n row 1: %d", nData); - assert(nData == 10); + DIE_UNLESS(nData == 10); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); nData= 20; rc= mysql_stmt_execute(stmt); @@ -5299,10 +5364,10 @@ static void test_store_result2() check_execute(stmt, rc); fprintf(stdout, "\n row 1: %d", nData); - assert(nData == 20); + DIE_UNLESS(nData == 20); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -5374,13 +5439,18 @@ static void test_subselect() mysql_stmt_close(stmt); - assert(3 == my_stmt_result("SELECT * FROM test_sub2")); + rc= my_stmt_result("SELECT * FROM test_sub2"); + DIE_UNLESS(rc == 3); - strmov((char *)query , "SELECT ROW(1, 7) IN (select id, id1 from test_sub2 WHERE id1= ?)"); - assert(1 == my_stmt_result("SELECT ROW(1, 7) IN (select id, id1 from test_sub2 WHERE id1= 8)")); - assert(1 == my_stmt_result("SELECT ROW(1, 7) IN (select id, id1 from test_sub2 WHERE id1= 7)")); + rc= my_stmt_result("SELECT ROW(1, 7) IN (select id, id1 " + "from test_sub2 WHERE id1= 8)"); + DIE_UNLESS(rc == 1); + rc= my_stmt_result("SELECT ROW(1, 7) IN (select id, id1 " + "from test_sub2 WHERE id1= 7)"); + DIE_UNLESS(rc == 1); - stmt= mysql_simple_prepare(mysql, query); + stmt= mysql_simple_prepare(mysql, ("SELECT ROW(1, 7) IN (select id, id1 " + "from test_sub2 WHERE id1= ?)")); check_stmt(stmt); rc= mysql_stmt_bind_param(stmt, bind); @@ -5397,10 +5467,10 @@ static void test_subselect() check_execute(stmt, rc); fprintf(stdout, "\n row 1: %d", id); - assert(id == 1); + DIE_UNLESS(id == 1); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); id= 8; rc= mysql_stmt_execute(stmt); @@ -5410,10 +5480,10 @@ static void test_subselect() check_execute(stmt, rc); fprintf(stdout, "\n row 1: %d", id); - assert(id == 0); + DIE_UNLESS(id == 0); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -5505,10 +5575,11 @@ static void test_bind_date_conv(uint row_count) mysql_stmt_close(stmt); - assert(row_count == my_stmt_result("SELECT * FROM test_date")); + rc= my_stmt_result("SELECT * FROM test_date"); + DIE_UNLESS(row_count == rc); stmt= mysql_simple_prepare(mysql, "SELECT * FROM test_date"); - myquery(rc); + check_stmt(stmt); rc= mysql_stmt_bind_result(stmt, bind); check_execute(stmt, rc); @@ -5533,23 +5604,25 @@ static void test_bind_date_conv(uint row_count) tm[i].hour, tm[i].minute, tm[i].second, tm[i].second_part); - assert(tm[i].year == 0 || tm[i].year == year+count); - assert(tm[i].month == 0 || tm[i].month == month+count); - assert(tm[i].day == 0 || tm[i].day == day+count); + DIE_UNLESS(tm[i].year == 0 || tm[i].year == year+count); + DIE_UNLESS(tm[i].month == 0 || tm[i].month == month+count); + DIE_UNLESS(tm[i].day == 0 || tm[i].day == day+count); - assert(tm[i].hour == 0 || tm[i].hour == hour+count); + DIE_UNLESS(tm[i].hour == 0 || tm[i].hour == hour+count); +#if 0 /* - minute causes problems from date<->time, don't assert, instead - validate separatly in another routine - */ - /*assert(tm[i].minute == 0 || tm[i].minute == minute+count); - assert(tm[i].second == 0 || tm[i].second == sec+count);*/ - - assert(tm[i].second_part == 0 || tm[i].second_part == second_part+count); + minute causes problems from date<->time, don't assert, instead + validate separatly in another routine + */ + DIE_UNLESS(tm[i].minute == 0 || tm[i].minute == minute+count); + DIE_UNLESS(tm[i].second == 0 || tm[i].second == sec+count); +#endif + DIE_UNLESS(tm[i].second_part == 0 || + tm[i].second_part == second_part+count); } } rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -5792,9 +5865,9 @@ static void test_buffers() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n data: %s (%lu)", buffer, length); - assert(buffer[0] == 'M'); - assert(buffer[1] == 'X'); - assert(length == 5); + DIE_UNLESS(buffer[0] == 'M'); + DIE_UNLESS(buffer[1] == 'X'); + DIE_UNLESS(length == 5); bind[0].buffer_length= 8; rc= mysql_stmt_bind_result(stmt, bind);/* re-bind */ @@ -5803,8 +5876,8 @@ static void test_buffers() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n data: %s (%lu)", buffer, length); - assert(strncmp(buffer, "Database", 8) == 0); - assert(length == 8); + DIE_UNLESS(strncmp(buffer, "Database", 8) == 0); + DIE_UNLESS(length == 8); bind[0].buffer_length= 12; rc= mysql_stmt_bind_result(stmt, bind);/* re-bind */ @@ -5813,8 +5886,8 @@ static void test_buffers() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n data: %s (%lu)", buffer, length); - assert(strcmp(buffer, "Open-Source") == 0); - assert(length == 11); + DIE_UNLESS(strcmp(buffer, "Open-Source") == 0); + DIE_UNLESS(length == 11); bind[0].buffer_length= 6; rc= mysql_stmt_bind_result(stmt, bind);/* re-bind */ @@ -5823,8 +5896,8 @@ static void test_buffers() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n data: %s (%lu)", buffer, length); - assert(strncmp(buffer, "Popula", 6) == 0); - assert(length == 7); + DIE_UNLESS(strncmp(buffer, "Popula", 6) == 0); + DIE_UNLESS(length == 7); mysql_stmt_close(stmt); } @@ -5855,7 +5928,8 @@ static void test_open_direct() result= mysql_store_result(mysql); mytest(result); - assert(0 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 0); mysql_free_result(result); rc= mysql_stmt_execute(stmt); @@ -5869,7 +5943,8 @@ static void test_open_direct() result= mysql_store_result(mysql); mytest(result); - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); mysql_free_result(result); rc= mysql_stmt_execute(stmt); @@ -5883,7 +5958,8 @@ static void test_open_direct() result= mysql_store_result(mysql); mytest(result); - assert(2 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 2); mysql_free_result(result); mysql_stmt_close(stmt); @@ -5951,7 +6027,7 @@ static void test_fetch_nobuffs() rc++; fprintf(stdout, "\n total rows : %d", rc); - assert(rc == 1); + DIE_UNLESS(rc == 1); bind[0].buffer_type= MYSQL_TYPE_STRING; bind[0].buffer= (void *)str[0]; @@ -5979,7 +6055,7 @@ static void test_fetch_nobuffs() fprintf(stdout, "\n CURRENT_TIME() : %s", str[3]); } fprintf(stdout, "\n total rows : %d", rc); - assert(rc == 1); + DIE_UNLESS(rc == 1); mysql_stmt_close(stmt); } @@ -6050,20 +6126,20 @@ static void test_ushort_bug() fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); - assert(short_value == 35999); - assert(s_length == 2); + DIE_UNLESS(short_value == 35999); + DIE_UNLESS(s_length == 2); - assert(long_value == 35999); - assert(l_length == 4); + DIE_UNLESS(long_value == 35999); + DIE_UNLESS(l_length == 4); - assert(longlong_value == 35999); - assert(ll_length == 8); + DIE_UNLESS(longlong_value == 35999); + DIE_UNLESS(ll_length == 8); - assert(tiny_value == 200); - assert(t_length == 1); + DIE_UNLESS(tiny_value == 200); + DIE_UNLESS(t_length == 1); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -6134,20 +6210,20 @@ static void test_sshort_bug() fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); - assert(short_value == -5999); - assert(s_length == 2); + DIE_UNLESS(short_value == -5999); + DIE_UNLESS(s_length == 2); - assert(long_value == -5999); - assert(l_length == 4); + DIE_UNLESS(long_value == -5999); + DIE_UNLESS(l_length == 4); - assert(longlong_value == 35999); - assert(ll_length == 8); + DIE_UNLESS(longlong_value == 35999); + DIE_UNLESS(ll_length == 8); - assert(tiny_value == 200); - assert(t_length == 1); + DIE_UNLESS(tiny_value == 200); + DIE_UNLESS(t_length == 1); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -6218,20 +6294,20 @@ static void test_stiny_bug() fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); - assert(short_value == -128); - assert(s_length == 2); + DIE_UNLESS(short_value == -128); + DIE_UNLESS(s_length == 2); - assert(long_value == -127); - assert(l_length == 4); + DIE_UNLESS(long_value == -127); + DIE_UNLESS(l_length == 4); - assert(longlong_value == 255); - assert(ll_length == 8); + DIE_UNLESS(longlong_value == 255); + DIE_UNLESS(ll_length == 8); - assert(tiny_value == 0); - assert(t_length == 1); + DIE_UNLESS(tiny_value == 0); + DIE_UNLESS(t_length == 1); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -6256,13 +6332,14 @@ static void test_field_misc() result= mysql_store_result(mysql); mytest(result); - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); verify_prepare_field(result, 0, - "@@autocommit", "", /* field and its org name */ + "@@autocommit", "", /* field and its org name */ MYSQL_TYPE_LONGLONG, /* field type */ "", "", /* table and its org name */ - "", 1, 0); /* db name, length(its bool flag)*/ + "", 1, 0); /* db name, length(its bool flag)*/ mysql_free_result(result); @@ -6275,13 +6352,14 @@ static void test_field_misc() result= mysql_stmt_result_metadata(stmt); mytest(result); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); verify_prepare_field(result, 0, - "@@autocommit", "", /* field and its org name */ + "@@autocommit", "", /* field and its org name */ MYSQL_TYPE_LONGLONG, /* field type */ "", "", /* table and its org name */ - "", 1, 0); /* db name, length(its bool flag)*/ + "", 1, 0); /* db name, length(its bool flag)*/ mysql_free_result(result); mysql_stmt_close(stmt); @@ -6306,7 +6384,7 @@ static void test_field_misc() fprintf(stdout, "\n default table type: %s(%ld)", table_type, type_length); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); @@ -6315,12 +6393,12 @@ static void test_field_misc() result= mysql_stmt_result_metadata(stmt); mytest(result); - assert(mysql_stmt_field_count(stmt) == mysql_num_fields(result)); + DIE_UNLESS(mysql_stmt_field_count(stmt) == mysql_num_fields(result)); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + DIE_UNLESS(1 == my_process_stmt_result(stmt)); verify_prepare_field(result, 0, "@@table_type", "", /* field and its org name */ @@ -6340,7 +6418,8 @@ static void test_field_misc() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); verify_prepare_field(result, 0, "@@max_error_count", "", /* field and its org name */ @@ -6360,7 +6439,7 @@ static void test_field_misc() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + DIE_UNLESS(1 == my_process_stmt_result(stmt)); verify_prepare_field(result, 0, "@@max_allowed_packet", "", /* field and its org name */ @@ -6380,13 +6459,14 @@ static void test_field_misc() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); verify_prepare_field(result, 0, - "@@sql_warnings", "", /* field and its org name */ + "@@sql_warnings", "", /* field and its org name */ MYSQL_TYPE_LONGLONG, /* field type */ "", "", /* table and its org name */ - "", 1, 0); /* db name, length */ + "", 1, 0); /* db name, length */ mysql_free_result(result); mysql_stmt_close(stmt); @@ -6428,7 +6508,8 @@ static void test_set_option() result= mysql_store_result(mysql); mytest(result); - assert(2 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 2); mysql_free_result(result); @@ -6439,7 +6520,8 @@ static void test_set_option() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(2 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 2); mysql_stmt_close(stmt); @@ -6454,7 +6536,8 @@ static void test_set_option() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(4 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 4); mysql_stmt_close(stmt); } @@ -6527,7 +6610,8 @@ static void test_prepare_grant() execute_prepare_query("INSERT INTO test_grant(a) VALUES(NULL)", 1); execute_prepare_query("INSERT INTO test_grant VALUES(NULL)", 1); execute_prepare_query("UPDATE test_grant SET a=9 WHERE a=1", 1); - assert(4 == my_stmt_result("SELECT a FROM test_grant")); + rc= my_stmt_result("SELECT a FROM test_grant"); + DIE_UNLESS(rc == 4); /* Both DELETE expected to fail as user does not have DELETE privs */ @@ -6537,18 +6621,19 @@ static void test_prepare_grant() stmt= mysql_simple_prepare(mysql, "DELETE FROM test_grant"); check_stmt_r(stmt); - assert(4 == my_stmt_result("SELECT * FROM test_grant")); + rc= my_stmt_result("SELECT * FROM test_grant"); + DIE_UNLESS(rc == 4); mysql_close(lmysql); mysql= org_mysql; rc= mysql_query(mysql, "delete from mysql.user where User='test_grant'"); myquery(rc); - assert(1 == mysql_affected_rows(mysql)); + DIE_UNLESS(1 == mysql_affected_rows(mysql)); rc= mysql_query(mysql, "delete from mysql.tables_priv where User='test_grant'"); myquery(rc); - assert(1 == mysql_affected_rows(mysql)); + DIE_UNLESS(1 == mysql_affected_rows(mysql)); } } @@ -6603,7 +6688,7 @@ static void test_frm_bug() fprintf(stdout, "\n data directory: %s", data_dir); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); strxmov(test_frm, data_dir, "/", current_db, "/", "test_frm_bug.frm", NullS); @@ -6623,7 +6708,8 @@ static void test_frm_bug() result= mysql_store_result(mysql); mytest(result);/* It can't be NULL */ - assert(1 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); mysql_data_seek(result, 0); @@ -6631,7 +6717,7 @@ static void test_frm_bug() mytest(row); fprintf(stdout, "\n Comment: %s", row[17]); - assert(row[17] != 0); + DIE_UNLESS(row[17] != 0); mysql_free_result(result); mysql_stmt_close(stmt); @@ -6694,10 +6780,10 @@ static void test_decimal_bug() check_execute(stmt, rc); fprintf(stdout, "\n data: %s", data); - assert(strcmp(data, "8.00") == 0); + DIE_UNLESS(strcmp(data, "8.00") == 0); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); strcpy(data, "5.61"); rc= mysql_stmt_execute(stmt); @@ -6711,17 +6797,17 @@ static void test_decimal_bug() check_execute(stmt, rc); fprintf(stdout, "\n data: %s", data); - assert(strcmp(data, "5.61") == 0); + DIE_UNLESS(strcmp(data, "5.61") == 0); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); is_null= 1; rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); strcpy(data, "10.22"); is_null= 0; rc= mysql_stmt_execute(stmt); @@ -6735,10 +6821,10 @@ static void test_decimal_bug() check_execute(stmt, rc); fprintf(stdout, "\n data: %s", data); - assert(strcmp(data, "10.22") == 0); + DIE_UNLESS(strcmp(data, "10.22") == 0); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -6768,14 +6854,15 @@ static void test_explain_bug() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert( 2 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 2); result= mysql_stmt_result_metadata(stmt); mytest(result); fprintf(stdout, "\n total fields in the result: %d", mysql_num_fields(result)); - assert(6 == mysql_num_fields(result)); + DIE_UNLESS(6 == mysql_num_fields(result)); verify_prepare_field(result, 0, "Field", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_LEN, 0); @@ -6804,14 +6891,15 @@ static void test_explain_bug() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert( 1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); result= mysql_stmt_result_metadata(stmt); mytest(result); fprintf(stdout, "\n total fields in the result: %d", mysql_num_fields(result)); - assert(10 == mysql_num_fields(result)); + DIE_UNLESS(10 == mysql_num_fields(result)); verify_prepare_field(result, 0, "id", "", MYSQL_TYPE_LONGLONG, "", "", "", 3, 0); @@ -6863,7 +6951,7 @@ static void check_errcode(const unsigned int err) else fprintf(stdout, "\n [MySQL]"); fprintf(stdout, "[%d] %s\n", mysql_errno(mysql), mysql_error(mysql)); - assert(mysql_errno(mysql) == err); + DIE_UNLESS(mysql_errno(mysql) == err); } @@ -6959,16 +7047,16 @@ static void test_drop_temp() rc= mysql_query(mysql, "drop database test_drop_temp_db"); myquery(rc); - assert(1 == mysql_affected_rows(mysql)); + DIE_UNLESS(1 == mysql_affected_rows(mysql)); rc= mysql_query(mysql, "delete from mysql.user where User='test_temp'"); myquery(rc); - assert(1 == mysql_affected_rows(mysql)); + DIE_UNLESS(1 == mysql_affected_rows(mysql)); rc= mysql_query(mysql, "delete from mysql.tables_priv where User='test_temp'"); myquery(rc); - assert(1 == mysql_affected_rows(mysql)); + DIE_UNLESS(1 == mysql_affected_rows(mysql)); } } #endif @@ -6997,14 +7085,14 @@ static void test_cuted_rows() count= mysql_warning_count(mysql); fprintf(stdout, "\n total warnings: %d", count); - assert(count == 0); + DIE_UNLESS(count == 0); rc= mysql_query(mysql, "INSERT INTO t2 SELECT * FROM t1"); myquery(rc); count= mysql_warning_count(mysql); fprintf(stdout, "\n total warnings: %d", count); - assert(count == 2); + DIE_UNLESS(count == 2); rc= mysql_query(mysql, "SHOW WARNINGS"); myquery(rc); @@ -7012,7 +7100,8 @@ static void test_cuted_rows() result= mysql_store_result(mysql); mytest(result); - assert(2 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 2); mysql_free_result(result); rc= mysql_query(mysql, "INSERT INTO t1 VALUES('junk'), (876789)"); @@ -7020,7 +7109,7 @@ static void test_cuted_rows() count= mysql_warning_count(mysql); fprintf(stdout, "\n total warnings: %d", count); - assert(count == 2); + DIE_UNLESS(count == 2); rc= mysql_query(mysql, "SHOW WARNINGS"); myquery(rc); @@ -7028,7 +7117,8 @@ static void test_cuted_rows() result= mysql_store_result(mysql); mytest(result); - assert(2 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 2); mysql_free_result(result); } @@ -7134,44 +7224,44 @@ static void test_logs() fprintf(stdout, "\n id : %d", id); fprintf(stdout, "\n name : %s(%ld)", data, length); - assert(id == 9876); - assert(length == 19); /* Due to VARCHAR(20) */ - assert(strcmp(data, "MySQL - Open Source") == 0); + DIE_UNLESS(id == 9876); + DIE_UNLESS(length == 19); /* Due to VARCHAR(20) */ + DIE_UNLESS(strcmp(data, "MySQL - Open Source") == 0); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n name : %s(%ld)", data, length); - assert(length == 1); - assert(strcmp(data, "'") == 0); + DIE_UNLESS(length == 1); + DIE_UNLESS(strcmp(data, "'") == 0); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n name : %s(%ld)", data, length); - assert(length == 1); - assert(strcmp(data, "\"") == 0); + DIE_UNLESS(length == 1); + DIE_UNLESS(strcmp(data, "\"") == 0); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n name : %s(%ld)", data, length); - assert(length == 7); - assert(strcmp(data, "my\'sql\'") == 0); + DIE_UNLESS(length == 7); + DIE_UNLESS(strcmp(data, "my\'sql\'") == 0); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n name : %s(%ld)", data, length); - assert(length == 7); - /*assert(strcmp(data, "my\"sql\"") == 0); */ + DIE_UNLESS(length == 7); + /*DIE_UNLESS(strcmp(data, "my\"sql\"") == 0); */ rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); @@ -7239,10 +7329,10 @@ static void test_nstmts() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); fprintf(stdout, "\n total rows: %d", i); - assert( i == total_stmts); + DIE_UNLESS( i == total_stmts); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); @@ -7339,7 +7429,7 @@ static void test_fetch_seek() check_execute(stmt, rc); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); } @@ -7396,17 +7486,17 @@ static void test_fetch_offset() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); fprintf(stdout, "\n col 1: %s (%ld)", data, length); - assert(strncmp(data, "abcd", 4) == 0 && length == 10); + DIE_UNLESS(strncmp(data, "abcd", 4) == 0 && length == 10); rc= mysql_stmt_fetch_column(stmt, bind, 0, 5); check_execute(stmt, rc); fprintf(stdout, "\n col 1: %s (%ld)", data, length); - assert(strncmp(data, "fg", 2) == 0 && length == 10); + DIE_UNLESS(strncmp(data, "fg", 2) == 0 && length == 10); rc= mysql_stmt_fetch_column(stmt, bind, 0, 9); check_execute(stmt, rc); fprintf(stdout, "\n col 0: %s (%ld)", data, length); - assert(strncmp(data, "j", 1) == 0 && length == 10); + DIE_UNLESS(strncmp(data, "j", 1) == 0 && length == 10); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); @@ -7416,10 +7506,10 @@ static void test_fetch_offset() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); - assert(is_null == 1); + DIE_UNLESS(is_null == 1); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); rc= mysql_stmt_fetch_column(stmt, bind, 1, 0); check_execute_r(stmt, rc); @@ -7490,13 +7580,13 @@ static void test_fetch_column() rc= mysql_stmt_fetch_column(stmt, bind, 1, 0); check_execute(stmt, rc); fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); - assert(strncmp(c2, "venu", 4) == 0 && l2 == 4); + DIE_UNLESS(strncmp(c2, "venu", 4) == 0 && l2 == 4); c2[0]= '\0'; l2= 0; rc= mysql_stmt_fetch_column(stmt, bind, 1, 0); check_execute(stmt, rc); fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); - assert(strcmp(c2, "venu") == 0 && l2 == 4); + DIE_UNLESS(strcmp(c2, "venu") == 0 && l2 == 4); c1= 0; bind[0].buffer_type= MYSQL_TYPE_LONG; @@ -7508,7 +7598,7 @@ static void test_fetch_column() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); fprintf(stdout, "\n col 0: %d(%ld)", c1, l1); - assert(c1 == 1 && l1 == 4); + DIE_UNLESS(c1 == 1 && l1 == 4); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); @@ -7525,13 +7615,13 @@ static void test_fetch_column() rc= mysql_stmt_fetch_column(stmt, bind, 1, 0); check_execute(stmt, rc); fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); - assert(strncmp(c2, "mysq", 4) == 0 && l2 == 5); + DIE_UNLESS(strncmp(c2, "mysq", 4) == 0 && l2 == 5); c2[0]= '\0'; l2= 0; rc= mysql_stmt_fetch_column(stmt, bind, 1, 0); check_execute(stmt, rc); fprintf(stdout, "\n col 1: %si(%ld)", c2, l2); - assert(strcmp(c2, "mysql") == 0 && l2 == 5); + DIE_UNLESS(strcmp(c2, "mysql") == 0 && l2 == 5); c1= 0; bind[0].buffer_type= MYSQL_TYPE_LONG; @@ -7543,10 +7633,10 @@ static void test_fetch_column() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); fprintf(stdout, "\n col 0: %d(%ld)", c1, l1); - assert(c1 == 2 && l1 == 4); + DIE_UNLESS(c1 == 2 && l1 == 4); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); rc= mysql_stmt_fetch_column(stmt, bind, 1, 0); check_execute_r(stmt, rc); @@ -7572,13 +7662,16 @@ static void test_list_fields() result= mysql_list_fields(mysql, "test_list_fields", NULL); mytest(result); - assert( 0 == my_process_result_set(result)); + rc= my_process_result_set(result); + DIE_UNLESS(rc == 0); verify_prepare_field(result, 0, "c1", "c1", MYSQL_TYPE_LONG, - "test_list_fields", "test_list_fields", current_db, 11, "0"); + "test_list_fields", "test_list_fields", + current_db, 11, "0"); verify_prepare_field(result, 1, "c2", "c2", MYSQL_TYPE_STRING, - "test_list_fields", "test_list_fields", current_db, 10, "mysql"); + "test_list_fields", "test_list_fields", + current_db, 10, "mysql"); mysql_free_result(result); } @@ -7631,7 +7724,8 @@ static void test_mem_overun() rc= mysql_query(mysql, "select * from t_mem_overun"); myquery(rc); - assert(1 == my_process_result(mysql)); + rc= my_process_result(mysql); + DIE_UNLESS(rc == 1); stmt= mysql_simple_prepare(mysql, "select * from t_mem_overun"); check_stmt(stmt); @@ -7643,7 +7737,7 @@ static void test_mem_overun() mytest(field_res); fprintf(stdout, "\n total fields : %d", mysql_num_fields(field_res)); - assert( 1000 == mysql_num_fields(field_res)); + DIE_UNLESS( 1000 == mysql_num_fields(field_res)); rc= mysql_stmt_store_result(stmt); check_execute(stmt, rc); @@ -7652,7 +7746,7 @@ static void test_mem_overun() check_execute(stmt, rc); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_free_result(field_res); @@ -7710,7 +7804,7 @@ static void test_free_result() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); fprintf(stdout, "\n col 0: %s(%ld)", c2, l2); - assert(strncmp(c2, "1", 1) == 0 && l2 == 1); + DIE_UNLESS(strncmp(c2, "1", 1) == 0 && l2 == 1); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); @@ -7725,7 +7819,7 @@ static void test_free_result() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); fprintf(stdout, "\n col 0: %d(%ld)", c1, l2); - assert(c1 == 2 && l2 == 4); + DIE_UNLESS(c1 == 2 && l2 == 4); rc= mysql_query(mysql, "drop table test_free_result"); myquery_r(rc); /* error should be, COMMANDS OUT OF SYNC */ @@ -7792,7 +7886,7 @@ static void test_free_store_result() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); - assert(strncmp(c2, "1", 1) == 0 && l2 == 1); + DIE_UNLESS(strncmp(c2, "1", 1) == 0 && l2 == 1); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); @@ -7807,7 +7901,7 @@ static void test_free_store_result() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); fprintf(stdout, "\n col 0: %d(%ld)", c1, l2); - assert(c1 == 2 && l2 == 4); + DIE_UNLESS(c1 == 2 && l2 == 4); rc= mysql_stmt_free_result(stmt); check_execute(stmt, rc); @@ -7916,7 +8010,7 @@ static void test_sqlmode() check_execute(stmt, rc); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); fprintf(stdout, "\n returned 1 row\n"); mysql_stmt_close(stmt); @@ -7939,7 +8033,7 @@ static void test_sqlmode() check_execute(stmt, rc); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); fprintf(stdout, "\n returned 1 row"); mysql_stmt_close(stmt); @@ -8019,7 +8113,8 @@ static void test_ts() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(2 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 2); field_count= mysql_num_fields(prep_res); mysql_free_result(prep_res); @@ -8045,7 +8140,7 @@ static void test_ts() row_count++; fprintf(stdout, "\n returned '%d' rows", row_count); - assert(row_count == 2); + DIE_UNLESS(row_count == 2); mysql_stmt_close(stmt); } } @@ -8097,7 +8192,8 @@ static void test_bug1500() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); mysql_stmt_close(stmt); @@ -8133,7 +8229,8 @@ static void test_bug1500() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); /* FIXME If we comment out next string server will crash too :( @@ -8159,7 +8256,8 @@ static void test_bug1500() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); mysql_stmt_close(stmt); } @@ -8182,7 +8280,7 @@ static void test_bug1946() stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); rc= mysql_real_query(mysql, query, strlen(query)); - assert(rc != 0); + DIE_UNLESS(rc != 0); fprintf(stdout, "Got error (as expected):\n"); myerror(NULL); @@ -8200,18 +8298,19 @@ static void test_parse_error_and_bad_length() myheader("test_parse_error_and_bad_length"); rc= mysql_query(mysql, "SHOW DATABAAAA"); - assert(rc); + DIE_UNLESS(rc); fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql)); rc= mysql_real_query(mysql, "SHOW DATABASES", 100); - assert(rc); + DIE_UNLESS(rc); fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql)); stmt= mysql_simple_prepare(mysql, "SHOW DATABAAAA"); - assert(!stmt); + DIE_UNLESS(!stmt); fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql)); stmt= mysql_stmt_init(mysql); - assert(stmt); - assert(mysql_stmt_prepare(stmt, "SHOW DATABASES", 100) != 0); + DIE_UNLESS(stmt); + rc= mysql_stmt_prepare(stmt, "SHOW DATABASES", 100); + DIE_UNLESS(rc != 0); fprintf(stdout, "Got error (as expected): '%s'\n", mysql_stmt_error(stmt)); mysql_stmt_close(stmt); } @@ -8250,7 +8349,7 @@ static void test_bug2247() check_execute(stmt, rc); } exp_count= mysql_stmt_affected_rows(stmt); - assert(exp_count == 1); + DIE_UNLESS(exp_count == 1); rc= mysql_query(mysql, select); myquery(rc); @@ -8262,13 +8361,13 @@ static void test_bug2247() res= mysql_store_result(mysql); mytest(res); - assert(mysql_affected_rows(mysql) == NUM_ROWS); - assert(exp_count == mysql_stmt_affected_rows(stmt)); + DIE_UNLESS(mysql_affected_rows(mysql) == NUM_ROWS); + DIE_UNLESS(exp_count == mysql_stmt_affected_rows(stmt)); rc= mysql_query(mysql, update); myquery(rc); - assert(mysql_affected_rows(mysql) == NUM_ROWS); - assert(exp_count == mysql_stmt_affected_rows(stmt)); + DIE_UNLESS(mysql_affected_rows(mysql) == NUM_ROWS); + DIE_UNLESS(exp_count == mysql_stmt_affected_rows(stmt)); mysql_free_result(res); mysql_stmt_close(stmt); @@ -8282,12 +8381,12 @@ static void test_bug2247() rc= mysql_stmt_store_result(stmt); check_execute(stmt, rc); exp_count= mysql_stmt_affected_rows(stmt); - assert(exp_count == NUM_ROWS); + DIE_UNLESS(exp_count == NUM_ROWS); rc= mysql_query(mysql, insert); myquery(rc); - assert(mysql_affected_rows(mysql) == 1); - assert(mysql_stmt_affected_rows(stmt) == exp_count); + DIE_UNLESS(mysql_affected_rows(mysql) == 1); + DIE_UNLESS(mysql_stmt_affected_rows(stmt) == exp_count); mysql_stmt_close(stmt); fprintf(stdout, "OK"); @@ -8321,7 +8420,8 @@ static void test_subqueries() { rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(5 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 5); } mysql_stmt_close(stmt); @@ -8338,7 +8438,7 @@ static void test_bad_union() myheader("test_bad_union"); stmt= mysql_simple_prepare(mysql, query); - assert(stmt == 0); + DIE_UNLESS(stmt == 0); myerror(NULL); } @@ -8369,7 +8469,8 @@ static void test_distinct() check_stmt(stmt); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(5 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 5); mysql_stmt_close(stmt); } @@ -8418,7 +8519,7 @@ static void test_bug2248() /* This too should not hang but should return proper error */ rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); /* This too should not hang but should not bark */ rc= mysql_stmt_store_result(stmt); @@ -8427,7 +8528,7 @@ static void test_bug2248() /* This should return proper error */ rc= mysql_stmt_fetch(stmt); check_execute_r(stmt, rc); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); @@ -8460,7 +8561,8 @@ static void test_subqueries_ref() { rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); } mysql_stmt_close(stmt); @@ -8513,7 +8615,8 @@ static void test_union() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(20 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 20); mysql_stmt_close(stmt); rc= mysql_query(mysql, "DROP TABLE t1, t2"); @@ -8563,7 +8666,7 @@ static void test_bug3117() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - assert(is_null == 0 && lii == 1); + DIE_UNLESS(is_null == 0 && lii == 1); fprintf(stdout, "\n\tLAST_INSERT_ID()= 1 ok\n"); rc= mysql_query(mysql, "INSERT INTO t1 VALUES (NULL)"); @@ -8575,7 +8678,7 @@ static void test_bug3117() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - assert(is_null == 0 && lii == 2); + DIE_UNLESS(is_null == 0 && lii == 2); fprintf(stdout, "\tLAST_INSERT_ID()= 2 ok\n"); mysql_stmt_close(stmt); @@ -8626,7 +8729,8 @@ static void test_join() { rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(5 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 5); } mysql_stmt_close(stmt); } @@ -8673,7 +8777,8 @@ static void test_selecttmp() { rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(3 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 3); } mysql_stmt_close(stmt); @@ -8728,7 +8833,8 @@ static void test_create_drop() rc= mysql_stmt_execute(stmt_select); check_execute(stmt_select, rc); - assert(0 == my_process_stmt_result(stmt_select)); + rc= my_process_stmt_result(stmt_select); + DIE_UNLESS(rc == 0); rc= mysql_stmt_execute(stmt_drop); check_execute(stmt_drop, rc); @@ -8740,7 +8846,8 @@ static void test_create_drop() rc= mysql_stmt_execute(stmt_select); check_execute(stmt_select, rc); - assert(3 == my_process_stmt_result(stmt_select)); + rc= my_process_stmt_result(stmt_select); + DIE_UNLESS(rc == 3); rc= mysql_stmt_execute(stmt_drop); check_execute(stmt_drop, rc); @@ -8904,11 +9011,13 @@ static void test_multi() rc= mysql_stmt_execute(stmt_select1); check_execute(stmt_select1, rc); - assert((uint)(3-param) == my_process_stmt_result(stmt_select1)); + rc= my_process_stmt_result(stmt_select1); + DIE_UNLESS(rc == 3-param); rc= mysql_stmt_execute(stmt_select2); check_execute(stmt_select2, rc); - assert((uint)(3-param) == my_process_stmt_result(stmt_select2)); + rc= my_process_stmt_result(stmt_select2); + DIE_UNLESS(rc == 3-param); param++; } @@ -8958,7 +9067,8 @@ static void test_insert_select() rc= mysql_stmt_execute(stmt_select); check_execute(stmt_select, rc); - assert((i+1) == my_process_stmt_result(stmt_select)); + rc= my_process_stmt_result(stmt_select); + DIE_UNLESS(rc == (int)(i+1)); } mysql_stmt_close(stmt_insert); @@ -9056,7 +9166,8 @@ TYPE=InnoDB DEFAULT CHARSET=utf8"); { rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); } mysql_stmt_close(stmt); @@ -9108,7 +9219,8 @@ static void test_xjoin() { rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); } mysql_stmt_close(stmt); @@ -9265,37 +9377,37 @@ static void test_bug3035() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - assert(int8_val == int8_min); - assert(uint8_val == uint8_min); - assert(int16_val == int16_min); - assert(uint16_val == uint16_min); - assert(int32_val == int32_min); - assert(uint32_val == uint32_min); - assert(int64_val == int64_min); - assert(uint64_val == uint64_min); - assert(double_val == (longlong) uint64_min); - assert(udouble_val == ulonglong2double(uint64_val)); - assert(!strcmp(longlong_as_string, "0")); - assert(!strcmp(ulonglong_as_string, "0")); + DIE_UNLESS(int8_val == int8_min); + DIE_UNLESS(uint8_val == uint8_min); + DIE_UNLESS(int16_val == int16_min); + DIE_UNLESS(uint16_val == uint16_min); + DIE_UNLESS(int32_val == int32_min); + DIE_UNLESS(uint32_val == uint32_min); + DIE_UNLESS(int64_val == int64_min); + DIE_UNLESS(uint64_val == uint64_min); + DIE_UNLESS(double_val == (longlong) uint64_min); + DIE_UNLESS(udouble_val == ulonglong2double(uint64_val)); + DIE_UNLESS(!strcmp(longlong_as_string, "0")); + DIE_UNLESS(!strcmp(ulonglong_as_string, "0")); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - assert(int8_val == int8_max); - assert(uint8_val == uint8_max); - assert(int16_val == int16_max); - assert(uint16_val == uint16_max); - assert(int32_val == int32_max); - assert(uint32_val == uint32_max); - assert(int64_val == int64_max); - assert(uint64_val == uint64_max); - assert(double_val == (longlong) uint64_val); - assert(udouble_val == ulonglong2double(uint64_val)); - assert(!strcmp(longlong_as_string, "-1")); - assert(!strcmp(ulonglong_as_string, "18446744073709551615")); + DIE_UNLESS(int8_val == int8_max); + DIE_UNLESS(uint8_val == uint8_max); + DIE_UNLESS(int16_val == int16_max); + DIE_UNLESS(uint16_val == uint16_max); + DIE_UNLESS(int32_val == int32_max); + DIE_UNLESS(uint32_val == uint32_max); + DIE_UNLESS(int64_val == int64_max); + DIE_UNLESS(uint64_val == uint64_max); + DIE_UNLESS(double_val == (longlong) uint64_val); + DIE_UNLESS(udouble_val == ulonglong2double(uint64_val)); + DIE_UNLESS(!strcmp(longlong_as_string, "-1")); + DIE_UNLESS(!strcmp(ulonglong_as_string, "18446744073709551615")); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); @@ -9329,7 +9441,8 @@ static void test_union2() { rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(0 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 0); } mysql_stmt_close(stmt); @@ -9562,7 +9675,8 @@ static void test_union_param() { rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - assert(1 == my_process_stmt_result(stmt)); + rc= my_process_stmt_result(stmt); + DIE_UNLESS(rc == 1); } mysql_stmt_close(stmt); @@ -9653,13 +9767,13 @@ static void test_ps_i18n() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - assert(buf1_len == strlen(cp1251)); - assert(buf2_len == strlen(cp1251)); - assert(!memcmp(buf1, cp1251, buf1_len)); - assert(!memcmp(buf2, cp1251, buf1_len)); + DIE_UNLESS(buf1_len == strlen(cp1251)); + DIE_UNLESS(buf2_len == strlen(cp1251)); + DIE_UNLESS(!memcmp(buf1, cp1251, buf1_len)); + DIE_UNLESS(!memcmp(buf2, cp1251, buf1_len)); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); stmt_text= "DROP TABLE IF EXISTS t1"; rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); @@ -9738,12 +9852,12 @@ static void test_ps_i18n() while ((rc= mysql_stmt_fetch(stmt)) == 0) { - assert(buf1_len == strlen(koi8)); - assert(buf2_len == strlen(koi8)); - assert(!memcmp(buf1, koi8, buf1_len)); - assert(!memcmp(buf2, koi8, buf1_len)); + DIE_UNLESS(buf1_len == strlen(koi8)); + DIE_UNLESS(buf2_len == strlen(koi8)); + DIE_UNLESS(!memcmp(buf1, koi8, buf1_len)); + DIE_UNLESS(!memcmp(buf2, koi8, buf1_len)); } - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); stmt_text= "DROP TABLE t1"; @@ -9813,18 +9927,18 @@ static void test_bug3796() check_execute(stmt, rc); strcpy(canonical_buff, concat_arg0); strcat(canonical_buff, "ONE"); - assert(strlen(canonical_buff) == out_length && + DIE_UNLESS(strlen(canonical_buff) == out_length && strncmp(out_buff, canonical_buff, out_length) == 0); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); strcpy(canonical_buff + strlen(concat_arg0), "TWO"); - assert(strlen(canonical_buff) == out_length && + DIE_UNLESS(strlen(canonical_buff) == out_length && strncmp(out_buff, canonical_buff, out_length) == 0); printf("Concat result: '%s'\n", out_buff); rc= mysql_stmt_fetch(stmt); - assert(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); mysql_stmt_close(stmt); @@ -9871,7 +9985,7 @@ static void test_bug4026() time_in.second= 59; time_in.second_part= 123456; /* - This is not necessary, just to make assert below work: this field + This is not necessary, just to make DIE_UNLESS below work: this field is filled in when time is received from server */ time_in.time_type= MYSQL_TIMESTAMP_TIME; @@ -9894,15 +10008,15 @@ static void test_bug4026() mysql_stmt_bind_result(stmt, bind); rc= mysql_stmt_fetch(stmt); - assert(rc == 0); + DIE_UNLESS(rc == 0); printf("%d:%d:%d.%lu\n", time_out.hour, time_out.minute, time_out.second, time_out.second_part); printf("%d-%d-%d %d:%d:%d.%lu\n", datetime_out.year, datetime_out.month, datetime_out.day, datetime_out.hour, datetime_out.minute, datetime_out.second, datetime_out.second_part); - assert(memcmp(&time_in, &time_out, sizeof(time_in)) == 0); - assert(memcmp(&datetime_in, &datetime_out, sizeof(datetime_in)) == 0); + DIE_UNLESS(memcmp(&time_in, &time_out, sizeof(time_in)) == 0); + DIE_UNLESS(memcmp(&datetime_in, &datetime_out, sizeof(datetime_in)) == 0); mysql_stmt_close(stmt); } @@ -9942,7 +10056,7 @@ static void test_bug4079() mysql_stmt_bind_result(stmt, bind); rc= mysql_stmt_fetch(stmt); - assert(rc != 0 && rc != MYSQL_NO_DATA); + DIE_UNLESS(rc != 0 && rc != MYSQL_NO_DATA); printf("Got error from mysql_stmt_fetch (as expected):\n%s\n", mysql_stmt_error(stmt)); /* buggy version of libmysql hanged up here */ @@ -9970,7 +10084,7 @@ static void test_bug4236() backup.stmt_id= stmt->stmt_id; stmt->stmt_id= 0; rc= mysql_stmt_execute(stmt); - assert(rc); + DIE_UNLESS(rc); /* Restore original statement id to be able to reprepare it */ stmt->stmt_id= backup.stmt_id; @@ -10037,7 +10151,7 @@ static void test_bug4030() mysql_stmt_bind_result(stmt, bind); rc= mysql_stmt_fetch(stmt); - assert(rc == 0); + DIE_UNLESS(rc == 0); printf("%d:%d:%d.%lu\n", time_out.hour, time_out.minute, time_out.second, time_out.second_part); printf("%d-%d-%d\n", date_out.year, date_out.month, date_out.day); @@ -10045,9 +10159,9 @@ static void test_bug4030() datetime_out.day, datetime_out.hour, datetime_out.minute, datetime_out.second, datetime_out.second_part); - assert(memcmp(&time_canonical, &time_out, sizeof(time_out)) == 0); - assert(memcmp(&date_canonical, &date_out, sizeof(date_out)) == 0); - assert(memcmp(&datetime_canonical, &datetime_out, sizeof(datetime_out)) == 0); + DIE_UNLESS(memcmp(&time_canonical, &time_out, sizeof(time_out)) == 0); + DIE_UNLESS(memcmp(&date_canonical, &date_out, sizeof(date_out)) == 0); + DIE_UNLESS(memcmp(&datetime_canonical, &datetime_out, sizeof(datetime_out)) == 0); mysql_stmt_close(stmt); } @@ -10092,8 +10206,8 @@ static void test_bug5126() mysql_stmt_bind_result(stmt, bind); rc= mysql_stmt_fetch(stmt); - assert(rc == 0); - assert(c1 == 8386608 && c2 == 1); + DIE_UNLESS(rc == 0); + DIE_UNLESS(c1 == 8386608 && c2 == 1); printf("%ld, %ld\n", (long) c1, (long) c2); mysql_stmt_close(stmt); } @@ -10156,14 +10270,14 @@ static void test_bug4231() rc= mysql_stmt_fetch(stmt); /* binds are unequal, no rows should be returned */ - DBUG_ASSERT(rc == MYSQL_NO_DATA); + DIE_UNLESS(rc == MYSQL_NO_DATA); /* Set one of the dates to zero */ tm[0].year= tm[0].month= tm[0].day= 0; tm[1]= tm[0]; mysql_stmt_execute(stmt); rc= mysql_stmt_fetch(stmt); - DBUG_ASSERT(rc == 0); + DIE_UNLESS(rc == 0); mysql_stmt_close(stmt); stmt_text= "DROP TABLE t1"; @@ -10208,8 +10322,8 @@ static void test_bug5399() rc= mysql_stmt_store_result(stmt[i]); check_execute(stmt[i], rc); rc= mysql_stmt_fetch(stmt[i]); - assert(rc == 0); - assert((int32) i == no); + DIE_UNLESS(rc == 0); + DIE_UNLESS((int32) i == no); } for (i= 0; i < NUM_OF_USED_STMT; ++i) @@ -10410,19 +10524,19 @@ static void test_bug5315() stmt_text= "SELECT 1"; stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); - DBUG_ASSERT(rc == 0); + DIE_UNLESS(rc == 0); mysql_change_user(mysql, opt_user, opt_password, current_db); rc= mysql_stmt_execute(stmt); - DBUG_ASSERT(rc != 0); + DIE_UNLESS(rc != 0); if (rc) printf("Got error (as expected):\n%s", mysql_stmt_error(stmt)); /* check that connection is OK */ mysql_stmt_close(stmt); stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); - DBUG_ASSERT(rc == 0); + DIE_UNLESS(rc == 0); rc= mysql_stmt_execute(stmt); - DBUG_ASSERT(rc == 0); + DIE_UNLESS(rc == 0); mysql_stmt_close(stmt); } From fd6009accbe37ba3353e7a49ab29c62f22b0cb6f Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 13 Oct 2004 17:42:22 +0200 Subject: [PATCH 04/17] BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. Fixed problems detected on Windows build by VC++. Removed unused variables. Applied a neccessary cast. --- sql/sql_handler.cc | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index ffd64134182..f98bb0a9131 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -261,8 +261,6 @@ int mysql_ha_close(THD *thd, TABLE_LIST *tables) { TABLE_LIST *hash_tables; TABLE **table_ptr; - bool was_flushed= FALSE; - bool not_opened; DBUG_ENTER("mysql_ha_close"); DBUG_PRINT("enter",("'%s'.'%s' as '%s'", tables->db, tables->real_name, tables->alias)); @@ -366,7 +364,6 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, uint num_rows; byte *key; uint key_len; - bool was_flushed; DBUG_ENTER("mysql_ha_read"); DBUG_PRINT("enter",("'%s'.'%s' as '%s'", tables->db, tables->real_name, tables->alias)); @@ -624,10 +621,8 @@ err0: int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags) { - TABLE_LIST **tmp_tables_p; TABLE_LIST *tmp_tables; TABLE **table_ptr; - bool was_flushed; DBUG_ENTER("mysql_ha_flush"); DBUG_PRINT("enter", ("tables: %p mode_flags: 0x%02x", tables, mode_flags)); @@ -703,14 +698,13 @@ static int mysql_ha_flush_table(THD *thd, TABLE **table_ptr, uint mode_flags) { TABLE_LIST *hash_tables; TABLE *table= *table_ptr; - bool was_flushed; DBUG_ENTER("mysql_ha_flush_table"); DBUG_PRINT("enter",("'%s'.'%s' as '%s' flags: 0x%02x", table->table_cache_key, table->real_name, table->table_name, mode_flags)); if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash, - (*table_ptr)->table_name, + (byte*) (*table_ptr)->table_name, strlen((*table_ptr)->table_name) + 1))) { if (! (mode_flags & MYSQL_HA_REOPEN_ON_USAGE)) From 7b1f818d913f4ff96c2e33a7ffc4f3ad688374a5 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 13 Oct 2004 20:04:52 +0300 Subject: [PATCH 05/17] srv0srv.c, log0log.c, srv0srv.h, ha_innodb.cc, ha_innodb.h: Implement innobase_very_fast_shutdown and innobase_start_trx_and_assign_read_view(); these were requested by Guilhem sql/ha_innodb.h: Implement innobase_very_fast_shutdown and innobase_start_trx_and_assign_read_view(); these were requested by Guilhem sql/ha_innodb.cc: Implement innobase_very_fast_shutdown and innobase_start_trx_and_assign_read_view(); these were requested by Guilhem innobase/include/srv0srv.h: Implement innobase_very_fast_shutdown and innobase_start_trx_and_assign_read_view(); these were requested by Guilhem innobase/log/log0log.c: Implement innobase_very_fast_shutdown and innobase_start_trx_and_assign_read_view(); these were requested by Guilhem innobase/srv/srv0srv.c: Implement innobase_very_fast_shutdown and innobase_start_trx_and_assign_read_view(); these were requested by Guilhem --- innobase/include/srv0srv.h | 5 ++- innobase/log/log0log.c | 39 +++++++++++++++++------ innobase/srv/srv0srv.c | 23 ++++++++++++-- sql/ha_innodb.cc | 65 +++++++++++++++++++++++++++++++++++++- sql/ha_innodb.h | 6 ++++ 5 files changed, 124 insertions(+), 14 deletions(-) diff --git a/innobase/include/srv0srv.h b/innobase/include/srv0srv.h index 2050e5b45c0..ecd57bae47c 100644 --- a/innobase/include/srv0srv.h +++ b/innobase/include/srv0srv.h @@ -100,7 +100,10 @@ extern ulint srv_max_n_threads; extern lint srv_conc_n_threads; extern ibool srv_fast_shutdown; - +extern ibool srv_very_fast_shutdown; /* if this TRUE, do not flush the + buffer pool to data files at the + shutdown; we effectively 'crash' + InnoDB */ extern ibool srv_innodb_status; extern ibool srv_use_doublewrite_buf; diff --git a/innobase/log/log0log.c b/innobase/log/log0log.c index b6357fa2c76..e08adb013b5 100644 --- a/innobase/log/log0log.c +++ b/innobase/log/log0log.c @@ -3048,13 +3048,25 @@ loop: #ifdef UNIV_LOG_ARCHIVE log_archive_all(); #endif /* UNIV_LOG_ARCHIVE */ - log_make_checkpoint_at(ut_dulint_max, TRUE); + + if (!srv_very_fast_shutdown) { + /* In a 'very fast' shutdown we do not flush the buffer pool: + it is essentially a 'crash' of the InnoDB server. */ + + log_make_checkpoint_at(ut_dulint_max, TRUE); + } else { + /* Make sure that the log is all flushed to disk, so that + we can recover all committed transactions in a crash + recovery */ + log_buffer_flush_to_disk(); + } mutex_enter(&(log_sys->mutex)); lsn = log_sys->lsn; - if (ut_dulint_cmp(lsn, log_sys->last_checkpoint_lsn) != 0 + if ((ut_dulint_cmp(lsn, log_sys->last_checkpoint_lsn) != 0 + && !srv_very_fast_shutdown) #ifdef UNIV_LOG_ARCHIVE || (srv_log_archive_on && ut_dulint_cmp(lsn, @@ -3098,11 +3110,12 @@ loop: fil_flush_file_spaces(FIL_TABLESPACE); fil_flush_file_spaces(FIL_LOG); - /* The next fil_write_... will pass the buffer pool: therefore - it is essential that the buffer pool has been completely flushed - to disk! */ + /* The call fil_write_flushed_lsn_to_data_files() will pass the buffer + pool: therefore it is essential that the buffer pool has been + completely flushed to disk! (We do not call fil_write... if the + 'very fast' shutdown is enabled.) */ - if (!buf_all_freed()) { + if (!srv_very_fast_shutdown && !buf_all_freed()) { goto loop; } @@ -3125,7 +3138,7 @@ loop: /* Make some checks that the server really is quiet */ ut_a(srv_n_threads_active[SRV_MASTER] == 0); - ut_a(buf_all_freed()); + ut_a(srv_very_fast_shutdown || buf_all_freed()); ut_a(0 == ut_dulint_cmp(lsn, log_sys->lsn)); if (ut_dulint_cmp(lsn, srv_start_lsn) < 0) { @@ -3140,7 +3153,15 @@ loop: srv_shutdown_lsn = lsn; - fil_write_flushed_lsn_to_data_files(lsn, arch_log_no); + if (!srv_very_fast_shutdown) { + /* In a 'very fast' shutdown we do not flush the buffer pool: + it is essentially a 'crash' of the InnoDB server. Then we must + not write the lsn stamps to the data files, since at a + startup InnoDB deduces from the stamps if the previous + shutdown was clean. */ + + fil_write_flushed_lsn_to_data_files(lsn, arch_log_no); + } fil_flush_file_spaces(FIL_TABLESPACE); @@ -3148,7 +3169,7 @@ loop: /* Make some checks that the server really is quiet */ ut_a(srv_n_threads_active[SRV_MASTER] == 0); - ut_a(buf_all_freed()); + ut_a(srv_very_fast_shutdown || buf_all_freed()); ut_a(0 == ut_dulint_cmp(lsn, log_sys->lsn)); } diff --git a/innobase/srv/srv0srv.c b/innobase/srv/srv0srv.c index adffe06ef0a..d913d77fdfc 100644 --- a/innobase/srv/srv0srv.c +++ b/innobase/srv/srv0srv.c @@ -249,6 +249,10 @@ merge to completion before shutdown */ ibool srv_fast_shutdown = FALSE; +ibool srv_very_fast_shutdown = FALSE; /* if this TRUE, do not flush the + buffer pool to data files at the + shutdown; we effectively 'crash' + InnoDB */ /* Generate a innodb_status. file */ ibool srv_innodb_status = FALSE; @@ -2178,7 +2182,8 @@ loop: /*****************************************************************/ background_loop: /* ---- In this loop we run background operations when the server - is quiet from user activity */ + is quiet from user activity. Also in the case of a shutdown, we + loop here, flushing the buffer pool to the data files. */ /* The server has been quiet for a while: start running background operations */ @@ -2251,7 +2256,16 @@ background_loop: flush_loop: srv_main_thread_op_info = "flushing buffer pool pages"; - n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST, 100, ut_dulint_max); + + if (!srv_very_fast_shutdown) { + n_pages_flushed = + buf_flush_batch(BUF_FLUSH_LIST, 100, ut_dulint_max); + } else { + /* In a 'very fast' shutdown we do not flush the buffer pool + to data files: we set n_pages_flushed to 0 artificially. */ + + n_pages_flushed = 0; + } srv_main_thread_op_info = "reserving kernel mutex"; @@ -2304,7 +2318,10 @@ flush_loop: /* If we are doing a fast shutdown (= the default) we do not do purge or insert buffer merge. But we - flush the buffer pool completely to disk. */ + flush the buffer pool completely to disk. + In a 'very fast' shutdown we do not flush the buffer + pool to data files: we have set n_pages_flushed to + 0 artificially. */ goto background_loop; } diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index f10731628da..d748c005d02 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -20,6 +20,9 @@ NOTE: You can only use noninlined InnoDB functions in this file, because we have disables the InnoDB inlining in this file. */ /* TODO list for the InnoDB handler in 4.1: + - Remove the flag innodb_active_trans from thd and replace it with a + function call innodb_active_trans(thd), which looks at the InnoDB + trx struct state field - Find out what kind of problems the OS X case-insensitivity causes to table and database names; should we 'normalize' the names like we do in Windows? @@ -114,6 +117,9 @@ uint innobase_flush_log_at_trx_commit = 1; my_bool innobase_log_archive = FALSE;/* unused */ my_bool innobase_use_native_aio = FALSE; my_bool innobase_fast_shutdown = TRUE; +my_bool innobase_very_fast_shutdown = FALSE; /* this can be set to + 1 just prior calling + innobase_end() */ my_bool innobase_file_per_table = FALSE; my_bool innobase_locks_unsafe_for_binlog = FALSE; my_bool innobase_create_status_file = FALSE; @@ -799,6 +805,10 @@ ha_innobase::init_table_handle_for_HANDLER(void) trx_assign_read_view(prebuilt->trx); + /* Set the MySQL flag to mark that there is an active transaction */ + + current_thd->transaction.all.innodb_active_trans = 1; + /* We did the necessary inits in this function, no need to repeat them in row_search_for_mysql */ @@ -1059,6 +1069,15 @@ innobase_end(void) #endif if (innodb_inited) { + if (innobase_very_fast_shutdown) { + srv_very_fast_shutdown = TRUE; + fprintf(stderr, +"InnoDB: MySQL has requested a very fast shutdown without flushing\n" +"InnoDB: the InnoDB buffer pool to data files. At the next mysqld startup\n" +"InnoDB: InnoDB will do a crash recovery!\n"); + + } + innodb_inited= 0; if (innobase_shutdown_for_mysql() != DB_SUCCESS) err= 1; @@ -1115,6 +1134,48 @@ innobase_commit_low( trx_commit_for_mysql(trx); } +/********************************************************************* +Creates an InnoDB transaction struct for the thd if it does not yet have one. +Starts a new InnoDB transaction if a transaction is not yet started. And +assigns a new snapshot for a consistent read if the transaction does not yet +have one. */ + +int +innobase_start_trx_and_assign_read_view( +/*====================================*/ + /* out: 0 */ + THD* thd) /* in: MySQL thread handle of the user for whom + the transaction should be committed */ +{ + trx_t* trx; + + DBUG_ENTER("innobase_start_trx_and_assign_read_view"); + + /* Create a new trx struct for thd, if it does not yet have one */ + + trx = check_trx_exists(thd); + + /* This is just to play safe: release a possible FIFO ticket and + search latch. Since we will reserve the kernel mutex, we have to + release the search system latch first to obey the latching order. */ + + innobase_release_stat_resources(trx); + + /* If the transaction is not started yet, start it */ + + trx_start_if_not_started_noninline(trx); + + /* Assign a read view if the transaction does not have it yet */ + + trx_assign_read_view(trx); + + /* Set the MySQL flag to mark that there is an active transaction */ + + current_thd->transaction.all.innodb_active_trans = 1; + + DBUG_RETURN(0); +} + /********************************************************************* Commits a transaction in an InnoDB database or marks an SQL statement ended. */ @@ -1146,8 +1207,10 @@ innobase_commit( 1. ::external_lock(), 2. ::start_stmt(), - 3. innobase_query_caching_of_table_permitted(), and + 3. innobase_query_caching_of_table_permitted(), 4. innobase_savepoint(), + 5. ::init_table_handle_for_HANDLER(), + 6. innobase_start_trx_and_assign_read_view() and it is only set to 0 in a commit or a rollback. If it is 0 we know there cannot be resources to be freed and we could return immediately. diff --git a/sql/ha_innodb.h b/sql/ha_innodb.h index d72f5a58fe4..7f7b000a100 100644 --- a/sql/ha_innodb.h +++ b/sql/ha_innodb.h @@ -191,6 +191,11 @@ extern my_bool innobase_log_archive, innobase_use_native_aio, innobase_fast_shutdown, innobase_file_per_table, innobase_locks_unsafe_for_binlog, innobase_create_status_file; +extern my_bool innobase_very_fast_shutdown; /* set this to 1 just before + calling innobase_end() if you want + InnoDB to shut down without + flushing the buffer pool: this + is equivalent to a 'crash' */ extern "C" { extern ulong srv_max_buf_pool_modified_pct; extern ulong srv_auto_extend_increment; @@ -231,3 +236,4 @@ void innobase_release_temporary_latches(void* innobase_tid); void innobase_store_binlog_offset_and_flush_log(char *binlog_name,longlong offset); +int innobase_start_trx_and_assign_read_view(THD* thd); From 54b00f5453b49047142d59da21e19d607f4b208e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 Oct 2004 02:53:59 +0400 Subject: [PATCH 06/17] A fix and test case for Bug#5985 ""prepare stmt from "select rand(?)" crashes server." The fix makes Item_func_rand prepared-statements aware plus it fixes the case when RAND is used in prepared statements and replication is on (as well as several similar issues). Until now we did not reset THD before every execution of a prepared statement, so if some execution had set thd->time_zone_used or thd->rand_used they would not be reset until next mysql_parse. Some of post-review fixes done. mysql-test/r/ps.result: A test case for Bug#5985: test results fixed. mysql-test/t/ps.test: A test case for Bug#5985 "prepare stmt from "select rand(?)" crashes server." sql/item_func.cc: Actual fix for Bug#5985: Item_func_rand rewritten to be prepared statements aware. sql/item_func.h: Actual fix for Bug#5985: Item_func_rand rewritten to be prepared statements aware. sql/mysql_priv.h: We need a separate call to reset THD state before every execute of a prepared statement. Otherwise things like THD->user_var_events are never cleaned up and bloat binary log (as the list of events grows from execution to execution). sql/sql_class.cc: Statement::end_statement -> THD::end_statement() (a leftover from some design change which is not to pushed now, but the leftover is to be pushed). sql/sql_class.h: Statement::end_statement -> THD::end_statement() (a leftover from some design change which is not to pushed now, but the leftover is to be pushed). sql/sql_lex.cc: Move the part responsible for initializing LEX from mysql_init_query to lex_start. sql/sql_lex.h: All lex-related initialization is now in lex_start. Move thd->select_number to lex->select_number to be able to use it easily in lex_start. sql/sql_parse.cc: Split mysql_init_query into two functions: mysql_reset_thd_for_next_query, which is used in PS and conventional execution, and lex_start, used only when we want to parse something. Fix init_connect to use initialized THD. sql/sql_prepare.cc: Deploy mysql_reset_thd_for_next_query to reset THD state before execution of a prepared statement. Normally this should have been added to just one place, but we have to reset thd before assigning placeholders from variables, thus we can't do that in execute_stmt (yuck). --- mysql-test/r/ps.result | 39 +++++++++++++++++++++++++++++ mysql-test/t/ps.test | 28 ++++++++++++++++++++- sql/item_func.cc | 34 +++++++++++++++++++------ sql/item_func.h | 6 ++--- sql/mysql_priv.h | 1 + sql/sql_class.cc | 2 +- sql/sql_class.h | 12 ++++----- sql/sql_lex.cc | 23 +++++++++++++++++ sql/sql_lex.h | 4 +-- sql/sql_parse.cc | 57 +++++++++++++++++++----------------------- sql/sql_prepare.cc | 7 ++++-- 11 files changed, 159 insertions(+), 54 deletions(-) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index df5fa5fe999..0aba0c4672e 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -336,3 +336,42 @@ id select_type table type possible_keys key key_len ref rows Extra - - - - - - - - NULL Impossible WHERE drop table t1; deallocate prepare stmt; +create table t1 (a int); +insert into t1 (a) values (1), (2), (3), (4); +set @precision=10000000000; +select rand(), +cast(rand(10)*@precision as unsigned integer), +cast(rand(a)*@precision as unsigned integer) from t1; +rand() cast(rand(10)*@precision as unsigned integer) cast(rand(a)*@precision as unsigned integer) +- 6570515219 - +- 1282061302 - +- 6698761160 - +- 9647622201 - +prepare stmt from +"select rand(), + cast(rand(10)*@precision as unsigned integer), + cast(rand(a)*@precision as unsigned integer), + cast(rand(?)*@precision as unsigned integer) from t1"; +set @var=1; +execute stmt using @var; +rand() cast(rand(10)*@precision as unsigned integer) cast(rand(a)*@precision as unsigned integer) cast(rand(?)*@precision as unsigned integer) +- 6570515219 - 4054035371 +- 1282061302 - 8716141803 +- 6698761160 - 1418603212 +- 9647622201 - 944590960 +set @var=2; +execute stmt using @var; +rand() cast(rand(10)*@precision as unsigned integer) cast(rand(a)*@precision as unsigned integer) cast(rand(?)*@precision as unsigned integer) +- 6570515219 1559528654 6555866465 +- 1282061302 6238114970 1223466192 +- 6698761160 6511989195 6449731873 +- 9647622201 3845601374 8578261098 +set @var=3; +execute stmt using @var; +rand() cast(rand(10)*@precision as unsigned integer) cast(rand(a)*@precision as unsigned integer) cast(rand(?)*@precision as unsigned integer) +- 6570515219 1559528654 9057697559 +- 1282061302 6238114970 3730790581 +- 6698761160 6511989195 1480860534 +- 9647622201 3845601374 6211931236 +drop table t1; +deallocate prepare stmt; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 76c7fb7c2e7..7cbcd50245f 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -363,4 +363,30 @@ execute stmt using @v; drop table t1; deallocate prepare stmt; - +# +# A test case for Bug#5985 prepare stmt from "select rand(?)" crashes +# server. Check that Item_func_rand is prepared-statements friendly. +# +create table t1 (a int); +insert into t1 (a) values (1), (2), (3), (4); +set @precision=10000000000; +--replace_column 1 - 3 - +select rand(), + cast(rand(10)*@precision as unsigned integer), + cast(rand(a)*@precision as unsigned integer) from t1; +prepare stmt from +"select rand(), + cast(rand(10)*@precision as unsigned integer), + cast(rand(a)*@precision as unsigned integer), + cast(rand(?)*@precision as unsigned integer) from t1"; +set @var=1; +--replace_column 1 - 3 - +execute stmt using @var; +set @var=2; +--replace_column 1 - +execute stmt using @var; +set @var=3; +--replace_column 1 - +execute stmt using @var; +drop table t1; +deallocate prepare stmt; diff --git a/sql/item_func.cc b/sql/item_func.cc index ccdde399e0a..f20d69bf2ad 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1010,21 +1010,38 @@ double Item_func_round::val() } -void Item_func_rand::fix_length_and_dec() +bool Item_func_rand::fix_fields(THD *thd, struct st_table_list *tables, + Item **ref) { - decimals=NOT_FIXED_DEC; - max_length=float_length(decimals); + Item_real_func::fix_fields(thd, tables, ref); used_tables_cache|= RAND_TABLE_BIT; if (arg_count) { // Only use argument once in query - uint32 tmp= (uint32) (args[0]->val_int()); - if ((rand= (struct rand_struct*) sql_alloc(sizeof(*rand)))) - randominit(rand,(uint32) (tmp*0x10001L+55555555L), - (uint32) (tmp*0x10000001L)); + /* + Allocate rand structure once: we must use thd->current_arena + to create rand in proper mem_root if it's a prepared statement or + stored procedure. + */ + if (!rand && !(rand= (struct rand_struct*) + thd->current_arena->alloc(sizeof(*rand)))) + return TRUE; + /* + PARAM_ITEM is returned if we're in statement prepare and consequently + no placeholder value is set yet. + */ + if (args[0]->type() != PARAM_ITEM) + { + /* + TODO: do not do reinit 'rand' for every execute of PS/SP if + args[0] is a constant. + */ + uint32 tmp= (uint32) args[0]->val_int(); + randominit(rand, (uint32) (tmp*0x10001L+55555555L), + (uint32) (tmp*0x10000001L)); + } } else { - THD *thd= current_thd; /* No need to send a Rand log event if seed was given eg: RAND(seed), as it will be replicated in the query as such. @@ -1038,6 +1055,7 @@ void Item_func_rand::fix_length_and_dec() thd->rand_saved_seed2=thd->rand.seed2; rand= &thd->rand; } + return FALSE; } void Item_func_rand::update_used_tables() diff --git a/sql/item_func.h b/sql/item_func.h index 4889ca78a77..e61459cfbd8 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -512,13 +512,13 @@ class Item_func_rand :public Item_real_func { struct rand_struct *rand; public: - Item_func_rand(Item *a) :Item_real_func(a) {} - Item_func_rand() :Item_real_func() {} + Item_func_rand(Item *a) :Item_real_func(a), rand(0) {} + Item_func_rand() :Item_real_func() {} double val(); const char *func_name() const { return "rand"; } bool const_item() const { return 0; } void update_used_tables(); - void fix_length_and_dec(); + bool fix_fields(THD *thd, struct st_table_list *tables, Item **ref); }; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index e152cd9ea49..1a0879c6347 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -447,6 +447,7 @@ bool is_update_query(enum enum_sql_command command); bool alloc_query(THD *thd, char *packet, ulong packet_length); void mysql_init_select(LEX *lex); void mysql_init_query(THD *thd, uchar *buf, uint length); +void mysql_reset_thd_for_next_command(THD *thd); bool mysql_new_select(LEX *lex, bool move_down); void create_select_for_variable(const char *var_name); void mysql_init_multi_delete(LEX *lex); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 4ce655c78f8..f1c75a3b365 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1498,7 +1498,7 @@ void Statement::restore_backup_statement(Statement *stmt, Statement *backup) } -void Statement::end_statement() +void THD::end_statement() { /* Cleanup SQL processing state to resuse this statement in next query. */ lex_end(lex); diff --git a/sql/sql_class.h b/sql/sql_class.h index aaa81fbe165..f25689aa512 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -565,12 +565,6 @@ public: void restore_backup_statement(Statement *stmt, Statement *backup); /* return class type */ virtual Type type() const; - - /* - Cleanup statement parse state (parse tree, lex) after execution of - a non-prepared SQL statement. - */ - void end_statement(); }; @@ -1064,6 +1058,12 @@ public: void nocheck_register_item_tree_change(Item **place, Item *old_value, MEM_ROOT *runtime_memroot); void rollback_item_tree_changes(); + + /* + Cleanup statement parse state (parse tree, lex) and execution + state after execution of a non-prepared SQL statement. + */ + void end_statement(); }; /* Flags for the THD::system_thread (bitmap) variable */ diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 3deecccb4e1..856742d13bc 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -117,7 +117,30 @@ void lex_free(void) void lex_start(THD *thd, uchar *buf,uint length) { LEX *lex= thd->lex; + lex->unit.init_query(); + lex->unit.init_select(); lex->thd= thd; + lex->unit.thd= thd; + lex->select_lex.init_query(); + lex->value_list.empty(); + lex->param_list.empty(); + lex->unit.next= lex->unit.master= + lex->unit.link_next= lex->unit.return_to= 0; + lex->unit.prev= lex->unit.link_prev= 0; + lex->unit.slave= lex->unit.global_parameters= lex->current_select= + lex->all_selects_list= &lex->select_lex; + lex->select_lex.master= &lex->unit; + lex->select_lex.prev= &lex->unit.slave; + lex->select_lex.link_next= lex->select_lex.slave= lex->select_lex.next= 0; + lex->select_lex.link_prev= (st_select_lex_node**)&(lex->all_selects_list); + lex->select_lex.options= 0; + lex->describe= 0; + lex->derived_tables= FALSE; + lex->lock_option= TL_READ; + lex->found_colon= 0; + lex->safe_to_cache_query= 1; + lex->time_zone_tables_used= 0; + lex->select_lex.select_number= 1; lex->next_state=MY_LEX_START; lex->end_of_query=(lex->ptr=buf)+length; lex->yylineno = 1; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index d198855a2d3..38cdde019ff 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -369,7 +369,7 @@ public: ulong init_prepare_fake_select_lex(THD *thd); int change_result(select_subselect *result, select_subselect *old_result); - friend void mysql_init_query(THD *thd, uchar *buf, uint length); + friend void lex_start(THD *thd, uchar *buf, uint length); friend int subselect_union_engine::exec(); private: bool create_total_list_n_last_return(THD *thd, st_lex *lex, @@ -508,7 +508,7 @@ public: bool test_limit(); - friend void mysql_init_query(THD *thd, uchar *buf, uint length); + friend void lex_start(THD *thd, uchar *buf, uint length); st_select_lex() {} void make_empty_select() { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index c5ca19ecba8..c9c4ed35dc7 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1001,16 +1001,15 @@ pthread_handler_decl(handle_one_connection,arg) net->compress=1; // Use compression thd->version= refresh_version; + thd->proc_info= 0; + thd->set_time(); + thd->init_for_queries(); if (sys_init_connect.value_length && !(thd->master_access & SUPER_ACL)) { execute_init_command(thd, &sys_init_connect, &LOCK_sys_init_connect); if (thd->query_error) thd->killed= 1; } - - thd->proc_info=0; - thd->set_time(); - thd->init_for_queries(); while (!net->error && net->vio != 0 && !thd->killed) { if (do_command(thd)) @@ -3854,7 +3853,6 @@ bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize) return 0; } - /**************************************************************************** Initialize global thd variables needed for query ****************************************************************************/ @@ -3863,33 +3861,30 @@ void mysql_init_query(THD *thd, uchar *buf, uint length) { DBUG_ENTER("mysql_init_query"); - LEX *lex= thd->lex; - lex->unit.init_query(); - lex->unit.init_select(); - lex->unit.thd= thd; - lex->select_lex.init_query(); - lex->value_list.empty(); - lex->param_list.empty(); - lex->unit.next= lex->unit.master= - lex->unit.link_next= lex->unit.return_to=0; - lex->unit.prev= lex->unit.link_prev= 0; - lex->unit.slave= lex->unit.global_parameters= lex->current_select= - lex->all_selects_list= &lex->select_lex; - lex->select_lex.master= &lex->unit; - lex->select_lex.prev= &lex->unit.slave; - lex->select_lex.link_next= lex->select_lex.slave= lex->select_lex.next= 0; - lex->select_lex.link_prev= (st_select_lex_node**)&(lex->all_selects_list); - lex->select_lex.options=0; - lex->describe= 0; - lex->derived_tables= FALSE; - lex->lock_option= TL_READ; - lex->found_colon= 0; - lex->safe_to_cache_query= 1; - lex->time_zone_tables_used= 0; lex_start(thd, buf, length); - thd->select_number= lex->select_lex.select_number= 1; - thd->free_list= 0; - thd->total_warn_count=0; // Warnings for this query + mysql_reset_thd_for_next_command(thd); + DBUG_VOID_RETURN; +} + + +/* + Reset THD part responsible for command processing state. + + DESCRIPTION + This needs to be called before execution of every statement + (prepared or conventional). + + TODO + Make it a method of THD and align its name with the rest of + reset/end/start/init methods. + Call it after we use THD for queries, not before. +*/ + +void mysql_reset_thd_for_next_command(THD *thd) +{ + DBUG_ENTER("mysql_reset_thd_for_next_command"); + thd->select_number= 1; + thd->total_warn_count= 0; // Warnings for this query thd->last_insert_id_used= thd->query_start_used= thd->insert_id_used=0; thd->sent_row_count= thd->examined_row_count= 0; thd->is_fatal_error= thd->rand_used= thd->time_zone_used= 0; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index a638e74dc2f..27d98fdfeba 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1760,6 +1760,8 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) DBUG_VOID_RETURN; } + DBUG_ASSERT(thd->free_list == NULL); + mysql_reset_thd_for_next_command(thd); #ifndef EMBEDDED_LIBRARY if (stmt->param_count) { @@ -1778,7 +1780,6 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) if (stmt->param_count && stmt->set_params_data(stmt, &expanded_query)) goto set_params_data_err; #endif - DBUG_ASSERT(thd->free_list == NULL); thd->protocol= &thd->protocol_prep; // Switch to binary protocol execute_stmt(thd, stmt, &expanded_query, true); thd->protocol= &thd->protocol_simple; // Use normal protocol @@ -1823,7 +1824,8 @@ void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name) } DBUG_ASSERT(thd->free_list == NULL); - + /* Must go before setting variables, as it clears thd->user_var_events */ + mysql_reset_thd_for_next_command(thd); thd->set_n_backup_statement(stmt, &thd->stmt_backup); if (stmt->set_params_from_vars(stmt, thd->stmt_backup.lex->prepared_stmt_params, @@ -1932,6 +1934,7 @@ void mysql_stmt_reset(THD *thd, char *packet) */ reset_stmt_params(stmt); + mysql_reset_thd_for_next_command(thd); send_ok(thd); DBUG_VOID_RETURN; From 761ae02ca77722f34744a912315d52a0c0f7fca6 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 Oct 2004 03:37:20 +0400 Subject: [PATCH 07/17] Followup to Bug#5985: fixing one thing that went wrong. --- sql/sql_parse.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index c9c4ed35dc7..e7a013e19ea 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3883,6 +3883,7 @@ mysql_init_query(THD *thd, uchar *buf, uint length) void mysql_reset_thd_for_next_command(THD *thd) { DBUG_ENTER("mysql_reset_thd_for_next_command"); + thd->free_list= 0; thd->select_number= 1; thd->total_warn_count= 0; // Warnings for this query thd->last_insert_id_used= thd->query_start_used= thd->insert_id_used=0; From 81914f489ea2d9b838acdb93318c8d3549e03d55 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 Oct 2004 14:14:50 +0500 Subject: [PATCH 08/17] Bug #6043 erratic searching for diacriticals in indexed MyISAM UTF-8 table --- mysql-test/r/ctype_utf8.result | 29 +++++++++++++++++++++++++++++ mysql-test/t/ctype_utf8.test | 20 ++++++++++++++++++++ sql/field.cc | 12 ++++++------ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 0b98d9432ae..0ed3444581c 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -750,3 +750,32 @@ SELECT id FROM t1 WHERE (list_id = 1) AND (term = "letterd"); id 4 DROP TABLE t1; +SET NAMES latin1; +CREATE TABLE t1 ( +id int unsigned NOT NULL auto_increment, +list_id smallint unsigned NOT NULL, +term text NOT NULL, +PRIMARY KEY(id), +INDEX(list_id, term(19)) +) TYPE=MyISAM CHARSET=utf8; +Warnings: +Warning 1287 'TYPE=storage_engine' is deprecated; use 'ENGINE=storage_engine' instead +INSERT INTO t1 set list_id = 1, term = "testtest"; +INSERT INTO t1 set list_id = 1, term = "testetest"; +INSERT INTO t1 set list_id = 1, term = "testtest"; +SELECT id, term FROM t1 where (list_id = 1) AND (term = "testtest"); +id term +1 testtest +2 testetest +3 testtest +SELECT id, term FROM t1 where (list_id = 1) AND (term = "testetest"); +id term +1 testtest +2 testetest +3 testtest +SELECT id, term FROM t1 where (list_id = 1) AND (term = "testtest"); +id term +1 testtest +2 testetest +3 testtest +DROP TABLE t1; diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 4a8eb63ed36..36aeec7145e 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -592,3 +592,23 @@ SELECT id FROM t1 WHERE (list_id = 1) AND (term = "letterb"); SELECT id FROM t1 WHERE (list_id = 1) AND (term = "lettera"); SELECT id FROM t1 WHERE (list_id = 1) AND (term = "letterd"); DROP TABLE t1; + + +# +# Bug #6043 erratic searching for diacriticals in indexed MyISAM UTF-8 table +# +SET NAMES latin1; +CREATE TABLE t1 ( + id int unsigned NOT NULL auto_increment, + list_id smallint unsigned NOT NULL, + term text NOT NULL, + PRIMARY KEY(id), + INDEX(list_id, term(19)) +) TYPE=MyISAM CHARSET=utf8; +INSERT INTO t1 set list_id = 1, term = "testtest"; +INSERT INTO t1 set list_id = 1, term = "testetest"; +INSERT INTO t1 set list_id = 1, term = "testtest"; +SELECT id, term FROM t1 where (list_id = 1) AND (term = "testtest"); +SELECT id, term FROM t1 where (list_id = 1) AND (term = "testetest"); +SELECT id, term FROM t1 where (list_id = 1) AND (term = "testtest"); +DROP TABLE t1; diff --git a/sql/field.cc b/sql/field.cc index ec3bd72878d..3dc1375dff3 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5000,10 +5000,10 @@ String *Field_blob::val_str(String *val_buffer __attribute__((unused)), int Field_blob::cmp(const char *a,uint32 a_length, const char *b, uint32 b_length) { - int diff=my_strnncoll(field_charset, - (const uchar*)a,min(a_length,b_length), - (const uchar*)b,min(a_length,b_length)); - return diff ? diff : (int) (a_length - b_length); + return field_charset->coll->strnncoll(field_charset, + (const uchar*)a, a_length, + (const uchar*)b, b_length, + 0); } @@ -5087,8 +5087,8 @@ void Field_blob::get_key_image(char *buff,uint length, get_ptr(&blob); uint char_length= length / cs->mbmaxlen; - char_length= my_charpos(cs, blob, blob + length, char_length); - set_if_smaller(length, char_length); + char_length= my_charpos(cs, blob, blob + blob_length, char_length); + set_if_smaller(blob_length, char_length); if ((uint32) length > blob_length) { From a5484c0c6fc7692621e495a4a2c87798941c1309 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 Oct 2004 15:29:07 +0500 Subject: [PATCH 09/17] ctype_utf8.test: Bug#6086 "ctype_utf8" test fails when MySQL does not include InnoDB support mysql-test/t/ctype_utf8.test: Bug#6086 "ctype_utf8" test fails when MySQL does not include InnoDB support --- mysql-test/t/ctype_utf8.test | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 36aeec7145e..ae8db92e3f9 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -221,7 +221,9 @@ drop table t1; # Bug 4521: unique key prefix interacts poorly with utf8 # InnoDB: keys with prefix compression, case insensitive collation. # +--disable_warnings create table t1 (c varchar(30) character set utf8, unique(c(10))) engine=innodb; +--enable_warnings insert into t1 values ('1'),('2'),('3'),('x'),('y'),('z'); insert into t1 values ('aaaaaaaaaa'); --error 1062 @@ -269,7 +271,9 @@ drop table t1; # Bug 4521: unique key prefix interacts poorly with utf8 # InnoDB: fixed length keys, case insensitive collation # +--disable_warnings create table t1 (c char(3) character set utf8, unique (c(2))) engine=innodb; +--enable_warnings insert into t1 values ('1'),('2'),('3'),('4'),('x'),('y'),('z'); insert into t1 values ('a'); insert into t1 values ('aa'); @@ -504,10 +508,12 @@ drop table t1; # Bug#4594: column index make = failed for gbk, but like works # Check InnoDB # +--disable_warnings create table t1 ( str varchar(255) character set utf8 not null, key str (str(2)) ) engine=innodb; +--enable_warnings INSERT INTO t1 VALUES ('str'); INSERT INTO t1 VALUES ('str2'); select * from t1 where str='str'; @@ -563,10 +569,12 @@ DROP TABLE t1; # Bug #5723: length() returns varying results # SET NAMES utf8; +--disable_warnings CREATE TABLE t1 ( subject varchar(255) character set utf8 collate utf8_unicode_ci, p varchar(15) character set utf8 ) ENGINE=InnoDB DEFAULT CHARSET=latin1; +--enable_warnings INSERT INTO t1 VALUES ('谷川俊二と申しますが、インターネット予約の会員登録をしましたところ、メールアドレスを間違えてしまい会員IDが受け取ることが出来ませんでした。間違えアドレスはtani-shun@n.vodafone.ne.jpを書き込みました。どうすればよいですか? その他、住所等は間違えありません。連絡ください。よろしくお願いします。m(__)m','040312-000057'); INSERT INTO t1 VALUES ('aaa','bbb'); SELECT length(subject) FROM t1; From ae0acc8472b23729396cc1ad6b4a904680e1f0ac Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 Oct 2004 16:36:29 +0500 Subject: [PATCH 10/17] Bug #6019 SELECT tries to use too short prefix index on utf8 data --- mysql-test/r/ctype_utf8.result | 11 +++++++++++ mysql-test/t/ctype_utf8.test | 15 +++++++++++++++ strings/ctype-mb.c | 4 ++++ strings/ctype-utf8.c | 4 ++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 0ed3444581c..e52b6f9a609 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -779,3 +779,14 @@ id term 2 testetest 3 testtest DROP TABLE t1; +set names utf8; +create table t1 ( +a int primary key, +b varchar(6), +index b3(b(3)) +) engine=myisam character set=utf8; +insert into t1 values(1,'foo'),(2,'foobar'); +select * from t1 where b like 'foob%'; +a b +2 foobar +drop table t1; diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index ae8db92e3f9..0da52054aac 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -620,3 +620,18 @@ SELECT id, term FROM t1 where (list_id = 1) AND (term = "test SELECT id, term FROM t1 where (list_id = 1) AND (term = "testetest"); SELECT id, term FROM t1 where (list_id = 1) AND (term = "testtest"); DROP TABLE t1; + +# +# Bug #6019 SELECT tries to use too short prefix index on utf8 data +# +set names utf8; +--disable_warnings +create table t1 ( + a int primary key, + b varchar(6), + index b3(b(3)) +) engine=myisam character set=utf8; +--enable_warnings +insert into t1 values(1,'foo'),(2,'foobar'); +select * from t1 where b like 'foob%'; +drop table t1; diff --git a/strings/ctype-mb.c b/strings/ctype-mb.c index 3bfc66029ce..a41449d5e50 100644 --- a/strings/ctype-mb.c +++ b/strings/ctype-mb.c @@ -499,6 +499,10 @@ my_bool my_like_range_mb(CHARSET_INFO *cs, { char buf[10]; uint buflen; + uint charlen= my_charpos(cs, min_org, min_str, res_length/cs->mbmaxlen); + + if (charlen < (uint) (min_str - min_org)) + min_str= min_org + charlen; /* Write min key */ *min_length= (uint) (min_str - min_org); diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c index 62e97d51328..fd6610b72b1 100644 --- a/strings/ctype-utf8.c +++ b/strings/ctype-utf8.c @@ -2059,7 +2059,7 @@ static MY_COLLATION_HANDLER my_collation_ci_handler = my_strnncoll_utf8, my_strnncollsp_utf8, my_strnxfrm_utf8, - my_like_range_simple, + my_like_range_mb, my_wildcmp_mb, my_strcasecmp_utf8, my_instr_mb, @@ -2119,7 +2119,7 @@ CHARSET_INFO my_charset_utf8_general_ci= 1, /* mbminlen */ 3, /* mbmaxlen */ 0, /* min_sort_char */ - 255, /* max_sort_char */ + 0xFFFF, /* max_sort_char */ &my_charset_utf8_handler, &my_collation_ci_handler }; From 3329f3161b7df73efe741ac83b7e88db895d0211 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 Oct 2004 16:40:03 +0500 Subject: [PATCH 11/17] ctype_utf8.test, ctype_utf8.result: Wrong handler. mysql-test/r/ctype_utf8.result: Wrong handler. mysql-test/t/ctype_utf8.test: Wrong handler. --- mysql-test/r/ctype_utf8.result | 2 +- mysql-test/t/ctype_utf8.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index e52b6f9a609..2e8bbc8fa92 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -784,7 +784,7 @@ create table t1 ( a int primary key, b varchar(6), index b3(b(3)) -) engine=myisam character set=utf8; +) engine=innodb character set=utf8; insert into t1 values(1,'foo'),(2,'foobar'); select * from t1 where b like 'foob%'; a b diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 0da52054aac..fc6eb88ad68 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -630,7 +630,7 @@ create table t1 ( a int primary key, b varchar(6), index b3(b(3)) -) engine=myisam character set=utf8; +) engine=innodb character set=utf8; --enable_warnings insert into t1 values(1,'foo'),(2,'foobar'); select * from t1 where b like 'foob%'; From 9689d9562b05172d22ea2f9ed234efeb2c30e84b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 Oct 2004 14:54:06 +0200 Subject: [PATCH 12/17] - added missing file strings/my_strtoll10.c to the libmysql.dsp and mysqlclient.dsp project files VC++Files/client/mysqlclient.dsp: - added missing file strings/my_strtoll10.c to the mysqlclient.dsp project file VC++Files/libmysql/libmysql.dsp: - added missing file strings/my_strtoll10.c to the libmysql.dsp project file --- VC++Files/client/mysqlclient.dsp | 4 ++++ VC++Files/libmysql/libmysql.dsp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/VC++Files/client/mysqlclient.dsp b/VC++Files/client/mysqlclient.dsp index 4de32e447d3..75008858e55 100644 --- a/VC++Files/client/mysqlclient.dsp +++ b/VC++Files/client/mysqlclient.dsp @@ -423,6 +423,10 @@ SOURCE=..\mysys\my_static.c # End Source File # Begin Source File +SOURCE=..\strings\my_strtoll10.c +# End Source File +# Begin Source File + SOURCE=..\mysys\my_symlink.c # End Source File # Begin Source File diff --git a/VC++Files/libmysql/libmysql.dsp b/VC++Files/libmysql/libmysql.dsp index f382f36cb85..ce81a3b7435 100644 --- a/VC++Files/libmysql/libmysql.dsp +++ b/VC++Files/libmysql/libmysql.dsp @@ -383,6 +383,10 @@ SOURCE=..\mysys\my_static.c # End Source File # Begin Source File +SOURCE=..\strings\my_strtoll10.c +# End Source File +# Begin Source File + SOURCE=..\mysys\my_symlink.c # End Source File # Begin Source File From f35377c6cc441bbf11a9d830bb26414d0bc21f8b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 Oct 2004 16:52:00 +0200 Subject: [PATCH 13/17] - Cleanup: removed unreferenced local variable "local_file" in mysqlimport.c client/mysqlimport.c: - Cleanup: removed unreferenced local variable "local_file" --- client/mysqlimport.c | 1 - 1 file changed, 1 deletion(-) diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 447410fa947..fae84be610a 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -264,7 +264,6 @@ static int write_to_table(char *filename, MYSQL *sock) { char tablename[FN_REFLEN], hard_path[FN_REFLEN], sql_statement[FN_REFLEN*16+256], *end; - my_bool local_file; DBUG_ENTER("write_to_table"); DBUG_PRINT("enter",("filename: %s",filename)); From feb23bf9fe6f49b24e297814f8d158cb0767a4e0 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Oct 2004 00:36:45 +0400 Subject: [PATCH 14/17] compile-hpux11-parisc2-aCC: Fix a typo. Cleanup. BUILD/compile-hpux11-parisc2-aCC: Fix a typo. Cleanup. --- BUILD/compile-hpux11-parisc2-aCC | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/BUILD/compile-hpux11-parisc2-aCC b/BUILD/compile-hpux11-parisc2-aCC index 1bdef94e080..2fc7a6d2b6e 100755 --- a/BUILD/compile-hpux11-parisc2-aCC +++ b/BUILD/compile-hpux11-parisc2-aCC @@ -20,7 +20,7 @@ release_flags="-fast +O3" # note on pointers below. cflags="-g -z +O0" cxxflags="-g0 -z +O0" -debug_conigure_options="--with-debug" +debug_configure_options="--with-debug" while [ "$#" != 0 ]; do case "$1" in @@ -40,23 +40,23 @@ while [ "$#" != 0 ]; do --release) echo "Building release binary" cflags="$release_flags" - cxxflags="$release_flags" - debug_configure_options="" + cxxflags="$release_flags" + debug_configure_options="" ;; - -32) - echo "Building 32-bit binary" - ;; - -64) - echo "Building 64-bit binary" + -32) + echo "Building 32-bit binary" + ;; + -64) + echo "Building 64-bit binary" cflags="$cflags +DA2.0W +DD64" cxxflags="$cxxflags +DA2.0W +DD64" - ;; + ;; *) echo "$0: invalid option '$1'; use --help to show usage" exit 1 ;; esac - shift + shift done From e8bc4e16e079377de4f6f513ddfe017a3d095926 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Oct 2004 02:52:52 +0400 Subject: [PATCH 15/17] libmysql/libmysql.c: Fix for Bug#6025 "Test "client_test" fails in 4.1.6-gamma build (2)". No need for a test case, the bug is covered already. libmysql/libmysql.c: Fix for Bug#6025 "Test "client_test" fails in 4.1.6-gamma build (2)": the bug was in assignments like: *row+= read_binary_time(tm, row); which makes two assingments without a sequence point (read_binary_* changes *row too) => undefined behaviour. The fix changes read_binary_{time,date,datetime} signature to get rid of any probability to fall into the same trouble in future. --- libmysql/libmysql.c | 78 +++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 2ad6771cc69..b8e53cf92bb 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -3196,24 +3196,20 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, read_binary_{date,time,datetime}() tm MYSQL_TIME structure to fill pos pointer to current position in network buffer. - These functions increase pos to point to the beginning of this - field (this is just due to implementation of net_field_length - which is used to get length of binary representation of - time value). + These functions increase pos to point to the beginning of the + next column. Auxiliary functions to read time (date, datetime) values from network buffer and store in MYSQL_TIME structure. Jointly used by conversion and no-conversion fetching. */ -static uint read_binary_time(MYSQL_TIME *tm, uchar **pos) +static void read_binary_time(MYSQL_TIME *tm, uchar **pos) { - uint length; - /* net_field_length will set pos to the first byte of data */ - if (!(length= net_field_length(pos))) - set_zero_time(tm); - else + uint length= net_field_length(pos); + + if (length) { uchar *to= *pos; tm->neg= (bool) to[0]; @@ -3226,17 +3222,18 @@ static uint read_binary_time(MYSQL_TIME *tm, uchar **pos) tm->year= tm->month= 0; tm->time_type= MYSQL_TIMESTAMP_TIME; + + *pos+= length; } - return length; + else + set_zero_time(tm); } -static uint read_binary_datetime(MYSQL_TIME *tm, uchar **pos) +static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos) { - uint length; + uint length= net_field_length(pos); - if (!(length= net_field_length(pos))) - set_zero_time(tm); - else + if (length) { uchar *to= *pos; @@ -3255,17 +3252,18 @@ static uint read_binary_datetime(MYSQL_TIME *tm, uchar **pos) tm->hour= tm->minute= tm->second= 0; tm->second_part= (length > 7) ? (ulong) sint4korr(to+7) : 0; tm->time_type= MYSQL_TIMESTAMP_DATETIME; + + *pos+= length; } - return length; + else + set_zero_time(tm); } -static uint read_binary_date(MYSQL_TIME *tm, uchar **pos) +static void read_binary_date(MYSQL_TIME *tm, uchar **pos) { - uint length; + uint length= net_field_length(pos); - if (!(length= net_field_length(pos))) - set_zero_time(tm); - else + if (length) { uchar *to= *pos; tm->year = (uint) sint2korr(to); @@ -3276,8 +3274,11 @@ static uint read_binary_date(MYSQL_TIME *tm, uchar **pos) tm->second_part= 0; tm->neg= 0; tm->time_type= MYSQL_TIMESTAMP_DATE; + + *pos+= length; } - return length; + else + set_zero_time(tm); } @@ -3604,7 +3605,6 @@ static void fetch_datetime_with_conversion(MYSQL_BIND *param, static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, uchar **row) { - ulong length; enum enum_field_types field_type= field->type; uint field_is_unsigned= field->flags & UNSIGNED_FLAG; @@ -3615,7 +3615,7 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, longlong data= field_is_unsigned ? (longlong) (unsigned char) value : (longlong) value; fetch_long_with_conversion(param, field, data); - length= 1; + *row+= 1; break; } case MYSQL_TYPE_SHORT: @@ -3625,7 +3625,7 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, longlong data= field_is_unsigned ? (longlong) (unsigned short) value : (longlong) value; fetch_long_with_conversion(param, field, data); - length= 2; + *row+= 2; break; } case MYSQL_TYPE_INT24: /* mediumint is sent as 4 bytes int */ @@ -3635,14 +3635,14 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, longlong data= field_is_unsigned ? (longlong) (unsigned long) value : (longlong) value; fetch_long_with_conversion(param, field, data); - length= 4; + *row+= 4; break; } case MYSQL_TYPE_LONGLONG: { longlong value= (longlong)sint8korr(*row); fetch_long_with_conversion(param, field, value); - length= 8; + *row+= 8; break; } case MYSQL_TYPE_FLOAT: @@ -3650,7 +3650,7 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, float value; float4get(value,*row); fetch_float_with_conversion(param, field, value, FLT_DIG); - length= 4; + *row+= 4; break; } case MYSQL_TYPE_DOUBLE: @@ -3658,14 +3658,14 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, double value; float8get(value,*row); fetch_float_with_conversion(param, field, value, DBL_DIG); - length= 8; + *row+= 8; break; } case MYSQL_TYPE_DATE: { MYSQL_TIME tm; - length= read_binary_date(&tm, row); + read_binary_date(&tm, row); fetch_datetime_with_conversion(param, &tm); break; } @@ -3673,7 +3673,7 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, { MYSQL_TIME tm; - length= read_binary_time(&tm, row); + read_binary_time(&tm, row); fetch_datetime_with_conversion(param, &tm); break; } @@ -3682,16 +3682,18 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, { MYSQL_TIME tm; - length= read_binary_datetime(&tm, row); + read_binary_datetime(&tm, row); fetch_datetime_with_conversion(param, &tm); break; } default: - length= net_field_length(row); + { + ulong length= net_field_length(row); fetch_string_with_conversion(param, (char*) *row, length); + *row+= length; break; } - *row+= length; + } } @@ -3760,19 +3762,19 @@ static void fetch_result_double(MYSQL_BIND *param, uchar **row) static void fetch_result_time(MYSQL_BIND *param, uchar **row) { MYSQL_TIME *tm= (MYSQL_TIME *)param->buffer; - *row+= read_binary_time(tm, row); + read_binary_time(tm, row); } static void fetch_result_date(MYSQL_BIND *param, uchar **row) { MYSQL_TIME *tm= (MYSQL_TIME *)param->buffer; - *row+= read_binary_date(tm, row); + read_binary_date(tm, row); } static void fetch_result_datetime(MYSQL_BIND *param, uchar **row) { MYSQL_TIME *tm= (MYSQL_TIME *)param->buffer; - *row+= read_binary_datetime(tm, row); + read_binary_datetime(tm, row); } static void fetch_result_bin(MYSQL_BIND *param, uchar **row) From 77d7398e0b0b6461852658fcf9fb98b6a444ae94 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Oct 2004 03:54:40 +0400 Subject: [PATCH 16/17] Fix for Bug#6024 "Test "client_test" fails in 4.1.6-gamma build (1)": let's not assume that char is signed (its signedness is not defined). The server was also affected by the wrong typedef. include/my_global.h: Fix for Bug#6024 "Test "client_test" fails in 4.1.6-gamma build (1)": let's not assume that char is signed (its signedness is not defined). libmysql/libmysql.c: Fix for Bug#6024 "Test "client_test" fails in 4.1.6-gamma build (1)": let's not assume that char is signed (its signedness is not defined). --- include/my_global.h | 2 +- libmysql/libmysql.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/my_global.h b/include/my_global.h index 8e2e8e0eb6a..f6200830ee3 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -713,7 +713,7 @@ typedef void *gptr; /* Generic pointer */ typedef char *gptr; /* Generic pointer */ #endif #ifndef HAVE_INT_8_16_32 -typedef char int8; /* Signed integer >= 8 bits */ +typedef signed char int8; /* Signed integer >= 8 bits */ typedef short int16; /* Signed integer >= 16 bits */ #endif #ifndef HAVE_UCHAR diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index b8e53cf92bb..ef926e2f93d 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -3611,9 +3611,10 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, switch (field_type) { case MYSQL_TYPE_TINY: { - char value= (char) **row; - longlong data= field_is_unsigned ? (longlong) (unsigned char) value : - (longlong) value; + uchar value= **row; + /* sic: we need to cast to 'signed char' as 'char' may be unsigned */ + longlong data= field_is_unsigned ? (longlong) value : + (longlong) (signed char) value; fetch_long_with_conversion(param, field, data); *row+= 1; break; From fc759666047785f44392ca7790a17715484f34dd Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Oct 2004 00:55:50 -0500 Subject: [PATCH 17/17] TAG: Tagged ChangeSet 1.2091 as mysql-4.1.6 configure.in: Updated version string to 4.1.7 configure.in: Updated version string to 4.1.7 --- configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.in b/configure.in index d81a50b9367..b06fc35b23f 100644 --- a/configure.in +++ b/configure.in @@ -4,7 +4,7 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(sql/mysqld.cc) AC_CANONICAL_SYSTEM # The Docs Makefile.am parses this line! -AM_INIT_AUTOMAKE(mysql, 4.1.6-gamma) +AM_INIT_AUTOMAKE(mysql, 4.1.7-gamma) AM_CONFIG_HEADER(config.h) PROTOCOL_VERSION=10