Bug #101614 mysql_stmt_prepare() does not return on query with "order by ?"
Description:
On MySQL 8.0.22, mysql_stmt_prepare() does not return on query with "order by ?".
How to repeat:
mysql> create database test;
mysql> use test;
mysql> create table t (id int auto_increment primary key, n int);
mysql> insert into t values (1,5),(2,4),(3,3),(4,2),(5,1);
--- test.c ---
#include <stdio.h>
#include <string.h>
#include <mysql/mysql.h>
int main(int argc, char *argv[])
{
MYSQL my;
MYSQL_STMT *st;
MYSQL_BIND bind[1], bind2[2];
memset(bind, 0, sizeof(bind));
memset(bind2, 0, sizeof(bind2));
mysql_init(&my);
if (mysql_real_connect(&my, "127.0.0.1", "root", "", "test", 0, NULL, 0) == NULL)
goto error;
if ((st = mysql_stmt_init(&my)) == NULL)
goto error;
char *q = "select id,n from t order by ?";
mysql_stmt_prepare(st, q, strlen(q));
long n = 2;
bind[0].buffer_type = MYSQL_TYPE_LONG;
bind[0].buffer = &n;
bind[0].length = NULL;
bind[0].buffer_length = sizeof(n);
bind[0].is_null = 0;
if (mysql_stmt_bind_param(st, bind) != 0)
goto stmt_error;
if (mysql_stmt_execute(st) != 0)
goto stmt_error;
long id = 0;
bind2[0].buffer_type = MYSQL_TYPE_LONG;
bind2[0].buffer = &id;
bind2[0].buffer_length = sizeof(id);
bind2[0].length = NULL;
bind2[1].buffer_type = MYSQL_TYPE_LONG;
bind2[1].buffer = &n;
bind2[1].buffer_length = sizeof(n);
bind2[1].length = NULL;
if (mysql_stmt_bind_result(st, bind2) != 0)
goto stmt_error;
if (mysql_stmt_store_result(st) != 0)
goto stmt_error;
while (mysql_stmt_fetch(st) == 0) {
printf("%ld %ld\n", id, n);
}
exit(0);
error:
puts(mysql_error(&my));
exit(1);
stmt_error:
puts(mysql_stmt_error(st));
exit(1);
}
---
% gcc test.c -lmysqlclient
% ./a.out
On 8.0.21:
5 1
4 2
3 3
2 4
1 5
On 8.0.22:
(no reply)
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: On MySQL 8.0.22, mysql_stmt_prepare() does not return on query with "order by ?". How to repeat: mysql> create database test; mysql> use test; mysql> create table t (id int auto_increment primary key, n int); mysql> insert into t values (1,5),(2,4),(3,3),(4,2),(5,1); --- test.c --- #include <stdio.h> #include <string.h> #include <mysql/mysql.h> int main(int argc, char *argv[]) { MYSQL my; MYSQL_STMT *st; MYSQL_BIND bind[1], bind2[2]; memset(bind, 0, sizeof(bind)); memset(bind2, 0, sizeof(bind2)); mysql_init(&my); if (mysql_real_connect(&my, "127.0.0.1", "root", "", "test", 0, NULL, 0) == NULL) goto error; if ((st = mysql_stmt_init(&my)) == NULL) goto error; char *q = "select id,n from t order by ?"; mysql_stmt_prepare(st, q, strlen(q)); long n = 2; bind[0].buffer_type = MYSQL_TYPE_LONG; bind[0].buffer = &n; bind[0].length = NULL; bind[0].buffer_length = sizeof(n); bind[0].is_null = 0; if (mysql_stmt_bind_param(st, bind) != 0) goto stmt_error; if (mysql_stmt_execute(st) != 0) goto stmt_error; long id = 0; bind2[0].buffer_type = MYSQL_TYPE_LONG; bind2[0].buffer = &id; bind2[0].buffer_length = sizeof(id); bind2[0].length = NULL; bind2[1].buffer_type = MYSQL_TYPE_LONG; bind2[1].buffer = &n; bind2[1].buffer_length = sizeof(n); bind2[1].length = NULL; if (mysql_stmt_bind_result(st, bind2) != 0) goto stmt_error; if (mysql_stmt_store_result(st) != 0) goto stmt_error; while (mysql_stmt_fetch(st) == 0) { printf("%ld %ld\n", id, n); } exit(0); error: puts(mysql_error(&my)); exit(1); stmt_error: puts(mysql_stmt_error(st)); exit(1); } --- % gcc test.c -lmysqlclient % ./a.out On 8.0.21: 5 1 4 2 3 3 2 4 1 5 On 8.0.22: (no reply)