c++ - 为什么这个插入给出语法错误

标签 c++ sql

res = PQexec(conn,"INSERT INTO worker (fullname,type) VALUES ('"ptr"',"type")");

type 是整数,ptr 是字符串。这里有什么问题?我该如何解决? “”是不是有问题

最佳答案

代替

res = PQexec(conn,"INSERT INTO worker (fullname,type) VALUES ('"ptr"',"type")");

使用字符串流创建字符串

#include <sstream>
std::stringstream ss;

ss << "INSERT INTO worker (fullname,type) VALUES ('" << ptr << "'," << type << ")";
res = PQexec(conn, ss.str().c_str() );

关于c++ - 为什么这个插入给出语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15765528/

相关文章:

sql - 我如何求和不同的行?

c# - NHibernate分层递归查询

html - SQL 查询内联表,打印到 HTML <select> 标签

android - 如何在 Android 中调用 onUpgrade() 以使用 sqlite 数据库

c++ - 如何正确处理信号,以便 gperftools CPU 分析器仍然有效?

c++ - 了解使用 # 的 C++ 宏

c++ - 转换 Classname::FunctionName( Para1, Para2 ) 中的符号

sql - MERGE 语句执行时间太长(仅针对 1 条记录)。 (MS-SQL Server 2012)

c++ - do while 循环中的 if 语句以 yes 或 no 结尾

c++ - 非模板函数中的 std::forward