Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
47ba1e81
Commit
47ba1e81
authored
Sep 18, 2008
by
Matthias Leich
Browse files
Options
Browse Files
Download
Plain Diff
Merge actual tree -> local tree
no conflicts
parents
2130b894
86775b10
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
316 additions
and
4 deletions
+316
-4
mysql-test/r/loaddata.result
mysql-test/r/loaddata.result
+120
-0
mysql-test/t/loaddata.test
mysql-test/t/loaddata.test
+181
-1
sql/sql_class.cc
sql/sql_class.cc
+11
-2
sql/sql_class.h
sql/sql_class.h
+1
-0
sql/sql_load.cc
sql/sql_load.cc
+3
-1
No files found.
mysql-test/r/loaddata.result
View file @
47ba1e81
...
...
@@ -328,3 +328,123 @@ DROP VIEW v2;
DROP VIEW v3;
# -- End of Bug#35469.
Bug#37114
SET SESSION character_set_client=latin1;
SET SESSION character_set_server=latin1;
SET SESSION character_set_connection=latin1;
SET @OLD_SQL_MODE=@@SESSION.SQL_MODE;
test LOAD DATA INFILE
SET sql_mode = '';
SELECT '1 \\aa\n' INTO DUMPFILE 'MYSQLTEST_VARDIR/tmp/bug37114.txt';
CREATE TABLE t1 (id INT, val1 CHAR(3)) ENGINE=MyISAM;
SET sql_mode = 'NO_BACKSLASH_ESCAPES';
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug37114.txt' REPLACE INTO TABLE t1 FIELDS TERMINATED BY ' ';
SELECT * FROM t1;
id val1
1 \aa
SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug37114_out.txt' FIELDS ESCAPED BY '' TERMINATED BY ' ' FROM t1;
SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug37114_out.txt' FIELDS TERMINATED BY ' ' FROM t1;
INSERT INTO t1 (id, val1) VALUES (1, '\aa');
SELECT * FROM t1;
id val1
1 \aa
1 \aa
SET sql_mode='';
INSERT INTO t1 (id, val1) VALUES (1, '\aa');
SELECT * FROM t1;
id val1
1 \aa
1 \aa
1 aa
DROP TABLE t1;
test SELECT INTO OUTFILE
CREATE TABLE t1 (id INT PRIMARY KEY, val1 CHAR(4));
CREATE TABLE t2 LIKE t1;
SET sql_mode = '';
INSERT INTO t1 (id, val1) VALUES (5, '\ttab');
INSERT INTO t1 (id, val1) VALUES (4, '\\r');
SET sql_mode = 'NO_BACKSLASH_ESCAPES';
INSERT INTO t1 (id, val1) VALUES (3, '\tx');
1.1 NO_BACKSLASH_ESCAPES, use defaults for ESCAPED BY
SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug37114.txt' FIELDS TERMINATED BY ' ' FROM t1 ORDER BY id;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug37114.txt' INTO TABLE t2 FIELDS TERMINATED BY ' ';
SELECT 'before' AS t, id, val1, hex(val1) FROM t1 UNION
SELECT 'after' AS t, id, val1, hex(val1) FROM t2 ORDER BY id,t DESC;
t id val1 hex(val1)
before 3 \tx 5C7478
after 3 \tx 5C7478
before 4 \r 5C72
after 4 \r 5C72
before 5 tab 09746162
after 5 tab 09746162
TRUNCATE t2;
SELECT LOAD_FILE("MYSQLTEST_VARDIR/tmp/bug37114.txt");
LOAD_FILE("MYSQLTEST_VARDIR/tmp/bug37114.txt")
3 \tx
4 \r
5 tab
1.2 NO_BACKSLASH_ESCAPES, override defaults for ESCAPED BY
SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug37114.txt' FIELDS ESCAPED BY '\' TERMINATED BY ' ' FROM t1 ORDER BY id;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug37114.txt' INTO TABLE t2 FIELDS ESCAPED BY '\' TERMINATED BY ' ';
SELECT 'before' AS t, id, val1, hex(val1) FROM t1 UNION
SELECT 'after' AS t, id, val1, hex(val1) FROM t2 ORDER BY id,t DESC;
t id val1 hex(val1)
before 3 \tx 5C7478
after 3 \tx 5C7478
before 4 \r 5C72
after 4 \r 5C72
before 5 tab 09746162
after 5 tab 09746162
TRUNCATE t2;
SELECT LOAD_FILE("MYSQLTEST_VARDIR/tmp/bug37114.txt");
LOAD_FILE("MYSQLTEST_VARDIR/tmp/bug37114.txt")
3 \\tx
4 \\r
5 tab
SET sql_mode = '';
2.1 !NO_BACKSLASH_ESCAPES, use defaults for ESCAPED BY
SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug37114.txt' FIELDS TERMINATED BY ' ' FROM t1 ORDER BY id;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug37114.txt' INTO TABLE t2 FIELDS TERMINATED BY ' ';
SELECT 'before' AS t, id, val1, hex(val1) FROM t1 UNION
SELECT 'after' AS t, id, val1, hex(val1) FROM t2 ORDER BY id,t DESC;
t id val1 hex(val1)
before 3 \tx 5C7478
after 3 \tx 5C7478
before 4 \r 5C72
after 4 \r 5C72
before 5 tab 09746162
after 5 tab 09746162
TRUNCATE t2;
SET sql_mode = 'NO_BACKSLASH_ESCAPES';
SELECT LOAD_FILE("MYSQLTEST_VARDIR/tmp/bug37114.txt");
LOAD_FILE("MYSQLTEST_VARDIR/tmp/bug37114.txt")
3 \\tx
4 \\r
5 tab
SET sql_mode = '';
2.2 !NO_BACKSLASH_ESCAPES, override defaults for ESCAPED BY
SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug37114.txt' FIELDS ESCAPED BY '' TERMINATED BY ' ' FROM t1 ORDER BY id;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug37114.txt' INTO TABLE t2 FIELDS ESCAPED BY '' TERMINATED BY ' ';
SELECT 'before' AS t, id, val1, hex(val1) FROM t1 UNION
SELECT 'after' AS t, id, val1, hex(val1) FROM t2 ORDER BY id,t DESC;
t id val1 hex(val1)
before 3 \tx 5C7478
after 3 \tx 5C7478
before 4 \r 5C72
after 4 \r 5C72
before 5 tab 09746162
after 5 tab 09746162
TRUNCATE t2;
SET sql_mode = 'NO_BACKSLASH_ESCAPES';
SELECT LOAD_FILE("MYSQLTEST_VARDIR/tmp/bug37114.txt");
LOAD_FILE("MYSQLTEST_VARDIR/tmp/bug37114.txt")
3 \tx
4 \r
5 tab
set session sql_mode=@OLD_SQL_MODE;
DROP TABLE t1,t2;
End of 5.0 tests
mysql-test/t/loaddata.test
View file @
47ba1e81
...
...
@@ -318,4 +318,184 @@ DROP VIEW v3;
###########################################################################
# End of 5.0 tests
#
# Bug#37114: sql_mode NO_BACKSLASH_ESCAPES does not work properly with
# LOAD DATA INFILE
#
# - For each plain "SELECT id,...", the 1st pair ("before" SELECT...OUTFILE,
# LOAD...INFILE) and the 2nd pair of lines ("after") in the result should
# look the same, otherwise we broke the dumpe/restore cycle!
#
# - the \r is always { '\\', 'r' } in memory, but on-disk format changes
#
# - the \t is { '\t' } or { '\\', 't' } in memory depending on whether \
# is magic (that is, NO_BACKSLASH_ESCAPES is not set) at INSERT-time.
# on-disk format varies.
#
# - while INFILE/OUTFILE behaviour changes according to NO_BACKSLASH_ESCAPES,
# we can override these defaults using ESCAPED BY '...'
# 1: NO_BACKSLASH_ESCAPES default, \ on-disk: \,t,x,\r
# 2: NO_BACKSLASH_ESCAPES override, \\ on-disk: \,\,t,x,\,\,r
# 3: !NO_BACKSLASH_ESCAPES default, \\ on-disk: tab,\,\,r
# 3: !NO_BACKSLASH_ESCAPES override, \ on-disk: tab,\,r
--
echo
Bug
#37114
SET
SESSION
character_set_client
=
latin1
;
SET
SESSION
character_set_server
=
latin1
;
SET
SESSION
character_set_connection
=
latin1
;
SET
@
OLD_SQL_MODE
=@@
SESSION
.
SQL_MODE
;
# 0. test LOAD DATA INFILE first; if that works, all issues in
# SELECT INTO OUTFILE / LOAD DATA INFILE cycles below are
# arguably in the saving.
--
echo
test
LOAD
DATA
INFILE
--
let
$file
=
$MYSQLTEST_VARDIR
/
tmp
/
bug37114
.
txt
--
let
$file2
=
$MYSQLTEST_VARDIR
/
tmp
/
bug37114_out
.
txt
SET
sql_mode
=
''
;
--
replace_result
$MYSQLTEST_VARDIR
MYSQLTEST_VARDIR
--
eval
SELECT
'1 \\\\aa\n'
INTO
DUMPFILE
'$file'
CREATE
TABLE
t1
(
id
INT
,
val1
CHAR
(
3
))
ENGINE
=
MyISAM
;
SET
sql_mode
=
'NO_BACKSLASH_ESCAPES'
;
--
replace_result
$MYSQLTEST_VARDIR
MYSQLTEST_VARDIR
--
eval
LOAD
DATA
INFILE
'$file'
REPLACE
INTO
TABLE
t1
FIELDS
TERMINATED
BY
' '
SELECT
*
FROM
t1
;
# show we can write this with OUTFILE, forcing the parameters for now
--
replace_result
$MYSQLTEST_VARDIR
MYSQLTEST_VARDIR
--
eval
SELECT
*
INTO
OUTFILE
'$file2'
FIELDS
ESCAPED
BY
''
TERMINATED
BY
' '
FROM
t1
--
diff_files
$file
$file2
--
remove_file
$file2
# now show the OUTFILE defaults are correct with NO_BACKSLASH_ESCAPES
--
replace_result
$MYSQLTEST_VARDIR
MYSQLTEST_VARDIR
--
eval
SELECT
*
INTO
OUTFILE
'$file2'
FIELDS
TERMINATED
BY
' '
FROM
t1
--
diff_files
$file
$file2
--
remove_file
$file2
INSERT
INTO
t1
(
id
,
val1
)
VALUES
(
1
,
'\aa'
);
SELECT
*
FROM
t1
;
SET
sql_mode
=
''
;
INSERT
INTO
t1
(
id
,
val1
)
VALUES
(
1
,
'\aa'
);
SELECT
*
FROM
t1
;
DROP
TABLE
t1
;
--
remove_file
$file
--
echo
test
SELECT
INTO
OUTFILE
CREATE
TABLE
t1
(
id
INT
PRIMARY
KEY
,
val1
CHAR
(
4
));
CREATE
TABLE
t2
LIKE
t1
;
# 1. with NO_BACKSLASH_ESCAPES on
SET
sql_mode
=
''
;
INSERT
INTO
t1
(
id
,
val1
)
VALUES
(
5
,
'\ttab'
);
INSERT
INTO
t1
(
id
,
val1
)
VALUES
(
4
,
'\\r'
);
SET
sql_mode
=
'NO_BACKSLASH_ESCAPES'
;
INSERT
INTO
t1
(
id
,
val1
)
VALUES
(
3
,
'\tx'
);
--
echo
1.1
NO_BACKSLASH_ESCAPES
,
use
defaults
for ESCAPED BY
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT * INTO OUTFILE '$file' FIELDS TERMINATED BY ' ' FROM t1 ORDER BY id
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval LOAD DATA INFILE '$file' INTO TABLE t2 FIELDS TERMINATED BY ' '
SELECT 'before'
AS
t
, id, val1, hex(val1) FROM t1 UNION
SELECT 'after'
AS
t
, id, val1, hex(val1) FROM t2 ORDER BY id,t DESC
;
TRUNCATE
t2
;
--
replace_result
$MYSQLTEST_VARDIR
MYSQLTEST_VARDIR
eval
SELECT
LOAD_FILE
(
"
$file
"
);
--
remove_file
$file
--
echo
1.2
NO_BACKSLASH_ESCAPES
,
override
defaults
for
ESCAPED
BY
--
replace_result
$MYSQLTEST_VARDIR
MYSQLTEST_VARDIR
--
eval
SELECT
*
INTO
OUTFILE
'$file'
FIELDS
ESCAPED
BY
'\' TERMINATED BY '
' FROM t1 ORDER BY id
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval LOAD DATA INFILE '
$file
' INTO TABLE t2 FIELDS ESCAPED BY '
\
' TERMINATED BY '
'
SELECT '
before
' AS t, id, val1, hex(val1) FROM t1 UNION
SELECT '
after
' AS t, id, val1, hex(val1) FROM t2 ORDER BY id,t DESC;
TRUNCATE t2;
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval SELECT LOAD_FILE("$file");
--remove_file $file
# 2. with NO_BACKSLASH_ESCAPES off
SET sql_mode = '';
--echo 2.1 !NO_BACKSLASH_ESCAPES, use defaults for ESCAPED BY
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT * INTO OUTFILE '
$file
' FIELDS TERMINATED BY '
' FROM t1 ORDER BY id
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval LOAD DATA INFILE '
$file
' INTO TABLE t2 FIELDS TERMINATED BY '
'
SELECT '
before
' AS t, id, val1, hex(val1) FROM t1 UNION
SELECT '
after
' AS t, id, val1, hex(val1) FROM t2 ORDER BY id,t DESC;
TRUNCATE t2;
SET sql_mode = '
NO_BACKSLASH_ESCAPES
';
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval SELECT LOAD_FILE("$file");
--remove_file $file
SET sql_mode = '';
--echo 2.2 !NO_BACKSLASH_ESCAPES, override defaults for ESCAPED BY
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT * INTO OUTFILE '
$file
' FIELDS ESCAPED BY '' TERMINATED BY '
' FROM t1 ORDER BY id
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval LOAD DATA INFILE '
$file
' INTO TABLE t2 FIELDS ESCAPED BY '' TERMINATED BY '
'
SELECT '
before
' AS t, id, val1, hex(val1) FROM t1 UNION
SELECT '
after
' AS t, id, val1, hex(val1) FROM t2 ORDER BY id,t DESC;
TRUNCATE t2;
SET sql_mode = '
NO_BACKSLASH_ESCAPES
'
;
--
replace_result
$MYSQLTEST_VARDIR
MYSQLTEST_VARDIR
eval
SELECT
LOAD_FILE
(
"
$file
"
);
--
remove_file
$file
# clean up
set
session
sql_mode
=@
OLD_SQL_MODE
;
DROP
TABLE
t1
,
t2
;
--
echo
End
of
5.0
tests
sql/sql_class.cc
View file @
47ba1e81
...
...
@@ -974,6 +974,12 @@ sql_exchange::sql_exchange(char *name,bool flag)
cs
=
NULL
;
}
bool
sql_exchange
::
escaped_given
(
void
)
{
return
escaped
!=
&
default_escaped
;
}
bool
select_send
::
send_fields
(
List
<
Item
>
&
list
,
uint
flags
)
{
bool
res
;
...
...
@@ -1234,8 +1240,11 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
exchange
->
line_term
=
exchange
->
field_term
;
// Use this if it exists
field_sep_char
=
(
exchange
->
enclosed
->
length
()
?
(
int
)
(
uchar
)
(
*
exchange
->
enclosed
)[
0
]
:
field_term_char
);
escape_char
=
(
exchange
->
escaped
->
length
()
?
(
int
)
(
uchar
)
(
*
exchange
->
escaped
)[
0
]
:
-
1
);
if
(
exchange
->
escaped
->
length
()
&&
(
exchange
->
escaped_given
()
||
!
(
thd
->
variables
.
sql_mode
&
MODE_NO_BACKSLASH_ESCAPES
)))
escape_char
=
(
int
)
(
uchar
)
(
*
exchange
->
escaped
)[
0
];
else
escape_char
=
-
1
;
is_ambiguous_field_sep
=
test
(
strchr
(
ESCAPE_CHARS
,
field_sep_char
));
is_unsafe_field_sep
=
test
(
strchr
(
NUMERIC_CHARS
,
field_sep_char
));
line_sep_char
=
(
exchange
->
line_term
->
length
()
?
...
...
sql/sql_class.h
View file @
47ba1e81
...
...
@@ -1896,6 +1896,7 @@ class sql_exchange :public Sql_alloc
ulong
skip_lines
;
CHARSET_INFO
*
cs
;
sql_exchange
(
char
*
name
,
bool
dumpfile_flag
);
bool
escaped_given
(
void
);
};
#include "log_event.h"
...
...
sql/sql_load.cc
View file @
47ba1e81
...
...
@@ -325,7 +325,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
bzero
((
char
*
)
&
info
,
sizeof
(
info
));
info
.
ignore
=
ignore
;
info
.
handle_duplicates
=
handle_duplicates
;
info
.
escape_char
=
escaped
->
length
()
?
(
*
escaped
)[
0
]
:
INT_MAX
;
info
.
escape_char
=
(
escaped
->
length
()
&&
(
ex
->
escaped_given
()
||
!
(
thd
->
variables
.
sql_mode
&
MODE_NO_BACKSLASH_ESCAPES
)))
?
(
*
escaped
)[
0
]
:
INT_MAX
;
READ_INFO
read_info
(
file
,
tot_length
,
ex
->
cs
?
ex
->
cs
:
thd
->
variables
.
collation_database
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment