I did some further digging.

I realized that the error doesn't occur when I use libmysql from mysql-devel instead of mariadb-connector-c-devel.
So, it seems that his is not an issue between libzdb and ProxySQL but rather with some incompatibilities between MariaDB client libs and ProxySQL...

I then found this here, which confirms it: https://github.com/sysown/proxysql/issues/4227

Case closed!

Best regards
Till

June 23, 2025 5:50 AM, g4-lisz@tonarchiv.ch wrote:
Hello again!

I found the problem:

It seems that ProxySQL has an issue with the CURSOR_TYPE_READ_ONLY option:

#if MYSQL_VERSION_ID >= 50002
unsigned long cursor = CURSOR_TYPE_READ_ONLY;
mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &cursor);
#endif

If I comment these lines, all works fine!

I'm using ProxySQL v 2.7.3

Cheers,
Till

June 23, 2025 3:39 AM, g4-lisz@tonarchiv.ch wrote:

Hi there,

I wrote an application using libzdb, which works fine when I connect directly to a MySQL server.

But when I connect to ProxySQL I get this error when doing a Connection_executeQuery():

SQLException: Commands out of sync; you can't run this command now
raised in Connection_executeQuery at src/db/Connection.c:335

It's a very basic select: "SELECT * FROM instance".

When I do the same with libmysql (acutally it's libmariadb), there's no issue.

This is the test code:

#include <stdio.h>
#include <zdb.h>

main() {
URL_T url = URL_new("mysql://sbuser:sbpass@127.0.0.1:6033/cpr_db");
ConnectionPool_T pool = ConnectionPool_new(url);
ConnectionPool_start(pool);

Connection_T con = ConnectionPool_getConnection(pool);
ResultSet_T result = Connection_executeQuery(con, "SELECT * FROM instance");
while (ResultSet_next(result))
{
int id = ResultSet_getInt(result, 1);
printf("%d\n", id);
}
Connection_close(con);

ConnectionPool_free(&pool);
URL_free(&url);
}

Any idea what is the issue here?

Cheers
Till