【发布时间】:2015-12-25 08:43:51
【问题描述】:
是否可以执行一个事务包含多个查询,例如insert smth in table1和insert smth in table2?我该如何实现呢?我使用libpqxx 与数据库进行交互并期待与此相关的答案。谢谢。
【问题讨论】:
标签: postgresql libpqxx
是否可以执行一个事务包含多个查询,例如insert smth in table1和insert smth in table2?我该如何实现呢?我使用libpqxx 与数据库进行交互并期待与此相关的答案。谢谢。
【问题讨论】:
标签: postgresql libpqxx
pqxx::work 是默认事务类型。
在commit() 之前使用多个exec() 方法在一个事务中运行多个查询:
using namespace pqxx;
...
connection c("dbname=test user=postgres hostaddr=127.0.0.1");
work w(c);
w.exec("create table test_xx (id int primary key)");
w.exec("insert into test_xx values (1)");
w.commit();
...
【讨论】: