summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/loaddata.result8
-rw-r--r--mysql-test/std_data/loaddata5.dat3
-rw-r--r--mysql-test/t/loaddata.test8
-rw-r--r--sql/sql_load.cc19
4 files changed, 36 insertions, 2 deletions
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)