pg_async
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
transaction.hpp
Go to the documentation of this file.
1 
8 #ifndef TIP_DB_PG_DETAIL_CONNECTION_LOCK_HPP_
9 #define TIP_DB_PG_DETAIL_CONNECTION_LOCK_HPP_
10 
11 #include <memory>
12 #include <functional>
13 #include <tip/db/pg/common.hpp>
14 
15 namespace tip {
16 namespace db {
17 namespace pg {
18 class basic_connection;
19 
29 class transaction : public std::enable_shared_from_this< transaction > {
30 public:
31  typedef std::shared_ptr<basic_connection> connection_ptr;
32  typedef basic_connection* pointer;
33  typedef basic_connection const* const_pointer;
34 public:
36  ~transaction();
37 
38  transaction(transaction const&) = delete;
40  operator = (transaction const&) = delete;
41  transaction(transaction&&) = delete;
43  operator = (transaction&&) = delete;
44 
46 
47  pointer
49  {
50  return connection_.get();
51  }
53  operator-> () const
54  {
55  return connection_.get();
56  }
57 
58  pointer
60  {
61  return connection_.get();
62  }
64  operator* () const
65  {
66  return connection_.get();
67  }
69 
70  dbalias const&
71  alias() const;
72 
73  bool
74  in_transaction() const;
75 
76  void
77  commit();
78  void
79  rollback();
80 
81  void
84  void
85  execute(std::string const& query, type_oid_sequence const& param_types,
86  std::vector< byte > params_buffer,
88 private:
89  void
90  handle_results(resultset, bool, query_result_callback);
91  void
92  handle_query_error(error::query_error const&, query_error_callback);
93  connection_ptr connection_;
94  bool finished_;
95 };
96 
97 } /* namespace pg */
98 } /* namespace db */
99 } /* namespace tip */
100 
101 #endif /* TIP_DB_PG_DETAIL_CONNECTION_LOCK_HPP_ */
std::shared_ptr< basic_connection > connection_ptr
Definition: common.hpp:341
bool in_transaction() const
Short unique string to refer a database. Signature structure, to pass instead of connection string...
Definition: common.hpp:209
dbalias const & alias() const
RAII transaction object.
Definition: transaction.hpp:29
Asynchronous query class.
Definition: query.hpp:51
void execute(std::string const &query, query_result_callback, query_error_callback)
basic_connection const * const_pointer
Definition: transaction.hpp:33
std::shared_ptr< basic_connection > connection_ptr
Definition: transaction.hpp:31
basic_connection * pointer
Definition: transaction.hpp:32
An error generated by the PostgreSQL server when executing a query.
Definition: error.hpp:49
std::function< void(error::query_error const &) > query_error_callback
Callback for a query error.
Definition: common.hpp:357
transaction(connection_ptr)
std::vector< oids::type::oid_type > type_oid_sequence
Definition: common.hpp:346
std::function< void(transaction_ptr, resultset, bool) > query_result_callback
Callback for query results.
Definition: common.hpp:355
transaction & operator=(transaction const &)=delete