/usr/include/mysql++/transaction.h is in libmysql++-dev 3.2.1+pristine-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | /// \file transaction.h
/// \brief Declares the Transaction class.
///
/// This object works with the Connection class to automate the use of
/// MySQL transactions. It allows you to express these transactions
/// directly in C++ code instead of sending the raw SQL commands.
/***********************************************************************
Copyright (c) 2006-2009 by Educational Technology Resources, Inc. and
(c) 2008 by AboveNet, Inc. Others may also hold copyrights on code
in this file. See the CREDITS.txt file in the top directory of the
distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#if !defined(MYSQLPP_TRANSACTION_H)
#define MYSQLPP_TRANSACTION_H
#include "common.h"
namespace mysqlpp {
#if !defined(DOXYGEN_IGNORE)
// Make Doxygen ignore this
class MYSQLPP_EXPORT Connection;
#endif
/// \brief Helper object for creating exception-safe SQL transactions.
class MYSQLPP_EXPORT Transaction
{
public:
/// \brief Transaction isolation levels defined in SQL
///
/// These values can be passed to one of the Transaction
/// constructors to change the way the database engine protects
/// transactions from other DB updates. These values are in order
/// of increasing isolation, but decreasing performance.
enum IsolationLevel {
read_uncommitted, ///< allow "dirty reads" from other transactions
read_committed, ///< only read rows committed by other transactions
repeatable_read, ///< other transactions do not affect repeated reads in this transaction
serializable ///< this transaction prevents writes to any rows it accesses while it runs
};
/// \brief Isolation level scopes defined in SQL
///
/// These values are only used with one of the Transaction
/// constructors, to select which transaction(s) our change to
// the isolation scope will affect.
enum IsolationScope {
this_transaction, ///< change level for this transaction only
session, ///< change level for all transactions in this session
global ///< change level for all transactions on the DB server
};
/// \brief Simple constructor
///
/// \param conn The connection we use to manage the transaction set
/// \param consistent Whether to use "consistent snapshots" during
/// the transaction. See the documentation for "START TRANSACTION"
/// in the MySQL manual for more on this.
Transaction(Connection& conn, bool consistent = false);
/// \brief Constructor allowing custom transaction isolation level
/// and scope
///
/// \param conn The connection we use to manage the transaction set
/// \param level Isolation level to use for this transaction
/// \param scope Selects the scope of the isolation level change
/// \param consistent Whether to use "consistent snapshots" during
/// the transaction. See the documentation for "START TRANSACTION"
/// in the MySQL manual for more on this.
Transaction(Connection& conn, IsolationLevel level,
IsolationScope scope = this_transaction,
bool consistent = false);
/// \brief Destructor
///
/// If the transaction has not been committed or rolled back by the
/// time the destructor is called, it is rolled back. This is the
/// right thing because one way this can happen is if the object is
/// being destroyed as the stack is unwound to handle an exception.
/// In that instance, you certainly want to roll back the
/// transaction.
~Transaction();
/// \brief Commits the transaction
///
/// This commits all updates to the database using the connection
/// we were created with since this object was created. This is a
/// no-op if the table isn't stored using a transaction-aware
/// storage engine. See CREATE TABLE in the MySQL manual for
/// details.
void commit();
/// \brief Rolls back the transaction
///
/// This abandons all SQL statements made on the connection since
/// this object was created. This only works on tables stored using
/// a transaction-aware storage engine. See CREATE TABLE in the
/// MySQL manual for details.
void rollback();
private:
Connection& conn_; ///! Connection to send queries through
bool finished_; ///! True when we commit or roll back xaction
};
/// \brief Compile-time substitute for Transaction, which purposely
/// does nothing. Use it to instantiate templates that take Transaction
/// when you don't want transactions to be used.
///
/// This was created for use with InsertPolicy, used by
/// Query::insertfrom(). You might use it when your code already
/// wraps a given sequence of MySQL++ calls in a transaction and does
/// an insertfrom() as part of that. MySQL doesn't support nested
/// transactions, so you need to suppress the one insertfrom() would
/// normally start.
class MYSQLPP_EXPORT NoTransaction
{
public:
/// \brief Constructor
NoTransaction(Connection&, bool = false)
{
}
/// \brief Destructor
~NoTransaction() { }
/// \brief stub to replace Transaction::commit()
void commit() { }
/// \brief stub to replace Transaction::rollback()
void rollback() { }
};
} // end namespace mysqlpp
#endif // !defined(MYSQLPP_TRANSACTION_H)
|