C++ 通过libpqxx向PostgreSQL插入数据时出现问题
我有一个名为mydb的数据库,它有一个表Peopleid,name 我想使用pqxx C++接口将这个表插入到一个行中。 SQL查询非常简单,可以插入到人员id、名称值1、Bob中 < C++代码在这里:C++ 通过libpqxx向PostgreSQL插入数据时出现问题,c++,database,postgresql,libpqxx,C++,Database,Postgresql,Libpqxx,我有一个名为mydb的数据库,它有一个表Peopleid,name 我想使用pqxx C++接口将这个表插入到一个行中。 SQL查询非常简单,可以插入到人员id、名称值1、Bob中 < C++代码在这里: #include <pqxx/pqxx> using namespace std; int main(int, char *argv[]) { pqxx::connection conn( /* some stuff here */ ); conn.prepare("
#include <pqxx/pqxx>
using namespace std;
int main(int, char *argv[])
{
pqxx::connection conn( /* some stuff here */ );
conn.prepare("insert_to_people", "insert into people (id, name) values ($1, $2);");
pqxx::work pq(conn);
pq.prepared("insert_to_people")(1)("Bob").exec();
pq.commit();
return 0;
}
什么是错误的? < P> >我用C++已经有几年了!查看文档,似乎需要声明参数类型?也许这会奏效:
conn.prepare("insert_to_people", "insert into people (id, name) values ($1, $2)")("integer")("varchar", pqxx::prepare::treat_string);
还有一个尾随;在查询中。我不认为它会痛,但它是不必要的
-g
conn.prepare("insert_to_people", "insert into people (id, name) values ($1, $2)")("integer")("varchar", pqxx::prepare::treat_string);