Commit a02ba9c1 authored by Sergei Golubchik's avatar Sergei Golubchik

Merge branch '5.5' into 10.0

parents 8baf9b0c d5cd3345
...@@ -2321,8 +2321,10 @@ static bool add_line(String &buffer, char *line, ulong line_length, ...@@ -2321,8 +2321,10 @@ static bool add_line(String &buffer, char *line, ulong line_length,
continue; continue;
} }
#endif #endif
if (!*ml_comment && inchar == '\\' && if (!*ml_comment && inchar == '\\' && *in_string != '`' &&
!(*in_string && !(*in_string == '"' &&
(mysql.server_status & SERVER_STATUS_ANSI_QUOTES)) &&
!(*in_string &&
(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES))) (mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)))
{ {
// Found possbile one character command like \c // Found possbile one character command like \c
......
...@@ -6562,6 +6562,16 @@ my_bool end_of_query(int c) ...@@ -6562,6 +6562,16 @@ my_bool end_of_query(int c)
} }
static inline bool is_escape_char(char c, char in_string)
{
if (c != '\\' || in_string == '`') return false;
if (!cur_con) return true;
uint server_status= cur_con->mysql->server_status;
if (server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) return false;
return !(server_status & SERVER_STATUS_ANSI_QUOTES && in_string == '"');
}
/* /*
Read one "line" from the file Read one "line" from the file
...@@ -6670,7 +6680,7 @@ int read_line(char *buf, int size) ...@@ -6670,7 +6680,7 @@ int read_line(char *buf, int size)
state= R_Q; state= R_Q;
} }
} }
have_slash= (c == '\\'); have_slash= is_escape_char(c, last_quote);
break; break;
case R_COMMENT: case R_COMMENT:
...@@ -6740,7 +6750,7 @@ int read_line(char *buf, int size) ...@@ -6740,7 +6750,7 @@ int read_line(char *buf, int size)
case R_Q: case R_Q:
if (c == last_quote) if (c == last_quote)
state= R_NORMAL; state= R_NORMAL;
else if (c == '\\') else if (is_escape_char(c, last_quote))
state= R_SLASH_IN_Q; state= R_SLASH_IN_Q;
break; break;
......
...@@ -329,6 +329,8 @@ enum enum_server_command ...@@ -329,6 +329,8 @@ enum enum_server_command
*/ */
#define SERVER_STATUS_IN_TRANS_READONLY 8192 #define SERVER_STATUS_IN_TRANS_READONLY 8192
#define SERVER_STATUS_ANSI_QUOTES 32768
/** /**
Server status flags that must be cleared when starting Server status flags that must be cleared when starting
......
...@@ -529,3 +529,61 @@ a ...@@ -529,3 +529,61 @@ a
+-------------------+ +-------------------+
End of tests End of tests
create table `a1\``b1` (a int);
show tables;
Tables_in_test
a1\`b1
insert `a1\``b1` values (1),(2);
show create table `a1\``b1`;
Table Create Table
a1\`b1 CREATE TABLE `a1\``b1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `a1\``b1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO `a1\``b1` VALUES (1),(2);
insert `a1\``b1` values (4),(5);
show create table `a1\``b1`;
Table Create Table
a1\`b1 CREATE TABLE `a1\``b1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from `a1\``b1`;
a
1
2
drop table `a1\``b1`;
set sql_mode=ansi_quotes;
create table "a1\""b1" (a int);
show tables;
Tables_in_test
a1\"b1
insert "a1\""b1" values (1),(2);
show create table "a1\""b1";
Table Create Table
a1\"b1 CREATE TABLE "a1\""b1" (
"a" int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE "a1\""b1" (
"a" int(11) DEFAULT NULL
);
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO "a1\""b1" VALUES (1),(2);
insert "a1\""b1" values (4),(5);
show create table "a1\""b1";
Table Create Table
a1\"b1 CREATE TABLE "a1\""b1" (
"a" int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from "a1\""b1";
a
1
2
drop table "a1\""b1";
set sql_mode=default;
...@@ -960,4 +960,9 @@ con1 ...@@ -960,4 +960,9 @@ con1
con2 con2
con2 con2
-closed_connection- -closed_connection-
set sql_mode=no_backslash_escapes;
select "foo\""bar";
foo\"bar
foo\"bar
set sql_mode=default;
End of tests End of tests
...@@ -618,3 +618,33 @@ EOF ...@@ -618,3 +618,33 @@ EOF
--echo --echo
--echo End of tests --echo End of tests
#
# MDEV-13187 incorrect backslash parsing in clients
#
create table `a1\``b1` (a int);
show tables;
insert `a1\``b1` values (1),(2);
show create table `a1\``b1`;
--exec $MYSQL_DUMP --compact test
--exec $MYSQL_DUMP test > $MYSQLTEST_VARDIR/tmp/bug.sql
insert `a1\``b1` values (4),(5);
--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug.sql
show create table `a1\``b1`;
select * from `a1\``b1`;
drop table `a1\``b1`;
# same with ansi_quotes
set sql_mode=ansi_quotes;
create table "a1\""b1" (a int);
show tables;
insert "a1\""b1" values (1),(2);
show create table "a1\""b1";
--exec $MYSQL_DUMP --compact --compatible=postgres test
--exec $MYSQL_DUMP --compatible=postgres test > $MYSQLTEST_VARDIR/tmp/bug.sql
insert "a1\""b1" values (4),(5);
--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug.sql
show create table "a1\""b1";
select * from "a1\""b1";
drop table "a1\""b1";
set sql_mode=default;
...@@ -2948,11 +2948,17 @@ disconnect $x; ...@@ -2948,11 +2948,17 @@ disconnect $x;
# Disconnect the selected connection # Disconnect the selected connection
disconnect $y; disconnect $y;
--echo $CURRENT_CONNECTION --echo $CURRENT_CONNECTION
connection default;
#
# MDEV-13187 incorrect backslash parsing in clients
#
set sql_mode=no_backslash_escapes;
select "foo\""bar";
set sql_mode=default;
--echo End of tests --echo End of tests
connection default;
# Wait till we reached the initial number of concurrent sessions # Wait till we reached the initial number of concurrent sessions
--source include/wait_until_count_sessions.inc --source include/wait_until_count_sessions.inc
......
...@@ -1378,6 +1378,8 @@ void THD::init(void) ...@@ -1378,6 +1378,8 @@ void THD::init(void)
server_status= SERVER_STATUS_AUTOCOMMIT; server_status= SERVER_STATUS_AUTOCOMMIT;
if (variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) if (variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)
server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES; server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES;
if (variables.sql_mode & MODE_ANSI_QUOTES)
server_status|= SERVER_STATUS_ANSI_QUOTES;
transaction.all.modified_non_trans_table= transaction.all.modified_non_trans_table=
transaction.stmt.modified_non_trans_table= FALSE; transaction.stmt.modified_non_trans_table= FALSE;
......
...@@ -2899,6 +2899,10 @@ static bool fix_sql_mode(sys_var *self, THD *thd, enum_var_type type) ...@@ -2899,6 +2899,10 @@ static bool fix_sql_mode(sys_var *self, THD *thd, enum_var_type type)
thd->server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES; thd->server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES;
else else
thd->server_status&= ~SERVER_STATUS_NO_BACKSLASH_ESCAPES; thd->server_status&= ~SERVER_STATUS_NO_BACKSLASH_ESCAPES;
if (thd->variables.sql_mode & MODE_ANSI_QUOTES)
thd->server_status|= SERVER_STATUS_ANSI_QUOTES;
else
thd->server_status&= ~SERVER_STATUS_ANSI_QUOTES;
} }
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment