mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-5273 Prepared statement doesn't return metadata after prepare.
Fix for SHOW CREATE DATABASE.
This commit is contained in:
@@ -1812,6 +1812,14 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool send_stmt_metadata(THD *thd, Prepared_statement *stmt, List<Item> *fields)
|
||||||
|
{
|
||||||
|
return send_prep_stmt(stmt, fields->elements) ||
|
||||||
|
thd->protocol->send_result_set_metadata(fields, Protocol::SEND_EOF) ||
|
||||||
|
thd->protocol->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Validate and prepare for execution SHOW CREATE TABLE statement.
|
Validate and prepare for execution SHOW CREATE TABLE statement.
|
||||||
|
|
||||||
@@ -1824,7 +1832,7 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
|
|||||||
TRUE error, error message is set in THD
|
TRUE error, error message is set in THD
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int mysql_test_show_create_table(Prepared_statement *stmt,
|
static bool mysql_test_show_create_table(Prepared_statement *stmt,
|
||||||
TABLE_LIST *tables)
|
TABLE_LIST *tables)
|
||||||
{
|
{
|
||||||
DBUG_ENTER("mysql_test_show_create_table");
|
DBUG_ENTER("mysql_test_show_create_table");
|
||||||
@@ -1833,22 +1841,31 @@ static int mysql_test_show_create_table(Prepared_statement *stmt,
|
|||||||
char buff[2048];
|
char buff[2048];
|
||||||
String buffer(buff, sizeof(buff), system_charset_info);
|
String buffer(buff, sizeof(buff), system_charset_info);
|
||||||
|
|
||||||
if (mysqld_show_create_get_fields(thd, tables, &fields, &buffer))
|
DBUG_RETURN(mysqld_show_create_get_fields(thd, tables, &fields, &buffer) ||
|
||||||
goto err_exit;
|
send_stmt_metadata(thd, stmt, &fields));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Validate and prepare for execution SHOW CREATE DATABASE statement.
|
||||||
|
|
||||||
|
@param stmt prepared statement
|
||||||
|
|
||||||
|
@retval
|
||||||
|
FALSE success
|
||||||
|
@retval
|
||||||
|
TRUE error, error message is set in THD
|
||||||
|
*/
|
||||||
|
|
||||||
|
static bool mysql_test_show_create_db(Prepared_statement *stmt)
|
||||||
|
{
|
||||||
|
DBUG_ENTER("mysql_test_show_create_db");
|
||||||
|
THD *thd= stmt->thd;
|
||||||
|
List<Item> fields;
|
||||||
|
|
||||||
|
mysqld_show_create_db_get_fields(thd, &fields);
|
||||||
|
|
||||||
if (!stmt->is_sql_prepare())
|
DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
|
||||||
{
|
|
||||||
if (send_prep_stmt(stmt, fields.elements) ||
|
|
||||||
thd->protocol->send_result_set_metadata(&fields, Protocol::SEND_EOF) ||
|
|
||||||
thd->protocol->flush())
|
|
||||||
goto err_exit;
|
|
||||||
|
|
||||||
DBUG_RETURN(2);
|
|
||||||
}
|
|
||||||
DBUG_RETURN(0);
|
|
||||||
|
|
||||||
err_exit:
|
|
||||||
DBUG_RETURN(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2186,8 +2203,14 @@ static bool check_prepared_statement(Prepared_statement *stmt)
|
|||||||
res= mysql_test_create_table(stmt);
|
res= mysql_test_create_table(stmt);
|
||||||
break;
|
break;
|
||||||
case SQLCOM_SHOW_CREATE:
|
case SQLCOM_SHOW_CREATE:
|
||||||
res= mysql_test_show_create_table(stmt, tables);
|
if (!(res= mysql_test_show_create_table(stmt, tables)))
|
||||||
if (res == 2)
|
{
|
||||||
|
/* Statement and field info has already been sent */
|
||||||
|
DBUG_RETURN(FALSE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SQLCOM_SHOW_CREATE_DB:
|
||||||
|
if (!(res= mysql_test_show_create_db(stmt)))
|
||||||
{
|
{
|
||||||
/* Statement and field info has already been sent */
|
/* Statement and field info has already been sent */
|
||||||
DBUG_RETURN(FALSE);
|
DBUG_RETURN(FALSE);
|
||||||
|
@@ -1272,6 +1272,19 @@ exit:
|
|||||||
DBUG_RETURN(error);
|
DBUG_RETURN(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mysqld_show_create_db_get_fields(THD *thd, List<Item> *field_list)
|
||||||
|
{
|
||||||
|
MEM_ROOT *mem_root= thd->mem_root;
|
||||||
|
field_list->push_back(new (mem_root)
|
||||||
|
Item_empty_string(thd, "Database", NAME_CHAR_LEN),
|
||||||
|
mem_root);
|
||||||
|
field_list->push_back(new (mem_root)
|
||||||
|
Item_empty_string(thd, "Create Database", 1024),
|
||||||
|
mem_root);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool mysqld_show_create_db(THD *thd, LEX_STRING *dbname,
|
bool mysqld_show_create_db(THD *thd, LEX_STRING *dbname,
|
||||||
LEX_STRING *orig_dbname,
|
LEX_STRING *orig_dbname,
|
||||||
const DDL_options_st &options)
|
const DDL_options_st &options)
|
||||||
@@ -1284,7 +1297,7 @@ bool mysqld_show_create_db(THD *thd, LEX_STRING *dbname,
|
|||||||
#endif
|
#endif
|
||||||
Schema_specification_st create;
|
Schema_specification_st create;
|
||||||
Protocol *protocol=thd->protocol;
|
Protocol *protocol=thd->protocol;
|
||||||
MEM_ROOT *mem_root= thd->mem_root;
|
List<Item> field_list;
|
||||||
DBUG_ENTER("mysql_show_create_db");
|
DBUG_ENTER("mysql_show_create_db");
|
||||||
|
|
||||||
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
||||||
@@ -1318,13 +1331,8 @@ bool mysqld_show_create_db(THD *thd, LEX_STRING *dbname,
|
|||||||
|
|
||||||
load_db_opt_by_name(thd, dbname->str, &create);
|
load_db_opt_by_name(thd, dbname->str, &create);
|
||||||
}
|
}
|
||||||
List<Item> field_list;
|
|
||||||
field_list.push_back(new (mem_root)
|
mysqld_show_create_db_get_fields(thd, &field_list);
|
||||||
Item_empty_string(thd, "Database", NAME_CHAR_LEN),
|
|
||||||
mem_root);
|
|
||||||
field_list.push_back(new (mem_root)
|
|
||||||
Item_empty_string(thd, "Create Database", 1024),
|
|
||||||
mem_root);
|
|
||||||
|
|
||||||
if (protocol->send_result_set_metadata(&field_list,
|
if (protocol->send_result_set_metadata(&field_list,
|
||||||
Protocol::SEND_NUM_ROWS |
|
Protocol::SEND_NUM_ROWS |
|
||||||
|
@@ -88,6 +88,7 @@ int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd);
|
|||||||
bool mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list,
|
bool mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list,
|
||||||
List<Item> *field_list, String *buffer);
|
List<Item> *field_list, String *buffer);
|
||||||
bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
|
bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
|
||||||
|
void mysqld_show_create_db_get_fields(THD *thd, List<Item> *field_list);
|
||||||
bool mysqld_show_create_db(THD *thd, LEX_STRING *db_name,
|
bool mysqld_show_create_db(THD *thd, LEX_STRING *db_name,
|
||||||
LEX_STRING *orig_db_name,
|
LEX_STRING *orig_db_name,
|
||||||
const DDL_options_st &options);
|
const DDL_options_st &options);
|
||||||
|
@@ -426,9 +426,14 @@ static void test_prepare_simple()
|
|||||||
strmov(query, "SHOW CREATE TABLE test_prepare_simple");
|
strmov(query, "SHOW CREATE TABLE test_prepare_simple");
|
||||||
stmt= mysql_simple_prepare(mysql, query);
|
stmt= mysql_simple_prepare(mysql, query);
|
||||||
check_stmt(stmt);
|
check_stmt(stmt);
|
||||||
|
|
||||||
DIE_UNLESS(mysql_stmt_field_count(stmt) == 2);
|
DIE_UNLESS(mysql_stmt_field_count(stmt) == 2);
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
|
/* show create database */
|
||||||
|
strmov(query, "SHOW CREATE DATABASE test");
|
||||||
|
stmt= mysql_simple_prepare(mysql, query);
|
||||||
|
check_stmt(stmt);
|
||||||
|
DIE_UNLESS(mysql_stmt_field_count(stmt) == 2);
|
||||||
mysql_stmt_close(stmt);
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
/* now fetch the results ..*/
|
/* now fetch the results ..*/
|
||||||
|
Reference in New Issue
Block a user