diff options
author | unknown <monty@mysql.com> | 2005-01-03 13:57:17 +0200 |
---|---|---|
committer | unknown <monty@mysql.com> | 2005-01-03 13:57:17 +0200 |
commit | 79e05c83174783adb6cf89b2a2f3e9794637a2bb (patch) | |
tree | 04ac34f3b015421f37bef52c7bdf6d8ed5b0dafc | |
parent | 2c6636b56ae2fc01500b8860bb9b6b811f6a4e29 (diff) | |
parent | e055be6658fff00587999a1aab7dae522ba99cfc (diff) | |
download | mariadb-git-79e05c83174783adb6cf89b2a2f3e9794637a2bb.tar.gz |
Merge bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/home/my/mysql-5.0
-rw-r--r-- | mysql-test/r/func_str.result | 9 | ||||
-rw-r--r-- | mysql-test/t/func_str.test | 3 | ||||
-rw-r--r-- | mysql-test/t/trigger.test | 2 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 76 | ||||
-rw-r--r-- | sql/sql_base.cc | 1 | ||||
-rw-r--r-- | sql/sql_insert.cc | 2 | ||||
-rw-r--r-- | sql/sql_parse.cc | 3 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 14 | ||||
-rw-r--r-- | sql/table.cc | 20 | ||||
-rw-r--r-- | sql/table.h | 1 | ||||
-rw-r--r-- | tests/client_test.c | 50 |
11 files changed, 101 insertions, 80 deletions
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 530651e63f8..2399099b478 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -48,6 +48,9 @@ tcx.se .se select concat(':',ltrim(' left '),':',rtrim(' right '),':'); concat(':',ltrim(' left '),':',rtrim(' right '),':') :left : right: +select concat(':',trim(leading from ' left '),':',trim(trailing from ' right '),':'); +concat(':',trim(leading from ' left '),':',trim(trailing from ' right '),':') +:left : right: select concat(':',trim(LEADING FROM ' left'),':',trim(TRAILING FROM ' right '),':'); concat(':',trim(LEADING FROM ' left'),':',trim(TRAILING FROM ' right '),':') :left: right: @@ -703,3 +706,9 @@ NULL select trim('xyz' from null) as "must_be_null"; must_be_null NULL +select trim(leading NULL from 'kate') as "must_be_null"; +must_be_null +NULL +select trim(trailing NULL from 'xyz') as "must_be_null"; +must_be_null +NULL diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index a5d95332caa..4a1b8470ada 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -25,6 +25,7 @@ select substring_index('www.tcx.se','tcx',1),substring_index('www.tcx.se','tcx', select substring_index('.tcx.se','.',-2),substring_index('.tcx.se','.tcx',-1); select concat(':',ltrim(' left '),':',rtrim(' right '),':'); +select concat(':',trim(leading from ' left '),':',trim(trailing from ' right '),':'); select concat(':',trim(LEADING FROM ' left'),':',trim(TRAILING FROM ' right '),':'); select concat(':',trim(' m '),':',trim(BOTH FROM ' y '),':',trim('*' FROM '*s*'),':'); select concat(':',trim(BOTH 'ab' FROM 'ababmyabab'),':',trim(BOTH '*' FROM '***sql'),':'); @@ -443,3 +444,5 @@ select quote(trim(concat(' ', 'a'))); # select trim(null from 'kate') as "must_be_null"; select trim('xyz' from null) as "must_be_null"; +select trim(leading NULL from 'kate') as "must_be_null"; +select trim(trailing NULL from 'xyz') as "must_be_null"; diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index d4879b22bae..3900e59c2ee 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -53,6 +53,7 @@ select @a; drop trigger t1.trg; drop table t1; +--disable_ps_protocol # Before update trigger # (In future we will achieve this via proper error handling in triggers) create table t1 (aid int not null primary key, balance int not null default 0); @@ -74,6 +75,7 @@ select * from t1| drop trigger t1.trg| drop table t1| delimiter ;| +--enable_ps_protocol # After update trigger create table t1 (i int); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 88f32067c6c..3c4ffd3e4f3 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1185,21 +1185,29 @@ String *Item_func_substr_index::val_str(String *str) String *Item_func_ltrim::val_str(String *str) { DBUG_ASSERT(fixed == 1); - String *res =args[0]->val_str(str); - if ((null_value=args[0]->null_value)) - return 0; /* purecov: inspected */ - char buff[MAX_FIELD_WIDTH]; - String tmp(buff,sizeof(buff),res->charset()); - String *remove_str= (arg_count==2) ? args[1]->val_str(&tmp) : &remove; + char buff[MAX_FIELD_WIDTH], *ptr, *end; + String tmp(buff,sizeof(buff),system_charset_info); + String *res, *remove_str; uint remove_length; LINT_INIT(remove_length); - if (!remove_str || (remove_length=remove_str->length()) == 0 || + res= args[0]->val_str(str); + if ((null_value=args[0]->null_value)) + return 0; + remove_str= &remove; /* Default value. */ + if (arg_count == 2) + { + remove_str= args[1]->val_str(&tmp); + if ((null_value= args[1]->null_value)) + return 0; + } + + if ((remove_length= remove_str->length()) == 0 || remove_length > res->length()) return res; - char *ptr=(char*) res->ptr(); - char *end=ptr+res->length(); + ptr= (char*) res->ptr(); + end= ptr+res->length(); if (remove_length == 1) { char chr=(*remove_str)[0]; @@ -1224,21 +1232,29 @@ String *Item_func_ltrim::val_str(String *str) String *Item_func_rtrim::val_str(String *str) { DBUG_ASSERT(fixed == 1); - String *res =args[0]->val_str(str); - if ((null_value=args[0]->null_value)) - return 0; /* purecov: inspected */ - char buff[MAX_FIELD_WIDTH]; - String tmp(buff,sizeof(buff),res->charset()); - String *remove_str= (arg_count==2) ? args[1]->val_str(&tmp) : &remove; + char buff[MAX_FIELD_WIDTH], *ptr, *end; + String tmp(buff, sizeof(buff), system_charset_info); + String *res, *remove_str; uint remove_length; LINT_INIT(remove_length); - if (!remove_str || (remove_length=remove_str->length()) == 0 || + res= args[0]->val_str(str); + if ((null_value=args[0]->null_value)) + return 0; + remove_str= &remove; /* Default value. */ + if (arg_count == 2) + { + remove_str= args[1]->val_str(&tmp); + if ((null_value= args[1]->null_value)) + return 0; + } + + if ((remove_length= remove_str->length()) == 0 || remove_length > res->length()) return res; - char *ptr=(char*) res->ptr(); - char *end=ptr+res->length(); + ptr= (char*) res->ptr(); + end= ptr+res->length(); #ifdef USE_MB char *p=ptr; register uint32 l; @@ -1297,31 +1313,31 @@ String *Item_func_rtrim::val_str(String *str) String *Item_func_trim::val_str(String *str) { DBUG_ASSERT(fixed == 1); - String *res =args[0]->val_str(str); - if ((null_value=args[0]->null_value)) - return 0; /* purecov: inspected */ - char buff[MAX_FIELD_WIDTH]; - String tmp(buff,sizeof(buff),res->charset()); + char buff[MAX_FIELD_WIDTH], *ptr, *end; + const char *r_ptr; + String tmp(buff, sizeof(buff), system_charset_info); + String *res, *remove_str; uint remove_length; LINT_INIT(remove_length); - String *remove_str; /* The string to remove from res. */ + res= args[0]->val_str(str); + if ((null_value=args[0]->null_value)) + return 0; + remove_str= &remove; /* Default value. */ if (arg_count == 2) { remove_str= args[1]->val_str(&tmp); if ((null_value= args[1]->null_value)) return 0; } - else - remove_str= &remove; /* Default value. */ - if (!remove_str || (remove_length=remove_str->length()) == 0 || + if ((remove_length= remove_str->length()) == 0 || remove_length > res->length()) return res; - char *ptr=(char*) res->ptr(); - char *end=ptr+res->length(); - const char *r_ptr=remove_str->ptr(); + ptr= (char*) res->ptr(); + end= ptr+res->length(); + r_ptr= remove_str->ptr(); while (ptr+remove_length <= end && !memcmp(ptr,r_ptr,remove_length)) ptr+=remove_length; #ifdef USE_MB diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 950f6c7125d..4d34ce425b1 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1069,6 +1069,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, table->outer_join= table->null_row= table->maybe_null= table->force_index= 0; table->status=STATUS_NO_RECORD; table->keys_in_use_for_query= table->keys_in_use; + table->insert_values= 0; table->used_keys= table->keys_for_keyread; if (table->timestamp_field) table->timestamp_field_type= table->timestamp_field->get_auto_set_type(); diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 7a271daa862..41cc6ebf101 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -501,7 +501,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, ::send_ok(thd, (ulong) thd->row_count_func, id, buff); } free_underlaid_joins(thd, &thd->lex->select_lex); - table_list->clear_insert_values(); thd->abort_on_warning= 0; DBUG_RETURN(FALSE); @@ -511,7 +510,6 @@ abort: end_delayed_insert(thd); #endif free_underlaid_joins(thd, &thd->lex->select_lex); - table_list->clear_insert_values(); thd->abort_on_warning= 0; DBUG_RETURN(TRUE); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 1e03af7626c..096d6fa8e45 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3009,9 +3009,6 @@ create_error: lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE; delete result; } - /* in case of error first_table->table can be 0 */ - if (first_table->table) - first_table->table->insert_values= 0; /* revert changes for SP */ lex->select_lex.table_list.first= (byte*) first_table; } diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 92d92b73813..0a35b2dda8a 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -908,7 +908,11 @@ static bool mysql_test_insert(Prepared_statement *stmt, Item *unused_conds= 0; if (table_list->table) - table_list->table->insert_values=(byte *)1; // don't allocate insert_values + { + // don't allocate insert_values + table_list->table->insert_values=(byte *)1; + } + if ((res= mysql_prepare_insert(thd, table_list, table_list->table, fields, values, update_fields, update_values, duplic, @@ -934,8 +938,7 @@ static bool mysql_test_insert(Prepared_statement *stmt, res= 0; error: lex->unit.cleanup(); - if (table_list->table) - table_list->table->insert_values=0; + /* insert_values is cleared in open_table */ DBUG_RETURN(res); } @@ -1401,6 +1404,11 @@ static int mysql_test_insert_select(Prepared_statement *stmt, DBUG_ASSERT(first_local_table != 0); /* Skip first table, which is the table we are inserting in */ lex->select_lex.table_list.first= (byte*) first_local_table->next_local; + if (tables->table) + { + // don't allocate insert_values + tables->table->insert_values=(byte *)1; + } /* insert/replace from SELECT give its SELECT_LEX for SELECT, diff --git a/sql/table.cc b/sql/table.cc index ee204347b88..e9b89d6b124 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -2026,26 +2026,6 @@ bool st_table_list::set_insert_values(MEM_ROOT *mem_root) } -/* - clear insert_values reference - - SYNOPSIS - clear_insert_values() -*/ - -void st_table_list::clear_insert_values() -{ - if (table) - table->insert_values= 0; - else - { - DBUG_ASSERT(view && ancestor && ancestor->next_local); - for (TABLE_LIST *tbl= ancestor; tbl; tbl= tbl->next_local) - tbl->clear_insert_values(); - } -} - - void Field_iterator_view::set(TABLE_LIST *table) { ptr= table->field_translation; diff --git a/sql/table.h b/sql/table.h index 4f01751ea76..404ca762615 100644 --- a/sql/table.h +++ b/sql/table.h @@ -387,7 +387,6 @@ typedef struct st_table_list void restore_want_privilege(); bool check_single_table(st_table_list **table, table_map map); bool set_insert_values(MEM_ROOT *mem_root); - void clear_insert_values(); } TABLE_LIST; class Item; diff --git a/tests/client_test.c b/tests/client_test.c index 8dc0ec5ca84..d815a9abb3e 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -734,8 +734,8 @@ static void verify_st_affected_rows(MYSQL_STMT *stmt, ulonglong exp_count) { ulonglong affected_rows= mysql_stmt_affected_rows(stmt); if (!opt_silent) - fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", - affected_rows, exp_count); + fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)", + (long) affected_rows, (long) exp_count); DIE_UNLESS(affected_rows == exp_count); } @@ -746,8 +746,8 @@ static void verify_affected_rows(ulonglong exp_count) { ulonglong affected_rows= mysql_affected_rows(mysql); if (!opt_silent) - fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", - affected_rows, exp_count); + fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)", + (long) affected_rows, (long) exp_count); DIE_UNLESS(affected_rows == exp_count); } @@ -780,8 +780,8 @@ static void execute_prepare_query(const char *query, ulonglong exp_count) affected_rows= mysql_stmt_affected_rows(stmt); if (!opt_silent) - fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", - affected_rows, exp_count); + fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)", + (long) affected_rows, (long) exp_count); DIE_UNLESS(affected_rows == exp_count); mysql_stmt_close(stmt); @@ -1017,7 +1017,8 @@ my_bool fetch_n(const char **query_list, unsigned query_count) fprintf(stderr, "Got error reading rows from statement %d,\n" "query is: %s,\n" - "error message: %s", fetch - fetch_array, fetch->query, + "error message: %s", (int) (fetch - fetch_array), + fetch->query, mysql_stmt_error(fetch->handle)); error_count++; } @@ -1479,6 +1480,7 @@ static void test_prepare() double double_data, o_double_data; ulong length[7], len; my_bool is_null[7]; + char llbuf[22]; MYSQL_BIND bind[7]; myheader("test_prepare"); @@ -1596,7 +1598,8 @@ static void test_prepare() fprintf(stdout, "\n\t tiny : %d (%lu)", tiny_data, length[0]); fprintf(stdout, "\n\t short : %d (%lu)", small_data, length[3]); fprintf(stdout, "\n\t int : %d (%lu)", int_data, length[2]); - fprintf(stdout, "\n\t big : %lld (%lu)", big_data, length[4]); + fprintf(stdout, "\n\t big : %s (%lu)", llstr(big_data, llbuf), + length[4]); fprintf(stdout, "\n\t float : %f (%lu)", real_data, length[5]); fprintf(stdout, "\n\t double : %f (%lu)", double_data, length[6]); @@ -3446,7 +3449,7 @@ static void test_bind_result_ext() MYSQL_BIND bind[8]; ulong length[8]; my_bool is_null[8]; - + char llbuf[22]; myheader("test_bind_result_ext"); rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_result"); @@ -3520,7 +3523,7 @@ static void test_bind_result_ext() fprintf(stdout, "\n data (tiny) : %d", t_data); fprintf(stdout, "\n data (short) : %d", s_data); fprintf(stdout, "\n data (int) : %d", i_data); - fprintf(stdout, "\n data (big) : %lld", b_data); + fprintf(stdout, "\n data (big) : %s", llstr(b_data, llbuf)); fprintf(stdout, "\n data (float) : %f", f_data); fprintf(stdout, "\n data (double) : %f", d_data); @@ -5286,7 +5289,7 @@ static void test_manual_sample() affected_rows= mysql_stmt_affected_rows(stmt); if (!opt_silent) - fprintf(stdout, "\n total affected rows: %lld", affected_rows); + fprintf(stdout, "\n total affected rows: %ld", (ulong) affected_rows); if (affected_rows != 1) /* validate affected rows */ { fprintf(stderr, "\n invalid affected rows by MySQL"); @@ -5311,7 +5314,7 @@ static void test_manual_sample() affected_rows= mysql_stmt_affected_rows(stmt); if (!opt_silent) - fprintf(stdout, "\n total affected rows: %lld", affected_rows); + fprintf(stdout, "\n total affected rows: %ld", (ulong) affected_rows); if (affected_rows != 1) /* validate affected rows */ { fprintf(stderr, "\n invalid affected rows by MySQL"); @@ -5467,9 +5470,9 @@ DROP TABLE IF EXISTS test_multi_tab"; mysql_free_result(result); } else if (!opt_silent) - fprintf(stdout, "OK, %lld row(s) affected, %d warning(s)\n", - mysql_affected_rows(mysql_local), - mysql_warning_count(mysql_local)); + fprintf(stdout, "OK, %ld row(s) affected, %ld warning(s)\n", + (ulong) mysql_affected_rows(mysql_local), + (ulong) mysql_warning_count(mysql_local)); exp_value= (uint) mysql_affected_rows(mysql_local); if (rows[count] != exp_value) @@ -6549,7 +6552,7 @@ static void test_ushort_bug() ulonglong longlong_value; int rc; uchar tiny_value; - + char llbuf[22]; myheader("test_ushort_bug"); rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_ushort"); @@ -6601,7 +6604,8 @@ static void test_ushort_bug() { fprintf(stdout, "\n ushort : %d (%ld)", short_value, s_length); fprintf(stdout, "\n ulong : %lu (%ld)", (ulong) long_value, l_length); - fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); + fprintf(stdout, "\n longlong : %s (%ld)", llstr(longlong_value, llbuf), + ll_length); fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); } @@ -6636,6 +6640,7 @@ static void test_sshort_bug() ulonglong longlong_value; int rc; uchar tiny_value; + char llbuf[22]; myheader("test_sshort_bug"); @@ -6686,7 +6691,8 @@ static void test_sshort_bug() { fprintf(stdout, "\n sshort : %d (%ld)", short_value, s_length); fprintf(stdout, "\n slong : %ld (%ld)", (long) long_value, l_length); - fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); + fprintf(stdout, "\n longlong : %s (%ld)", llstr(longlong_value, llbuf), + ll_length); fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); } @@ -6721,6 +6727,7 @@ static void test_stiny_bug() ulonglong longlong_value; int rc; uchar tiny_value; + char llbuf[22]; myheader("test_stiny_bug"); @@ -6770,7 +6777,8 @@ static void test_stiny_bug() { fprintf(stdout, "\n sshort : %d (%ld)", short_value, s_length); fprintf(stdout, "\n slong : %ld (%ld)", (long) long_value, l_length); - fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); + fprintf(stdout, "\n longlong : %s (%ld)", llstr(longlong_value, llbuf), + ll_length); fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); } @@ -11263,7 +11271,7 @@ static void test_bug5399() for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt) { - sprintf(buff, "select %d", stmt - stmt_list); + sprintf(buff, "select %d", (int) (stmt - stmt_list)); *stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(*stmt, buff, strlen(buff)); check_execute(*stmt, rc); @@ -11452,7 +11460,7 @@ static void test_bug5194() if (!opt_silent) printf("Insert: query length= %d, row count= %d, param count= %lu\n", - strlen(query), nrows, mysql_stmt_param_count(stmt)); + (int) strlen(query), nrows, mysql_stmt_param_count(stmt)); /* bind the parameter array and execute the query */ rc= mysql_stmt_bind_param(stmt, bind); |