From bcc627846de20209d929b0fbbe929f432c1677a9 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 23 Oct 2007 16:16:59 +0500 Subject: Fixed bug #31663: if the FIELDS TERMINATED BY string in the SELECT INTO OUTFILE clause starts with a special character (one of n, t, r, b, 0, Z or N) and ENCLOSED BY is empty, every occurrence of this character within a field value is duplicated. Duplication has been avoided. New warning message has been added: "First character of the FIELDS TERMINATED string is ambiguous; please use non-optional and non-empty FIELDS ENCLOSED BY". mysql-test/r/outfile_loaddata.result: BitKeeper file /home/uchum/work/bk/5.0-opt-31663/mysql-test/r/outfile_loaddata.result Added test case for bug #31663. mysql-test/t/outfile_loaddata.test: BitKeeper file /home/uchum/work/bk/5.0-opt-31663/mysql-test/t/outfile_loaddata.test Added test case for bug #31663. sql/sql_class.h: Fixed bug #31663. The select_export::is_ambiguous_field_term field has been added. This field is true if select_export::field_sep_char contains the first char of the FIELDS TERMINATED BY (ENCLOSED BY is empty), and items can contain this character. The select_export::field_term_char field has been added (first char of the FIELDS TERMINATED BY string or INT_MAX). sql/sql_class.cc: Fixed bug #31663. The select_export::prepare method has been modified to calculate a value of the select_export::is_ambiguous_field_term field and to warn if this value is true. The select_export::send_data method has been modified to avoid escaping or duplication of the field_set_char if is_ambiguous_field_term is true. sql/share/errmsg.txt: Fixed bug #31663. The ER_AMBIGUOUS_FIELD_TERM warning has been added. --- sql/sql_class.cc | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index b67f63778dc..1836989f2fa 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1194,6 +1194,7 @@ int select_export::prepare(List &list, SELECT_LEX_UNIT *u) { bool blob_flag=0; + bool string_results= FALSE, non_string_results= FALSE; unit= u; if ((uint) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN) strmake(path,exchange->file_name,FN_REFLEN-1); @@ -1211,13 +1212,18 @@ select_export::prepare(List &list, SELECT_LEX_UNIT *u) blob_flag=1; break; } + if (item->result_type() == STRING_RESULT) + string_results= TRUE; + else + non_string_results= TRUE; } } field_term_length=exchange->field_term->length(); + field_term_char= field_term_length ? (*exchange->field_term)[0] : INT_MAX; if (!exchange->line_term->length()) exchange->line_term=exchange->field_term; // Use this if it exists field_sep_char= (exchange->enclosed->length() ? (*exchange->enclosed)[0] : - field_term_length ? (*exchange->field_term)[0] : INT_MAX); + field_term_char); escape_char= (exchange->escaped->length() ? (*exchange->escaped)[0] : -1); is_ambiguous_field_sep= test(strchr(ESCAPE_CHARS, field_sep_char)); is_unsafe_field_sep= test(strchr(NUMERIC_CHARS, field_sep_char)); @@ -1229,12 +1235,25 @@ select_export::prepare(List &list, SELECT_LEX_UNIT *u) exchange->opt_enclosed=1; // A little quicker loop fixed_row_size= (!field_term_length && !exchange->enclosed->length() && !blob_flag); + if ((is_ambiguous_field_sep && exchange->enclosed->is_empty() && + (string_results || is_unsafe_field_sep)) || + (exchange->opt_enclosed && non_string_results && + field_term_length && strchr(NUMERIC_CHARS, field_term_char))) + { + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_AMBIGUOUS_FIELD_TERM, ER(ER_AMBIGUOUS_FIELD_TERM)); + is_ambiguous_field_term= TRUE; + } + else + is_ambiguous_field_term= FALSE; + return 0; } #define NEED_ESCAPING(x) ((int) (uchar) (x) == escape_char || \ - (int) (uchar) (x) == field_sep_char || \ + (enclosed ? (int) (uchar) (x) == field_sep_char \ + : (int) (uchar) (x) == field_term_char) || \ (int) (uchar) (x) == line_sep_char || \ !(x)) @@ -1263,8 +1282,10 @@ bool select_export::send_data(List &items) while ((item=li++)) { Item_result result_type=item->result_type(); + bool enclosed = (exchange->enclosed->length() && + (!exchange->opt_enclosed || result_type == STRING_RESULT)); res=item->str_result(&tmp); - if (res && (!exchange->opt_enclosed || result_type == STRING_RESULT)) + if (res && enclosed) { if (my_b_write(&cache,(byte*) exchange->enclosed->ptr(), exchange->enclosed->length())) @@ -1355,11 +1376,16 @@ bool select_export::send_data(List &items) DBUG_ASSERT before the loop makes that sure. */ - if (NEED_ESCAPING(*pos) || - (check_second_byte && - my_mbcharlen(character_set_client, (uchar) *pos) == 2 && - pos + 1 < end && - NEED_ESCAPING(pos[1]))) + if ((NEED_ESCAPING(*pos) || + (check_second_byte && + my_mbcharlen(character_set_client, (uchar) *pos) == 2 && + pos + 1 < end && + NEED_ESCAPING(pos[1]))) && + /* + Don't escape field_term_char by doubling - doubling is only + valid for ENCLOSED BY characters: + */ + (enclosed || !is_ambiguous_field_term || *pos != field_term_char)) { char tmp_buff[2]; tmp_buff[0]= ((int) *pos == field_sep_char && @@ -1398,7 +1424,7 @@ bool select_export::send_data(List &items) goto err; } } - if (res && (!exchange->opt_enclosed || result_type == STRING_RESULT)) + if (res && enclosed) { if (my_b_write(&cache, (byte*) exchange->enclosed->ptr(), exchange->enclosed->length())) -- cgit v1.2.1 From e7c6a81f2574840b61b9260e97789980337ca18b Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 10 Nov 2007 23:44:48 +0400 Subject: Fixed bug #28076: inconsistent binary/varbinary comparison. After adding an index the IN (SELECT ...) clause returned a wrong result: the VARBINARY value was illegally padded with zero bytes to the length of the BINARY column for the index search. (, ...) IN (SELECT , ... ) clauses are affected too. sql/item.cc: Fixed bug #28076. The Item_cache_str::save_in_field method has been overloaded to check cached values for an illegal padding before the saving into a field. sql/item.h: Fixed bug #28076. The Item_cache_str::is_varbinary flag has been added and the Item_cache_str::save_in_field method has been overloaded to prevent cached values from an illegal padding when saving in fields. The signature of the Item_cache::get_cache method has been changed to accept pointers to Item instead of Item_result values. sql/item_cmpfunc.cc: Fixed bug #28076. The Item_in_optimizer::fix_left method has been modified to to call Item_cache::get_cache in a new manner. sql/item_subselect.cc: Fixed bug #28076. The subselect_indexsubquery_engine::exec method has been modified to take into account field conversion errors (copy&paste from subselect_uniquesubquery_engine::exec). sql/sp_rcontext.cc: Fixed bug #28076. The sp_rcontext::create_case_expr_holder method has been modified to call Item_cache::get_cache in a new manner. sql/sp_rcontext.h: Fixed bug #28076. The sp_rcontext::create_case_expr_holder method signature has been modified to pass Item pointers to the Item_cache::get_cache method. sql/sql_class.cc: Fixed bug #28076. The select_max_min_finder_subselect::send_data method has been modified to call Item_cache::get_cache in a new manner. mysql-test/t/subselect.test: Added test case for bug #28076. mysql-test/r/subselect.result: Added test case for bug #28076. --- sql/sql_class.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 0bef946928b..ef199b6f883 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1553,7 +1553,7 @@ bool select_max_min_finder_subselect::send_data(List &items) { if (!cache) { - cache= Item_cache::get_cache(val_item->result_type()); + cache= Item_cache::get_cache(val_item); switch (val_item->result_type()) { case REAL_RESULT: -- cgit v1.2.1