mysqlpp : SQL syntax error when using template queries

标签 mysql sql mysql++

我尝试使用模板查询来构建我的 SQL 查询。这是示例代码:

unsigned int version = 2;
try {
    // key_version is INT UNSIGNED
    mysqlpp::Query query = conn->query("SELECT * FROM agentlist WHERE key_version != %0q");
    mysqlpp::StoreQueryResult res = query.store(version);
    // string type param also caused the same problem
    // mysqlpp::StoreQueryResult res = query.store(std::to_string(version));
} catch (const exception &ex) {
    // deal with exceptions
}

代码将转到catch部分。 ex.what():

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'2\' at line 1

我认为这是由 SQLQueryParms 类型引起的,但教程和文档都没有显示任何解决此问题的方法。

顺便说一句,如何获取解析的查询字符串(替换模板参数)?我尝试了 query.str(version) 但它与 query.str() 相同。

最佳答案

我的错。忘记了一个重要的函数调用 query.parse()

现在一切正常了。

关于mysqlpp : SQL syntax error when using template queries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46767045/

相关文章:

php - 统计同一个表的某个状态列出现的频率

mysql - 多个 JOIN 太复杂

mysql - 修复损坏的 UTF8 字符 MYSQL

c# - 我在 SQL 中发现一对(零或一) Entity Framework 关系的重复行 - 如何/为什么?

c++ - 为什么简单的 mysql++ 代码可以独立编译,但不能在项目中编译?

mysql - 在多行上使用多个 IN 子句进行查询

sql - 从 prestodb 中选择多个列的不同列

sql - 最快日期有条件加入 - SQL Server 2017

c++ - 尝试连接到 google-cloud 中的 MariaDB 数据库但无法连接不显示任何错误报告

c - mysql 和 c -- 在查询中使用变量