pg_async
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
common.hpp
Go to the documentation of this file.
1 
132 #ifndef TIP_DB_PG_COMMON_HPP_
133 #define TIP_DB_PG_COMMON_HPP_
134 
135 #include <string>
136 #include <iosfwd>
137 #include <vector>
138 #include <functional>
139 #include <memory>
140 #include <map>
141 #include <boost/integer.hpp>
142 #include <boost/optional.hpp>
143 
144 #include <tip/util/streambuf.hpp>
145 #include <tip/db/pg/pg_types.hpp>
146 
147 namespace tip {
148 namespace db {
149 namespace pg {
150 
154 typedef boost::int_t<16>::exact smallint;
158 typedef boost::uint_t<16>::exact usmallint;
162 typedef boost::int_t<32>::exact integer;
166 typedef boost::uint_t<32>::exact uinteger;
170 typedef boost::int_t<64>::exact bigint;
174 typedef boost::uint_t<64>::exact ubigint;
175 
179 const integer PROTOCOL_VERSION = (3 << 16); // 3.0
180 
184 typedef char byte;
185 
190 template < typename T >
191 using nullable = boost::optional<T>;
192 
196 struct bytea {
197  typedef std::vector<byte> container_type;
199 };
200 
201 typedef tip::util::input_iterator_buffer field_buffer;
202 
209 struct dbalias {
211 
212  void
213  swap(std::string& rhs) /* no_throw */
214  {
215  value.swap(rhs);
216  }
217 
218  operator std::string () { return value; }
219 
220  bool
221  operator == (dbalias const& rhs) const
222  {
223  return value == rhs.value;
224  }
225  bool
226  operator != (dbalias const& rhs) const
227  {
228  return !(*this == rhs);
229  }
230 
231  bool
232  operator < (dbalias const& rhs) const
233  {
234  return value < rhs.value;
235  }
236 };
237 
238 inline bool
239 operator == (dbalias const& lhs, std::string const& rhs)
240 {
241  return lhs.value == rhs;
242 }
243 
244 std::ostream&
245 operator << (std::ostream& out, dbalias const&);
246 
262  void
263  generate_alias();
276  static connection_options
277  parse(std::string const&);
278 };
279 
286 };
287 
321 };
325 typedef std::vector< field_description > row_description_type;
326 
328 
329 class resultset;
330 class transaction;
331 class basic_connection;
332 namespace error {
333 class db_error;
334 class connection_error;
335 class query_error;
336 } // namespace error
338 
339 
340 typedef std::shared_ptr<transaction> transaction_ptr;
341 typedef std::shared_ptr<basic_connection> connection_ptr;
343 
345 typedef std::map< std::string, std::string > client_options_type;
346 typedef std::vector< oids::type::oid_type > type_oid_sequence;
347 
348 typedef std::function< void () > simple_callback;
350 typedef std::function< void (error::db_error const&) > error_callback;
352 typedef std::function< void (transaction_ptr) > transaction_callback;
353 
355 typedef std::function< void (transaction_ptr, resultset, bool) > query_result_callback;
357 typedef std::function< void (error::query_error const&) > query_error_callback;
358 
359 namespace options {
360 
361 const std::string HOST = "host";
362 const std::string PORT = "port";
363 const std::string USER = "user";
364 const std::string DATABASE = "database";
365 const std::string CLIENT_ENCODING = "client_encoding";
366 const std::string APPLICATION_NAME = "application_name";
367 
368 } // namespace options
369 
370 } // namespace pg
371 } // namespace db
372 } // namespace tip
373 
375 operator"" _db(const char*, size_t n);
376 
389 operator"" _pg(const char*, size_t);
390 
391 #endif /* TIP_DB_PG_COMMON_HPP_ */
std::vector< byte > container_type
Definition: common.hpp:197
boost::int_t< 64 >::exact bigint
8-byte integer, to match PostgreSQL bigint and bigserial types
Definition: common.hpp:170
std::shared_ptr< basic_connection > connection_ptr
Definition: common.hpp:341
Short unique string to refer a database. Signature structure, to pass instead of connection string...
Definition: common.hpp:209
std::shared_ptr< transaction > transaction_ptr
Definition: common.hpp:340
tip::util::input_iterator_buffer field_buffer
Definition: common.hpp:201
const integer PROTOCOL_VERSION
PostgreSQL protocol version.
Definition: common.hpp:179
boost::optional< T > nullable
Nullable data type.
Definition: common.hpp:191
RAII transaction object.
Definition: transaction.hpp:29
protocol_data_format
Definition: common.hpp:283
std::function< void(error::db_error const &) > error_callback
Callback for error handling.
Definition: common.hpp:350
smallint type_size
The data type size (see pg_type.typlen). Note that negative values denote variable-width types...
Definition: common.hpp:308
const std::string CLIENT_ENCODING
Definition: common.hpp:365
std::ostream & operator<<(std::ostream &out, dbalias const &)
boost::int_t< 32 >::exact integer
4-byte integer, to match PostgreSQL integer and serial types
Definition: common.hpp:162
integer type_mod
The type modifier (see pg_attribute.atttypmod). The meaning of the modifier is type-specific.
Definition: common.hpp:312
bool operator<(dbalias const &rhs) const
Definition: common.hpp:232
static connection_options parse(std::string const &)
boost::uint_t< 64 >::exact ubigint
8-byte unsigned integer
Definition: common.hpp:174
smallint attribute_number
If the field can be identified as a column of a specific table, the attribute number of the column; o...
Definition: common.hpp:302
bool operator==(dbalias const &rhs) const
Definition: common.hpp:221
protocol_data_format format_code
The format code being used for the field. Currently will be zero (text) or one (binary). In a RowDescription returned from the statement variant of Describe, the format code is not yet known and will always be zero.
Definition: common.hpp:319
const std::string DATABASE
Definition: common.hpp:364
boost::uint_t< 16 >::exact usmallint
2-byte unsigned integer
Definition: common.hpp:158
Postgre connection options.
Definition: common.hpp:250
std::map< std::string, std::string > client_options_type
Definition: common.hpp:345
const std::string PORT
Definition: common.hpp:362
integer table_oid
If the field can be identified as a column of a specific table, the object ID of the table; otherwise...
Definition: common.hpp:298
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
boost::uint_t< 32 >::exact uinteger
4-byte unsigned integer
Definition: common.hpp:166
Binary data, matches PostgreSQL bytea type.
Definition: common.hpp:196
boost::int_t< 16 >::exact smallint
2-byte integer, to match PostgreSQL smallint and smallserial types
Definition: common.hpp:154
Description of a field returned by the backend.
Definition: common.hpp:291
BINARY_DATA_FORMAT.
Definition: common.hpp:285
const std::string HOST
Definition: common.hpp:361
container_type data
Definition: common.hpp:198
oids::type::oid_type type_oid
The object ID of the field's data type.
Definition: common.hpp:304
std::string value
Definition: common.hpp:210
Base class for exceptions generated by the library.
Definition: error.hpp:22
std::string name
The field name.
Definition: common.hpp:294
void swap(std::string &rhs)
Definition: common.hpp:213
char byte
1-byte char or byte type.
Definition: common.hpp:184
std::vector< field_description > row_description_type
Result set's row description.
Definition: common.hpp:325
TEXT_DATA_FORMAT.
Definition: common.hpp:284
const std::string APPLICATION_NAME
Definition: common.hpp:366
bool operator==(dbalias const &lhs, std::string const &rhs)
Definition: common.hpp:239
bool operator!=(dbalias const &rhs) const
Definition: common.hpp:226
std::vector< oids::type::oid_type > type_oid_sequence
Definition: common.hpp:346
Connection with the database server failure. Includes network and authentication failures.
Definition: error.hpp:40
std::function< void() > simple_callback
Definition: common.hpp:348
const std::string USER
Definition: common.hpp:363
std::function< void(transaction_ptr, resultset, bool) > query_result_callback
Callback for query results.
Definition: common.hpp:355
std::function< void(transaction_ptr) > transaction_callback
Callback for starting a transaction.
Definition: common.hpp:352