我有一个mydb
用 table调用的数据库People(id, name)
。
我想使用 pqxx C++ 接口在该表中插入一行。
SQL查询非常简单INSERT INTO people (id, name) VALUES (1, "Bob");
C++ 代码在这里:
#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;
}
但我得到以下异常:
terminate called after throwing an instance of 'pqxx::usage_error'
what(): Too many arguments for prepared statement insert_to_people: expected 0, received 2
Aborted (core dumped)
怎么了?