I'm trying to run the following query via MariaDB Connector/C using a prepared statement:
SELECT * FROM customers WHERE ApiKey=?
However, mysql_stmt_execute() returns error code 1295:
This command is not supported in the prepared statement protocol yet
Below is the approximate code:
MYSQL mysql;
// ... Initialization of the connection
string query = "SELECT * FROM customers WHERE ApiKey=?";
MYSQL_STMT* pStmt = mysql_stmt_init(&mysql);
mysql_stmt_prepare(pStmt, query.c_str(), query.size());
constexpr const unsigned int nRows = 1;
unsigned long apiKeyLen[nRows] = { unsigned long(apiKey.size()) };
const char* pApiKey[nRows] = { apiKey.c_str() };
MYSQL_BIND bind[nParams];
memset(bind, 0, sizeof(bind));
bind[0].buffer_type = MYSQL_TYPE_STRING;
bind[0].buffer = pApiKey;
bind[0].length = apiKeyLen;
mysql_stmt_attr_set(pStmt, STMT_ATTR_ARRAY_SIZE, &nRows);
mysql_stmt_bind_param(pStmt, pBind);
mysql_stmt_execute(pStmt);
As the search on the internet doesn't give anything useful so far, I have finally found the culprit by means of exclusion. It's the call to
mysql_stmt_attr_set(pStmt, STMT_ATTR_ARRAY_SIZE, &nRows);. Apparently, this call only works forINSERTandUPDATEstatements and you must not call it when doing aSELECT.