# pqxx::subtransaction Class Reference

"Transaction" nested within another transaction More...

`#include <subtransaction.hxx>`

Inheritance diagram for pqxx::subtransaction:

[legend]

List of all members.

## Public Member Functions
| subtransaction (dbtransaction &T, const std::string &Name=std::string())

## Detailed Description

"Transaction" nested within another transaction

A subtransaction can be executed inside a backend transaction, or inside another subtransaction. This can be useful when, for example, statements in a transaction may harmlessly fail and you don't want them to abort the entire transaction. Here's an example of how a temporary table may be dropped before re-creating it, without failing if the table did not exist:

     void do_job(connection_base &C)
     {
       const string temptable = "fleetingtable";

       // Since we're dealing with a temporary table here, disallow automatic
       // recovery of the connection in case it breaks.
       C.inhibit_reactivation(true);

       work W(C, "do_job");
       do_firstpart(W);

       // Attempt to delete our temporary table if it already existed
       try
       {
         subtransaction S(W, "droptemp");
         W.exec("DROP TABLE " + temptable);
       }
       catch (const undefined_table &)
       {
         // Table did not exist.  Which is what we were hoping to achieve anyway.
         // Carry on without regrets.
       }

       W.exec("CREATE TEMP TABLE " + fleetingtable +
              "(bar integer, splat varchar)");

       do_lastpart(W);
     }

There are no isolation levels inside a transaction. They are not needed because all actions within the same backend transaction are always performed sequentially anyway.

## Constructor & Destructor Documentation

pqxx::subtransaction::subtransaction | ( | dbtransaction & | T,
|  | const std::string & | Name = `std ::string()` |
| ) |  |  | `[explicit]`

The documentation for this class was generated from the following files:

- subtransaction.hxx
- subtransaction.cxx