session.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2008 Maciej Sobczak, Stephen Hutton
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 #ifndef SOCI_SESSION_H_INCLUDED
8 #define SOCI_SESSION_H_INCLUDED
9 
10 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
11 
12 #include "once-temp-type.h"
13 #include "query_transformation.h"
14 #include "connection-parameters.h"
15 
16 // std
17 #include <cstddef>
18 #include <memory>
19 #include <ostream>
20 #include <sstream>
21 #include <string>
22 
23 namespace soci
24 {
25 class values;
26 class backend_factory;
27 
28 namespace details
29 {
30 
31 class session_backend;
32 class statement_backend;
33 class rowid_backend;
34 class blob_backend;
35 
36 } // namespace details
37 
38 class connection_pool;
39 
41 {
42 private:
43 
44  void set_query_transformation_(std::auto_ptr<details::query_transformation_function> qtf);
45 
46 public:
47  session();
48  explicit session(connection_parameters const & parameters);
49  session(backend_factory const & factory, std::string const & connectString);
50  session(std::string const & backendName, std::string const & connectString);
51  explicit session(std::string const & connectString);
52  explicit session(connection_pool & pool);
53 
54  ~session();
55 
56  void open(connection_parameters const & parameters);
57  void open(backend_factory const & factory, std::string const & connectString);
58  void open(std::string const & backendName, std::string const & connectString);
59  void open(std::string const & connectString);
60  void close();
61  void reconnect();
62 
63  void begin();
64  void commit();
65  void rollback();
66 
67  // once and prepare are for syntax sugar only
70 
71  // even more sugar
72  template <typename T>
73  details::once_temp_type operator<<(T const & t) { return once << t; }
74 
75  std::ostringstream & get_query_stream();
76  std::string get_query() const;
77 
78  template <typename T>
79  void set_query_transformation(T callback)
80  {
81  std::auto_ptr<details::query_transformation_function> qtf(new details::query_transformation<T>(callback));
82  set_query_transformation_(qtf);
83 
84  assert(qtf.get() == NULL);
85  }
86 
87  // support for basic logging
88  void set_log_stream(std::ostream * s);
89  std::ostream * get_log_stream() const;
90 
91  void log_query(std::string const & query);
92  std::string get_last_query() const;
93 
94  void set_got_data(bool gotData);
95  bool got_data() const;
96 
97  void uppercase_column_names(bool forceToUpper);
98 
99  bool get_uppercase_column_names() const;
100 
101  // Functions for dealing with sequence/auto-increment values.
102 
103  // If true is returned, value is filled with the next value from the given
104  // sequence. Otherwise either the sequence is invalid (doesn't exist) or
105  // the current backend doesn't support sequences. If you use sequences for
106  // automatically generating primary key values, you should use
107  // get_last_insert_id() after the insertion in this case.
108  bool get_next_sequence_value(std::string const & sequence, long & value);
109 
110  // If true is returned, value is filled with the last auto-generated value
111  // for this table (although some backends ignore the table argument and
112  // return the last value auto-generated in this session).
113  bool get_last_insert_id(std::string const & table, long & value);
114 
115 
116  // for diagnostics and advanced users
117  // (downcast it to expected back-end session class)
118  details::session_backend * get_backend() { return backEnd_; }
119 
120  std::string get_backend_name() const;
121 
122  details::statement_backend * make_statement_backend();
123  details::rowid_backend * make_rowid_backend();
124  details::blob_backend * make_blob_backend();
125 
126 private:
127  session(session const &);
128  session& operator=(session const &);
129 
130  std::ostringstream query_stream_;
132 
133  std::ostream * logStream_;
134  std::string lastQuery_;
135 
137 
139 
141 
142  bool gotData_;
143 
145  std::size_t poolPosition_;
147 };
148 
149 } // namespace soci
150 
151 #endif // SOCI_SESSION_H_INCLUDED
details::once_temp_type operator<<(T const &t)
Definition: session.h:73
std::ostream * logStream_
Definition: session.h:133
details::session_backend * backEnd_
Definition: session.h:140
std::string lastQuery_
Definition: session.h:134
details::session_backend * get_backend()
Definition: session.h:118
std::ostringstream query_stream_
Definition: session.h:130
details::once_type once
Definition: session.h:68
#define SOCI_DECL
Definition: soci-config.h:31
connection_parameters lastConnectParameters_
Definition: session.h:136
bool uppercaseColumnNames_
Definition: session.h:138
void set_query_transformation(T callback)
Definition: session.h:79
details::query_transformation_function * query_transformation_
Definition: session.h:131
bool isFromPool_
Definition: session.h:144
connection_pool * pool_
Definition: session.h:146
std::string connectString
Definition: test-db2.cpp:21
std::size_t poolPosition_
Definition: session.h:145
bool gotData_
Definition: session.h:142
std::vector< ISM::CombinatorialTrainerParameters > parameters
details::prepare_type prepare
Definition: session.h:69


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:41