Fix avro regression
The fact whether a query explicitly defined a query was ignored by the statement parsing function and it always assumed the database was explicitly defined. This caused the TABLE keyword in a CREATE TABLE statement to be falsely identified as the current database.
This commit is contained in:
@ -403,10 +403,12 @@ static bool get_table_name(const char* sql, char* dest)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the database name from a CREATE TABLE statement
|
* Extract the database name from a CREATE TABLE statement
|
||||||
|
*
|
||||||
* @param sql SQL statement
|
* @param sql SQL statement
|
||||||
* @param dest Destination where the database name is extracted. Must be at least
|
* @param dest Destination where the database name is extracted. Must be at least
|
||||||
* MYSQL_DATABASE_MAXLEN bytes long.
|
* MYSQL_DATABASE_MAXLEN bytes long.
|
||||||
* @return True if extraction was successful
|
*
|
||||||
|
* @return True if a database name was extracted
|
||||||
*/
|
*/
|
||||||
static bool get_database_name(const char* sql, char* dest)
|
static bool get_database_name(const char* sql, char* dest)
|
||||||
{
|
{
|
||||||
@ -426,6 +428,10 @@ static bool get_database_name(const char* sql, char* dest)
|
|||||||
ptr--;
|
ptr--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*ptr == '.')
|
||||||
|
{
|
||||||
|
// The query defines an explicit database
|
||||||
|
|
||||||
while (*ptr == '`' || *ptr == '.' || isspace(*ptr))
|
while (*ptr == '`' || *ptr == '.' || isspace(*ptr))
|
||||||
{
|
{
|
||||||
ptr--;
|
ptr--;
|
||||||
@ -443,6 +449,7 @@ static bool get_database_name(const char* sql, char* dest)
|
|||||||
dest[end - ptr] = '\0';
|
dest[end - ptr] = '\0';
|
||||||
rval = true;
|
rval = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
@ -717,13 +724,15 @@ TABLE_CREATE* table_create_alloc(const char* sql, int len, const char* db)
|
|||||||
{
|
{
|
||||||
err = "table name";
|
err = "table name";
|
||||||
}
|
}
|
||||||
/** The CREATE statement contains the database name */
|
|
||||||
if (get_database_name(sql, database))
|
if (get_database_name(sql, database))
|
||||||
{
|
{
|
||||||
|
// The CREATE statement contains the database name
|
||||||
db = database;
|
db = database;
|
||||||
}
|
}
|
||||||
else if (*db == '\0')
|
else if (*db == '\0')
|
||||||
{
|
{
|
||||||
|
// No explicit or current database
|
||||||
err = "database name";
|
err = "database name";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user