mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Fixed bug #29294.
The `SELECT 'r' INTO OUTFILE ... FIELDS ENCLOSED BY 'r' ' statement encoded the 'r' string to a 4 byte string of value x'725c7272' (sequence of 4 characters: r\rr). The LOAD DATA statement decoded this string to a 1 byte string of value x'0d' (ASCII Carriage Return character) instead of the original 'r' character. The same error also happened with the FIELDS ENCLOSED BY clause followed by special characters: 'n', 't', 'r', 'b', '0', 'Z' and 'N'. NOTE 1: This is a result of the undocumented feature: the LOAD DATA INFILE recognises 2-byte input sequences like \n, \t, \r and \Z in addition to documented 2-byte sequences: \0 and \N. This feature should be documented (here backspace character is a default ESCAPED BY character, in the real-life example it may be any ESCAPED BY character). NOTE 2, changed behaviour: Now the `SELECT INTO OUTFILE' statement with the `FIELDS ENCLOSED BY' clause followed by one of: 'n', 't', 'r', 'b', '0', 'Z' or 'N' characters encodes this special character itself by doubling it ('r' --> 'rr'), not by prepending it with an escape character.
This commit is contained in:
@ -1020,6 +1020,7 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
|
||||
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,9 @@ bool select_export::send_data(List<Item> &items)
|
||||
(int) *pos == line_sep_char || !*pos)
|
||||
{
|
||||
char tmp_buff[2];
|
||||
tmp_buff[0]= escape_char;
|
||||
tmp_buff[0]= ((int) *pos == field_sep_char &&
|
||||
is_ambiguous_field_sep) ?
|
||||
field_sep_char : 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))
|
||||
|
Reference in New Issue
Block a user