Commit 5ca36b3b authored by Annamalai Gurusami's avatar Annamalai Gurusami

Bug #12762377 FOREIGN KEYS NOT CONSTRUCTED WHEN APOSTROPHES ARE

ESCAPED WITH BACKSLASH

Problem:

When the CREATE TABLE statement used COMMENTS with escape sequences like
'foo\'s', InnoDB did not parse is correctly when trying to extract the
foreign key information.  Because of this, the foreign keys specified
in the CREATE TABLE statement were not created.

Solution:

Make the InnoDB internal parser aware of escape sequences. 

rb#2457 approved by Kevin.
parent 7397aa91
......@@ -2872,14 +2872,27 @@ dict_scan_to(
const char* string) /*!< in: look for this */
{
char quote = '\0';
ibool escape = FALSE;
for (; *ptr; ptr++) {
if (*ptr == quote) {
/* Closing quote character: do not look for
starting quote or the keyword. */
quote = '\0';
/* If the quote character is escaped by a
backslash, ignore it. */
if (escape) {
escape = FALSE;
} else {
quote = '\0';
}
} else if (quote) {
/* Within quotes: do nothing. */
if (escape) {
escape = FALSE;
} else if (*ptr == '\\') {
escape = TRUE;
}
} else if (*ptr == '`' || *ptr == '"' || *ptr == '\'') {
/* Starting quote: remember the quote character. */
quote = *ptr;
......@@ -3265,6 +3278,11 @@ dict_strip_comments(
char* ptr;
/* unclosed quote character (0 if none) */
char quote = 0;
ibool escape = FALSE;
DBUG_ENTER("dict_strip_comments");
DBUG_PRINT("dict_strip_comments", ("%s", sql_string));
str = mem_alloc(sql_length + 1);
......@@ -3279,16 +3297,29 @@ end_of_string:
ut_a(ptr <= str + sql_length);
return(str);
DBUG_PRINT("dict_strip_comments", ("%s", str));
DBUG_RETURN(str);
}
if (*sptr == quote) {
/* Closing quote character: do not look for
starting quote or comments. */
quote = 0;
/* If the quote character is escaped by a
backslash, ignore it. */
if (escape) {
escape = FALSE;
} else {
quote = 0;
}
} else if (quote) {
/* Within quotes: do not look for
starting quotes or comments. */
if (escape) {
escape = FALSE;
} else if (*sptr == '\\') {
escape = TRUE;
}
} else if (*sptr == '"' || *sptr == '`' || *sptr == '\'') {
/* Starting quote: remember the quote character. */
quote = *sptr;
......
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