aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/libpqxx/src/subtransaction.cxx
blob: 539c3c7847e21e831c80792313df1b68db1bf40d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/** Implementation of the pqxx::subtransaction class.
 *
 * pqxx::transaction is a nested transaction, i.e. one within a transaction
 *
 * Copyright (c) 2000-2019, Jeroen T. Vermeulen.
 *
 * See COPYING for copyright license.  If you did not receive a file called
 * COPYING with this source code, please notify the distributor of this mistake,
 * or contact the author.
 */
#include "pqxx/compiler-internal.hxx"

#include <stdexcept>

#include "pqxx/connection_base"
#include "pqxx/subtransaction"

#include "pqxx/internal/gates/transaction-subtransaction.hxx"

using namespace pqxx::internal;


pqxx::subtransaction::subtransaction(
	dbtransaction &T,
	const std::string &Name) :
  namedclass{"subtransaction", T.conn().adorn_name(Name)},
  transactionfocus{T},
  dbtransaction(T.conn(), false),
  m_parent{T}
{
}


namespace
{
using dbtransaction_ref = pqxx::dbtransaction &;
}


pqxx::subtransaction::subtransaction(
	subtransaction &T,
	const std::string &Name) :
  subtransaction(dbtransaction_ref(T), Name)
{
}


void pqxx::subtransaction::do_begin()
{
  try
  {
    direct_exec(("SAVEPOINT " + quote_name(name())).c_str());
  }
  catch (const sql_error &)
  {
    throw;
  }
}


void pqxx::subtransaction::do_commit()
{
  const int ra = m_reactivation_avoidance.get();
  m_reactivation_avoidance.clear();
  direct_exec(("RELEASE SAVEPOINT " + quote_name(name())).c_str());
  gate::transaction_subtransaction{m_parent}.add_reactivation_avoidance_count(
	ra);
}


void pqxx::subtransaction::do_abort()
{
  direct_exec(("ROLLBACK TO SAVEPOINT " + quote_name(name())).c_str());
}