MXS-1575: Fix CREATE TABLE processing

The CREATE TABLE processing failed to identify the explicit database names
that were generated by mysqldump.
This commit is contained in:
Markus Mäkelä
2018-01-05 10:37:43 +02:00
parent c64fd4f39f
commit ce1c45828a

View File

@ -421,28 +421,33 @@ static bool get_database_name(const char* sql, char* dest)
if (ptr) if (ptr)
{ {
ptr--; ptr--;
while (*ptr == '`' || isspace(*ptr)) while (ptr >= sql && (*ptr == '`' || isspace(*ptr)))
{ {
ptr--; ptr--;
} }
while (*ptr != '`' && *ptr != '.' && !isspace(*ptr)) while (ptr >= sql && *ptr != '`' && *ptr != '.' && !isspace(*ptr))
{ {
ptr--; ptr--;
} }
if (*ptr == '.') while (ptr >= sql && (*ptr == '`' || isspace(*ptr)))
{
ptr--;
}
if (ptr >= sql && *ptr == '.')
{ {
// The query defines an explicit database // The query defines an explicit database
while (*ptr == '`' || *ptr == '.' || isspace(*ptr)) while (ptr >= sql && (*ptr == '`' || *ptr == '.' || isspace(*ptr)))
{ {
ptr--; ptr--;
} }
const char* end = ptr + 1; const char* end = ptr + 1;
while (*ptr != '`' && *ptr != '.' && !isspace(*ptr)) while (ptr >= sql && *ptr != '`' && *ptr != '.' && !isspace(*ptr))
{ {
ptr--; ptr--;
} }
@ -1139,7 +1144,7 @@ void read_alter_identifier(const char *sql, const char *end, char *dest, int siz
int len = 0; int len = 0;
const char *tok = get_tok(sql, &len, end); // ALTER const char *tok = get_tok(sql, &len, end); // ALTER
if (tok && (tok = get_tok(tok + len, &len, end)) // TABLE if (tok && (tok = get_tok(tok + len, &len, end)) // TABLE
&& (tok = get_tok(tok + len, &len, end))) // Table identifier && (tok = get_tok(tok + len, &len, end))) // Table identifier
{ {
snprintf(dest, size, "%.*s", len, tok); snprintf(dest, size, "%.*s", len, tok);
remove_backticks(dest); remove_backticks(dest);