Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 执行INSERT into数据库后如何获取插入行的fetch id?_C++_Postgresql_C++11_Libpqxx - Fatal编程技术网

C++ 执行INSERT into数据库后如何获取插入行的fetch id?

C++ 执行INSERT into数据库后如何获取插入行的fetch id?,c++,postgresql,c++11,libpqxx,C++,Postgresql,C++11,Libpqxx,我正在使用c++11和pqxx访问postgresql数据库,我需要插入行的id和标志,看是否成功。 执行INSERT into数据库后如何获取插入行的fetch id? 我曾试图在网上找到榜样,但没有成功 work txn(*conn); txn.prepared("insert ")(person_name).exec(); txn.commit(); 工作txn(*conn); pqxx::result r=txn.prepared(“插入t(a,b,c)值(1,2,$1)返回id”)(

我正在使用c++11和pqxx访问postgresql数据库,我需要插入行的id和标志,看是否成功。 执行INSERT into数据库后如何获取插入行的fetch id? 我曾试图在网上找到榜样,但没有成功

work txn(*conn);
txn.prepared("insert ")(person_name).exec();
txn.commit();
工作txn(*conn);
pqxx::result r=txn.prepared(“插入t(a,b,c)值(1,2,$1)返回id”)(person_name).exec();
提交();
int id=r[0][0].as();

插入。。。返回
work txn(*conn);
pqxx::result r = txn.prepared("insert into t (a,b,c) values (1,2,$1) returning id")(person_name).exec();
txn.commit();
int id = r[0][0].as<int>();