Skip to content

Commit 11c85e1

Browse files
author
Alexey Botchkov
committed
MDEV-5273 Prepared statement doesn't return metadata after prepare.
The SQL command 'PREPARE' was broken - should be take into account.
1 parent 418518c commit 11c85e1

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

sql/sql_prepare.cc

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,11 +1814,17 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
18141814
}
18151815

18161816

1817-
static bool send_stmt_metadata(THD *thd, Prepared_statement *stmt, List<Item> *fields)
1817+
static int send_stmt_metadata(THD *thd, Prepared_statement *stmt, List<Item> *fields)
18181818
{
1819-
return send_prep_stmt(stmt, fields->elements) ||
1820-
thd->protocol->send_result_set_metadata(fields, Protocol::SEND_EOF) ||
1821-
thd->protocol->flush();
1819+
if (stmt->is_sql_prepare())
1820+
return 0;
1821+
1822+
if (send_prep_stmt(stmt, fields->elements) ||
1823+
thd->protocol->send_result_set_metadata(fields, Protocol::SEND_EOF) ||
1824+
thd->protocol->flush())
1825+
return 1;
1826+
1827+
return 2;
18221828
}
18231829

18241830

@@ -1834,7 +1840,7 @@ static bool send_stmt_metadata(THD *thd, Prepared_statement *stmt, List<Item> *f
18341840
TRUE error, error message is set in THD
18351841
*/
18361842

1837-
static bool mysql_test_show_create_table(Prepared_statement *stmt,
1843+
static int mysql_test_show_create_table(Prepared_statement *stmt,
18381844
TABLE_LIST *tables)
18391845
{
18401846
DBUG_ENTER("mysql_test_show_create_table");
@@ -1843,8 +1849,10 @@ static bool mysql_test_show_create_table(Prepared_statement *stmt,
18431849
char buff[2048];
18441850
String buffer(buff, sizeof(buff), system_charset_info);
18451851

1846-
DBUG_RETURN(mysqld_show_create_get_fields(thd, tables, &fields, &buffer) ||
1847-
send_stmt_metadata(thd, stmt, &fields));
1852+
if (mysqld_show_create_get_fields(thd, tables, &fields, &buffer))
1853+
DBUG_RETURN(1);
1854+
1855+
DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
18481856
}
18491857

18501858

@@ -1859,7 +1867,7 @@ static bool mysql_test_show_create_table(Prepared_statement *stmt,
18591867
TRUE error, error message is set in THD
18601868
*/
18611869

1862-
static bool mysql_test_show_create_db(Prepared_statement *stmt)
1870+
static int mysql_test_show_create_db(Prepared_statement *stmt)
18631871
{
18641872
DBUG_ENTER("mysql_test_show_create_db");
18651873
THD *thd= stmt->thd;
@@ -1883,7 +1891,7 @@ static bool mysql_test_show_create_db(Prepared_statement *stmt)
18831891
TRUE error, error message is set in THD
18841892
*/
18851893

1886-
static bool mysql_test_show_grants(Prepared_statement *stmt)
1894+
static int mysql_test_show_grants(Prepared_statement *stmt)
18871895
{
18881896
DBUG_ENTER("mysql_test_show_grants");
18891897
THD *thd= stmt->thd;
@@ -1908,7 +1916,7 @@ static bool mysql_test_show_grants(Prepared_statement *stmt)
19081916
TRUE error, error message is set in THD
19091917
*/
19101918

1911-
static bool mysql_test_show_slave_status(Prepared_statement *stmt)
1919+
static int mysql_test_show_slave_status(Prepared_statement *stmt)
19121920
{
19131921
DBUG_ENTER("mysql_test_show_slave_status");
19141922
THD *thd= stmt->thd;
@@ -1931,7 +1939,7 @@ static bool mysql_test_show_slave_status(Prepared_statement *stmt)
19311939
TRUE error, error message is set in THD
19321940
*/
19331941

1934-
static bool mysql_test_show_master_status(Prepared_statement *stmt)
1942+
static int mysql_test_show_master_status(Prepared_statement *stmt)
19351943
{
19361944
DBUG_ENTER("mysql_test_show_master_status");
19371945
THD *thd= stmt->thd;
@@ -1954,7 +1962,7 @@ static bool mysql_test_show_master_status(Prepared_statement *stmt)
19541962
TRUE error, error message is set in THD
19551963
*/
19561964

1957-
static bool mysql_test_show_binlogs(Prepared_statement *stmt)
1965+
static int mysql_test_show_binlogs(Prepared_statement *stmt)
19581966
{
19591967
DBUG_ENTER("mysql_test_show_binlogs");
19601968
THD *thd= stmt->thd;
@@ -1979,7 +1987,7 @@ static bool mysql_test_show_binlogs(Prepared_statement *stmt)
19791987
TRUE error, error message is set in THD
19801988
*/
19811989

1982-
static bool mysql_test_show_create_routine(Prepared_statement *stmt, int type)
1990+
static int mysql_test_show_create_routine(Prepared_statement *stmt, int type)
19831991
{
19841992
DBUG_ENTER("mysql_test_show_binlogs");
19851993
THD *thd= stmt->thd;
@@ -2325,22 +2333,22 @@ static bool check_prepared_statement(Prepared_statement *stmt)
23252333
res= mysql_test_create_table(stmt);
23262334
break;
23272335
case SQLCOM_SHOW_CREATE:
2328-
if (!(res= mysql_test_show_create_table(stmt, tables)))
2336+
if ((res= mysql_test_show_create_table(stmt, tables)) == 2)
23292337
{
23302338
/* Statement and field info has already been sent */
23312339
DBUG_RETURN(FALSE);
23322340
}
23332341
break;
23342342
case SQLCOM_SHOW_CREATE_DB:
2335-
if (!(res= mysql_test_show_create_db(stmt)))
2343+
if ((res= mysql_test_show_create_db(stmt)) == 2)
23362344
{
23372345
/* Statement and field info has already been sent */
23382346
DBUG_RETURN(FALSE);
23392347
}
23402348
break;
23412349
#ifndef NO_EMBEDDED_ACCESS_CHECKS
23422350
case SQLCOM_SHOW_GRANTS:
2343-
if (!(res= mysql_test_show_grants(stmt)))
2351+
if ((res= mysql_test_show_grants(stmt)) == 2)
23442352
{
23452353
/* Statement and field info has already been sent */
23462354
DBUG_RETURN(FALSE);
@@ -2349,36 +2357,36 @@ static bool check_prepared_statement(Prepared_statement *stmt)
23492357
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
23502358
#ifndef EMBEDDED_LIBRARY
23512359
case SQLCOM_SHOW_SLAVE_STAT:
2352-
if (!(res= mysql_test_show_slave_status(stmt)))
2360+
if ((res= mysql_test_show_slave_status(stmt)) == 2)
23532361
{
23542362
/* Statement and field info has already been sent */
23552363
DBUG_RETURN(FALSE);
23562364
}
23572365
break;
23582366
case SQLCOM_SHOW_MASTER_STAT:
2359-
if (!(res= mysql_test_show_master_status(stmt)))
2367+
if ((res= mysql_test_show_master_status(stmt)) == 2)
23602368
{
23612369
/* Statement and field info has already been sent */
23622370
DBUG_RETURN(FALSE);
23632371
}
23642372
break;
23652373
case SQLCOM_SHOW_BINLOGS:
2366-
if (!(res= mysql_test_show_binlogs(stmt)))
2374+
if ((res= mysql_test_show_binlogs(stmt)) == 2)
23672375
{
23682376
/* Statement and field info has already been sent */
23692377
DBUG_RETURN(FALSE);
23702378
}
23712379
break;
23722380
#endif /* EMBEDDED_LIBRARY */
23732381
case SQLCOM_SHOW_CREATE_PROC:
2374-
if (!(res= mysql_test_show_create_routine(stmt, TYPE_ENUM_PROCEDURE)))
2382+
if ((res= mysql_test_show_create_routine(stmt, TYPE_ENUM_PROCEDURE)) == 2)
23752383
{
23762384
/* Statement and field info has already been sent */
23772385
DBUG_RETURN(FALSE);
23782386
}
23792387
break;
23802388
case SQLCOM_SHOW_CREATE_FUNC:
2381-
if (!(res= mysql_test_show_create_routine(stmt, TYPE_ENUM_FUNCTION)))
2389+
if ((res= mysql_test_show_create_routine(stmt, TYPE_ENUM_FUNCTION)) == 2)
23822390
{
23832391
/* Statement and field info has already been sent */
23842392
DBUG_RETURN(FALSE);

0 commit comments

Comments
 (0)