【问题标题】:postgresql libpqxx Several queries as one transactionpostgresql libpqxx 多个查询作为一个事务
【发布时间】:2015-12-25 08:43:51
【问题描述】:

是否可以执行一个事务包含多个查询,例如insert smth in table1和insert smth in table2?我该如何实现呢?我使用libpqxx 与数据库进行交互并期待与此相关的答案。谢谢。

【问题讨论】:

    标签: postgresql libpqxx


    【解决方案1】:

    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();
    ...   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      相关资源
      最近更新 更多