From dab880274afbae01571257feebb819d94b861c01 Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Wed, 22 Jun 2005 16:14:14 -0700 Subject: [PATCH 1/3] Fix LOAD DATA to handle having the escape and enclosed-by character be the same. (Bug #11203) --- mysql-test/r/loaddata.result | 8 ++++++++ mysql-test/std_data/loaddata5.dat | 3 +++ mysql-test/t/loaddata.test | 8 ++++++++ sql/sql_load.cc | 19 +++++++++++++++++-- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 mysql-test/std_data/loaddata5.dat diff --git a/mysql-test/r/loaddata.result b/mysql-test/r/loaddata.result index c0baabcc507..cb9849ec23d 100644 --- a/mysql-test/r/loaddata.result +++ b/mysql-test/r/loaddata.result @@ -66,3 +66,11 @@ a b 3 row 3 0 drop table t1; +create table t1 (a varchar(20), b varchar(20)); +load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by ',' enclosed by '"' escaped by '"' (a,b); +select * from t1; +a b +field1 field2 +a"b cd"ef +a"b c"d"e +drop table t1; diff --git a/mysql-test/std_data/loaddata5.dat b/mysql-test/std_data/loaddata5.dat new file mode 100644 index 00000000000..5bdddfa977a --- /dev/null +++ b/mysql-test/std_data/loaddata5.dat @@ -0,0 +1,3 @@ +"field1","field2" +"a""b","cd""ef" +"a"b",c"d"e diff --git a/mysql-test/t/loaddata.test b/mysql-test/t/loaddata.test index aa0ea0a2f55..2afd710c694 100644 --- a/mysql-test/t/loaddata.test +++ b/mysql-test/t/loaddata.test @@ -31,3 +31,11 @@ load data infile '../../std_data/loaddata4.dat' into table t1 fields terminated select * from t1; drop table t1; +# +# Bug #11203: LOAD DATA does not accept same characters for ESCAPED and +# ENCLOSED +# +create table t1 (a varchar(20), b varchar(20)); +load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by ',' enclosed by '"' escaped by '"' (a,b); +select * from t1; +drop table t1; diff --git a/sql/sql_load.cc b/sql/sql_load.cc index c4f5b1427af..b998f39971c 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -799,8 +799,23 @@ int READ_INFO::read_field() *to++= (byte) escape_char; goto found_eof; } - *to++ = (byte) unescape((char) chr); - continue; + /* + When escape_char == enclosed_char, we treat it like we do for + handling quotes in SQL parsing -- you can double-up the + escape_char to include it literally, but it doesn't do escapes + like \n. This allows: LOAD DATA ... ENCLOSED BY '"' ESCAPED BY '"' + with data like: "fie""ld1", "field2" + */ + if (escape_char != enclosed_char || chr == escape_char) + { + *to++ = (byte) unescape((char) chr); + continue; + } + else + { + PUSH(chr); + chr= escape_char; + } } #ifdef ALLOW_LINESEPARATOR_IN_STRINGS if (chr == line_term_char) From 721873f7cda9587e40a461887a5b6bc6b698f2d8 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Fri, 21 Oct 2005 14:56:59 +0200 Subject: [PATCH 2/3] compilation failure fixed --- sql/item.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/item.cc b/sql/item.cc index d284af2b9f1..b2a1e44cfcc 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1768,7 +1768,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) Item** res= find_item_in_list(this, thd->lex->current_select->item_list, &counter, REPORT_EXCEPT_NOT_FOUND, ¬_used); - if (res != not_found_item && (*res)->type() == Item::FIELD_ITEM) + if (res != (Item **)not_found_item && (*res)->type() == Item::FIELD_ITEM) { set_field((*((Item_field**)res))->field); return 0; From 7510c45423af35a11a6c8942501e4a0a8d0c3da7 Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Fri, 21 Oct 2005 19:54:34 -0700 Subject: [PATCH 3/3] Fix merge of test that left out a drop table. --- mysql-test/r/loaddata.result | 1 + mysql-test/t/loaddata.test | 1 + 2 files changed, 2 insertions(+) diff --git a/mysql-test/r/loaddata.result b/mysql-test/r/loaddata.result index 85de8728bd7..e1076cd3072 100644 --- a/mysql-test/r/loaddata.result +++ b/mysql-test/r/loaddata.result @@ -76,6 +76,7 @@ select * from t1; id 0 SET @@SQL_MODE=@OLD_SQL_MODE; +drop table t1; create table t1 (a varchar(20), b varchar(20)); load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by ',' enclosed by '"' escaped by '"' (a,b); select * from t1; diff --git a/mysql-test/t/loaddata.test b/mysql-test/t/loaddata.test index 340801e6a01..e989cb0b2ac 100644 --- a/mysql-test/t/loaddata.test +++ b/mysql-test/t/loaddata.test @@ -56,6 +56,7 @@ enable_query_log; select * from t1; --exec rm $MYSQL_TEST_DIR/var/tmp/t1 SET @@SQL_MODE=@OLD_SQL_MODE; +drop table t1; # # Bug #11203: LOAD DATA does not accept same characters for ESCAPED and