2

我正在尝试使用准备好的语句通过 MariaDB Connector/C 运行以下查询:

SELECT * FROM customers WHERE ApiKey=?

但是,mysql_stmt_execute()返回错误代码1295

准备好的语句协议尚不支持此命令

下面是大概的代码:

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);
4

1 回答 1

2

由于到目前为止在互联网上的搜索没有给出任何有用的信息,我终于通过排除找到了罪魁祸首。这是对mysql_stmt_attr_set(pStmt, STMT_ATTR_ARRAY_SIZE, &nRows);. 显然,这个调用只适用于INSERTandUPDATE语句,你不能在做 a 时调用它SELECT

于 2020-05-14T20:33:59.510 回答