How to get after executing INSERT into database fe

2019-06-26 07:55发布

I am using c++11 and pqxx to access postgresql database and I need id of inserted row and flag if it was successful or not. How to get after executing INSERT into database fetch id of inserted row ? I have tried to find example on net but without success.

work txn(*conn);
txn.prepared("insert ")(person_name).exec();
txn.commit();

1条回答
Deceive 欺骗
2楼-- · 2019-06-26 08:10
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>();
查看更多
登录 后发表回答