Below is the list of changes that have just been committed into a local
4.1 repository of uchum. When uchum does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@1.2671, 2007-06-28 13:54:55+05:00, gshchepa@gleb.loc +5 -0
Fixed bug #29294.
Actually there were 2 different bugs:
- The `SELECT INTO OUTFILE ... FIELDS ENCLOSED BY 'r' ' statement
encoded the "r" string to a 2 byte string of value "\\r".
The LOAD DATA statement decoded this string to a 1 byte string of
value "\r" instead of "r".
The same error also happened with the FIELDS ENCLOSED BY clause
followed by special characters: 'n', 't', 'r', 'b', '0', 'Z' and 'N'.
NOTE, changed behaviour:
Now the `SELECT INTO OUTFILE' statement with the `FIELDS ENCLOSED BY'
clause followed by special character encodes this special character
itself by doubling it ("r" --> "rr"), not by prepending it with an
escape character.
2. The `LOAD DATA INFILE ... FIELDS ESCAPED BY 'r' ' statement
decoded 2 byte string "rr" to a 1 byte string of value "\r"
instead of "r".
The same error also happened with the FIELDS ESCAPED BY clause
followed by special characters: 'n', 't', 'r', 'b', '0', 'Z' and 'N'.
mysql-test/r/loaddata.result@1.18, 2007-06-27 23:47:52+05:00, gshchepa@gleb.loc +121 -1
Update test case for bug #29294.
mysql-test/t/loaddata.test@1.11, 2007-06-27 23:47:51+05:00, gshchepa@gleb.loc +61 -1
Update test case for bug #29294.
sql/sql_class.cc@1.215, 2007-06-27 23:47:19+05:00, gshchepa@gleb.loc +5 -1
Fixed bug #29294.
The select_export::send_data method has been modified to
encode special values of the field_sep field by
doubling of those values instead of prepending them with a
value of the escape_char field.
Example: The SELECT 'r' INTO OUTFILE FIELDS ENCLOSED BY 'r'
now produces the "rr" output string instead of "\\r".
sql/sql_class.h@1.294, 2007-06-27 23:47:15+05:00, gshchepa@gleb.loc +16 -0
Fixed bug #29294.
The ESCAPE_CHARS macro constant is defined to enumerate
symbolic names of special characters like '\n', '\t' etc.
The select_export::is_ambiguous_field_sep field has been added
to distinguish special values of the field_sep field from
another values (see ESCAPE_CHARS).
sql/sql_load.cc@1.91, 2007-06-27 23:47:30+05:00, gshchepa@gleb.loc +3 -2
Fixed bug #29294.
The READ_INFO::read_field method has been modified to not
to apply the unescape function to an escaped value of the
escape_char: now the LOAD DATA INFILE ... FIELDS ESCAPED BY 'r'
statement decodes input string of value "rr" into the "r" string
instead of "\r".
diff -Nrup a/mysql-test/r/loaddata.result b/mysql-test/r/loaddata.result
--- a/mysql-test/r/loaddata.result 2005-10-22 07:54:29 +05:00
+++ b/mysql-test/r/loaddata.result 2007-06-27 23:47:52 +05:00
@@ -1,4 +1,4 @@
-drop table if exists t1;
+drop table if exists t1,t2;
create table t1 (a date, b date, c date not null, d date);
load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',';
Warnings:
@@ -85,3 +85,123 @@ field1 field2
a"b cd"ef
a"b c"d"e
drop table t1;
+CREATE TABLE t1 (+id INT AUTO_INCREMENT PRIMARY KEY,+c1 VARCHAR(255)+);+CREATE TABLE t2 (+id INT,+c2 VARCHAR(255)+);+INSERT INTO t1 (c1) VALUES+('r'), ('rr'), ('rrr'), ('rrrr'),+('.r'), ('.rr'), ('.rrr'), ('.rrrr'),+('r.'), ('rr.'), ('rrr.'), ('rrrr.'),+('.r.'), ('.rr.'), ('.rrr.'), ('.rrrr.'),+('\r'), ('\\rr'), ('\\\rr'), ('\\\\rr');+SELECT * FROM t1;+id c1+1 r+2 rr+3 rrr+4 rrrr+5 .r+6 .rr+7 .rrr+8 .rrrr+9 r.+10 rr.+11 rrr.+12 rrrr.+13 .r.+14 .rr.+15 .rrr.+16 .rrrr.+17 +18 \rr+19 \r+20 \\rr+SELECT * INTO OUTFILE 'MYSQL_TEST_DIR/var/tmp/t1' FIELDS ENCLOSED BY 'r' FROM t1;+r1r rrrr+r2r rrrrrr+r3r rrrrrrrr+r4r rrrrrrrrrr+r5r r.rrr+r6r r.rrrrr+r7r r.rrrrrrr+r8r r.rrrrrrrrr+r9r rrr.r+r10r rrrrr.r+r11r rrrrrrr.r+r12r rrrrrrrrr.r+r13r r.rr.r+r14r r.rrrr.r+r15r r.rrrrrr.r+r16r r.rrrrrrrr.r+r17r rr+r18r r\\rrrrr+r19r r\\rrr+r20r r\\\\rrrrr+LOAD DATA INFILE 'MYSQL_TEST_DIR/var/tmp/t1' INTO TABLE t2 FIELDS ENCLOSED BY 'r';+SELECT COUNT(*) FROM t2;+COUNT(*)
+20+SELECT t1.id, c1, c2 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;+id c1 c2+TRUNCATE t2;+SELECT * INTO OUTFILE 'MYSQL_TEST_DIR/var/tmp/t1' FIELDS ESCAPED BY 'r' FROM t1;+1 rr+2 rrrr+3 rrrrrr+4 rrrrrrrr+5 .rr+6 .rrrr+7 .rrrrrr+8 .rrrrrrrr+9 rr.+10 rrrr.+11 rrrrrr.+12 rrrrrrrr.+13 .rr.+14 .rrrr.+15 .rrrrrr.+16 .rrrrrrrr.+17 +18 \rrrr+19 \rr+20 \\rrrr+LOAD DATA INFILE 'MYSQL_TEST_DIR/var/tmp/t1' INTO TABLE t2 FIELDS ESCAPED BY 'r';+SELECT COUNT(*) FROM t2;+COUNT(*)
+20+SELECT t1.id, c1, c2 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;+id c1 c2+TRUNCATE t2;+SELECT * INTO OUTFILE 'MYSQL_TEST_DIR/var/tmp/t1' FIELDS ENCLOSED BY 'r' ESCAPED BY 'r' FROM t1;+r1r rrrr+r2r rrrrrr+r3r rrrrrrrr+r4r rrrrrrrrrr+r5r r.rrr+r6r r.rrrrr+r7r r.rrrrrrr+r8r r.rrrrrrrrr+r9r rrr.r+r10r rrrrr.r+r11r rrrrrrr.r+r12r rrrrrrrrr.r+r13r r.rr.r+r14r r.rrrr.r+r15r r.rrrrrr.r+r16r r.rrrrrrrr.r+r17r rr+r18r r\rrrrr+r19r r\rrr+r20r r\\rrrrr+LOAD DATA INFILE 'MYSQL_TEST_DIR/var/tmp/t1' INTO TABLE t2 FIELDS ENCLOSED BY 'r' ESCAPED BY 'r';+SELECT COUNT(*) FROM t2;+COUNT(*)
+20+SELECT t1.id, c1, c2 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;+id c1 c2+DROP TABLE t1,t2;
diff -Nrup a/mysql-test/t/loaddata.test b/mysql-test/t/loaddata.test
--- a/mysql-test/t/loaddata.test 2005-10-22 07:54:29 +05:00
+++ b/mysql-test/t/loaddata.test 2007-06-27 23:47:51 +05:00
@@ -3,7 +3,7 @@
#
--disable_warnings
-drop table if exists t1;
+drop table if exists t1,t2;
--enable_warnings
create table t1 (a date, b date, c date not null, d date);
@@ -66,5 +66,65 @@ create table t1 (a varchar(20), b varcha
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;
+
+#
+# Bug #29294 SELECT INTO OUTFILE/LOAD DATA INFILE with special
+# characters in the FIELDS ENCLOSED BY clause
+#
+
+CREATE TABLE t1 (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ c1 VARCHAR(255)
+);
+
+CREATE TABLE t2 (
+ id INT,
+ c2 VARCHAR(255)
+);
+
+INSERT INTO t1 (c1) VALUES
+ ('r'), ('rr'), ('rrr'), ('rrrr'),
+ ('.r'), ('.rr'), ('.rrr'), ('.rrrr'),
+ ('r.'), ('rr.'), ('rrr.'), ('rrrr.'),
+ ('.r.'), ('.rr.'), ('.rrr.'), ('.rrrr.'),
+ ('\r'), ('\\rr'), ('\\\rr'), ('\\\\rr');
+SELECT * FROM t1;
+
+--exec rm -f $MYSQL_TEST_DIR/var/tmp/t1
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+eval SELECT * INTO OUTFILE '$MYSQL_TEST_DIR/var/tmp/t1' FIELDS ENCLOSED BY 'r' FROM t1;
+--exec cat $MYSQL_TEST_DIR/var/tmp/t1
+
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+eval LOAD DATA INFILE '$MYSQL_TEST_DIR/var/tmp/t1' INTO TABLE t2 FIELDS ENCLOSED BY 'r';
+SELECT COUNT(*) FROM t2;
+SELECT t1.id, c1, c2 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;
+
+TRUNCATE t2;
+
+--exec rm -f $MYSQL_TEST_DIR/var/tmp/t1
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+eval SELECT * INTO OUTFILE '$MYSQL_TEST_DIR/var/tmp/t1' FIELDS ESCAPED BY 'r' FROM t1;
+--exec cat $MYSQL_TEST_DIR/var/tmp/t1
+
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+eval LOAD DATA INFILE '$MYSQL_TEST_DIR/var/tmp/t1' INTO TABLE t2 FIELDS ESCAPED BY 'r';
+SELECT COUNT(*) FROM t2;
+SELECT t1.id, c1, c2 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;
+
+TRUNCATE t2;
+
+--exec rm -f $MYSQL_TEST_DIR/var/tmp/t1
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+eval SELECT * INTO OUTFILE '$MYSQL_TEST_DIR/var/tmp/t1' FIELDS ENCLOSED BY 'r' ESCAPED BY 'r' FROM t1;
+--exec cat $MYSQL_TEST_DIR/var/tmp/t1
+
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+eval LOAD DATA INFILE '$MYSQL_TEST_DIR/var/tmp/t1' INTO TABLE t2 FIELDS ENCLOSED BY 'r' ESCAPED BY 'r';
+SELECT COUNT(*) FROM t2;
+SELECT t1.id, c1, c2 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;
+
+--exec rm $MYSQL_TEST_DIR/var/tmp/t1
+DROP TABLE t1,t2;
# End of 4.1 tests
diff -Nrup a/sql/sql_class.cc b/sql/sql_class.cc
--- a/sql/sql_class.cc 2007-03-20 21:59:23 +04:00
+++ b/sql/sql_class.cc 2007-06-27 23:47:19 +05:00
@@ -1020,6 +1020,7 @@ select_export::prepare(List- &list,
field_sep_char= (exchange->enclosed->length() ? (*exchange->enclosed)[0] :
field_term_length ? (*exchange->field_term)[0] : INT_MAX);
escape_char= (exchange->escaped->length() ? (*exchange->escaped)[0] : -1);
+ is_ambiguous_field_sep= strchr(ESCAPE_CHARS, field_sep_char);
line_sep_char= (exchange->line_term->length() ?
(*exchange->line_term)[0] : INT_MAX);
if (!field_term_length)
@@ -1113,7 +1114,10 @@ bool select_export::send_data(List<Item>
(int) *pos == line_sep_char || !*pos)
{
char tmp_buff[2];
- tmp_buff[0]= escape_char;
+ if ((int) *pos == field_sep_char && is_ambiguous_field_sep)
+ tmp_buff[0]= field_sep_char;
+ else
+ tmp_buff[0]= escape_char;
tmp_buff[1]= *pos ? *pos : '0';
if (my_b_write(&cache,(byte*) start,(uint) (pos-start)) ||
my_b_write(&cache,(byte*) tmp_buff,2))
diff -Nrup a/sql/sql_class.h b/sql/sql_class.h
--- a/sql/sql_class.h 2007-01-15 13:58:02 +04:00
+++ b/sql/sql_class.h 2007-06-27 23:47:15 +05:00
@@ -1224,9 +1224,25 @@ public:
};
+#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescaped
+
+
class select_export :public select_to_file {
uint field_term_length;
int field_sep_char,escape_char,line_sep_char;
+ /*
+ The is_ambiguous_field_sep field is true if the value of field_sep_char
+ field is one of the 'n', 't', 'r' etc characters
+ (see the READ_INFO::unescape method and the ESCAPE_CHARS constant value).
+
+ For example, if the value of field_sep_char is 'r', it is incorrect to
+ escape an 'r' character in the string "...r..." with the value of
+ escape_char field, because the combination of escape_char and the 'r'
+ character will be decoded as '\r'. Thus, we should encode the "...r..."
+ string as the "...rr...", not as the "...\\r..." where '\' is a value of
+ escape_char.
+ */
+ bool is_ambiguous_field_sep;
bool fixed_row_size;
public:
select_export(sql_exchange *ex) :select_to_file(ex) {}
diff -Nrup a/sql/sql_load.cc b/sql/sql_load.cc
--- a/sql/sql_load.cc 2007-02-26 23:33:55 +04:00
+++ b/sql/sql_load.cc 2007-06-27 23:47:30 +05:00
@@ -611,6 +611,7 @@ read_sep_field(THD *thd,COPY_INFO &info,
char
READ_INFO::unescape(char chr)
{
+ /* Keep this switch statement synchronous with ESCAPE_CHARS constant */
switch(chr) {
case 'n': return '\n';
case 't': return '\t';
@@ -824,9 +825,9 @@ int READ_INFO::read_field()
like \n. This allows: LOAD DATA ... ENCLOSED BY '"' ESCAPED BY '"'
with data like: "fie""ld1", "field2"
*/
- if (escape_char != enclosed_char || chr == escape_char)
+ if (escape_char != enclosed_char)
{
- *to++ = (byte) unescape((char) chr);
+ *to++= chr == escape_char ? (byte) chr : (byte) unescape((char) chr);
continue;
}
PUSH(chr);
--
MySQL Code Commits Mailing List
For list archives:
http://lists.mysql.com/commits
To unsubscribe:
http://lists.mysql.com/commits?unsub=lists@pantek.com
Received on Thu Jun 28 04:55:10 2007