10 #ifndef INCLUDE_FUNAPI_DATABASE_MARIADB_H_ 11 #define INCLUDE_FUNAPI_DATABASE_MARIADB_H_ 13 #include <boost/bind.hpp> 14 #include <boost/enable_shared_from_this.hpp> 23 #include <mysqld_error.h> 39 size_t GetResultSetCount()
const;
43 bool SeekNextResultSet();
46 size_t GetCountOfAffectedRows()
const;
49 const std::vector<size_t> &GetCountsOfAffectedRows()
const;
53 size_t GetColumnCount()
const;
58 string GetColumnName(
const size_t &column_index)
const;
63 enum_field_types GetColumnType(
const size_t &column_index)
const;
67 size_t GetRowCount()
const;
75 bool IsNull(
size_t column_index)
const;
80 bool GetBool(
size_t column_index,
bool regard_null_as =
false)
const;
85 int64_t GetInt(
size_t column_index, int64_t regard_null_as = 0)
const;
86 int8_t GetInt8(
size_t column_index, int8_t regard_null_as = 0)
const;
87 int16_t GetInt16(
size_t column_index, int16_t regard_null_as = 0)
const;
88 int32_t GetInt32(
size_t column_index, int32_t regard_null_as = 0)
const;
89 int64_t GetInt64(
size_t column_index, int64_t regard_null_as = 0)
const;
94 uint64_t GetUint(
size_t column_index, uint64_t regard_null_as = 0)
const;
95 uint8_t GetUint8(
size_t column_index, uint8_t regard_null_as = 0)
const;
96 uint16_t GetUint16(
size_t column_index, uint16_t regard_null_as = 0)
const;
97 uint32_t GetUint32(
size_t column_index, uint32_t regard_null_as = 0)
const;
98 uint64_t GetUint64(
size_t column_index, uint64_t regard_null_as = 0)
const;
103 float GetFloat(
size_t column_index,
float regard_null_as = 0.0)
const;
108 double GetDouble(
size_t column_index,
double regard_null_as = 0.0)
const;
113 const char *GetString(
size_t column_index)
const;
118 const char *GetBinary(
size_t column_index)
const;
123 uint64_t GetFieldLength(
size_t column_index)
const;
128 WallClock::Value GetDateTime(
132 const string GetDateTimeString(
134 const string ®ard_null_as =
"")
const;
139 WallClock::Duration GetTime(
141 const WallClock::Duration ®ard_null_as =
147 bool GetBool(
const string &column_name,
bool regard_null_as =
false)
const;
152 int64_t GetInt(
const string &column_name, int64_t regard_null_as = 0)
const;
157 uint64_t GetUint(
const string &column_name, uint64_t regard_null_as = 0)
const;
162 float GetFloat(
const string &column_name,
float regard_null_as = 0.0)
const;
167 double GetDouble(
const string &column_name,
double regard_null_as = 0.0)
const;
172 const char *GetString(
const string &column_name)
const;
177 const char *GetBinary(
const string &column_name)
const;
182 uint64_t GetFieldLength(
const string &column_name)
const;
187 WallClock::Value GetDateTime(
188 const string &column_name,
194 WallClock::Duration GetTime(
195 const string &column_name,
196 const WallClock::Duration ®ard_null_as =
216 struct FUNAPI_DLL_VISIBILITY
Error {
225 void(
const Ptr<ResultSets> &,
226 const Error &)> QueryExecuteHandler;
228 void(
size_t ,
size_t ,
229 const WallClock::Value &)> ConnectionFailureHandler;
231 static const string kDefaultConnectionCharset;
232 static const bool kDefaultAutoRetryOnDeadlock;
233 static const unsigned long kDefaultClientFlags;
234 static const int64_t kDefaultSlowQueryLoggingTime;
235 static const ConnectionFailureHandler kDefaultConnectionFailureHandler;
237 static Ptr<Mariadb> Create(
238 const string &address,
const string &
id,
const string &password,
239 const string &database,
size_t connection_count,
240 const string &connection_charset = kDefaultConnectionCharset,
241 bool auto_retry_on_deadlock = kDefaultAutoRetryOnDeadlock,
242 unsigned long client_flags = kDefaultClientFlags,
243 int64_t slow_query_logging_time_in_ms = kDefaultSlowQueryLoggingTime,
244 const ConnectionFailureHandler &connection_failure_handler =
245 kDefaultConnectionFailureHandler);
250 void ExecuteQuery(
const string &query,
const QueryExecuteHandler &handler);
251 Ptr<ResultSets> ExecuteQuerySync(
const string &query,
Error *error = NULL);
253 Ptr<MariadbConnection> GetExclusiveConnection();
255 const string &address()
const;
256 const string &id()
const;
257 const string &database()
const;
259 size_t connection_count()
const;
260 size_t idle_connection_count()
const;
261 size_t query_queue_size()
const;
264 Mariadb(
const string &address,
const string &
id,
const string &password,
265 const string &database,
size_t connection_count,
266 const string &connection_charset,
bool auto_retry_on_deadlock,
267 unsigned long client_flags, int64_t slow_query_logging_time_in_ms,
268 const ConnectionFailureHandler &connection_failure_handler);
275 :
public boost::enable_shared_from_this<MariadbConnection> {
279 typedef Mariadb::QueryExecuteHandler QueryExecuteHandler;
282 void ExecuteQuery(
const string &query,
const QueryExecuteHandler &handler);
283 Ptr<ResultSets> ExecuteQuerySync(
const string &query, Error *error = NULL);
290 friend class Mariadb::Impl;
299 FUNAPI_DLL_VISIBILITY
300 std::ostream &operator<<(std::ostream &stream,
const Mariadb::Error &error);
304 #endif // INCLUDE_FUNAPI_DATABASE_MARIADB_H_ Provides query interface for Mariadb and manages connection pool.
Definition: mariadb.h:208
Definition: mariadb.h:274
Contains result sets and provides access interface.
Definition: mariadb.h:29
static const Duration kEmptyDuration
the value of 00:00:00.000000
Definition: wall_clock.h:36
Definition: mariadb.h:216
static const Value kEpochClock
The value of time_t(0), 1970-01-01 00:00:00.000000 UTC.
Definition: wall_clock.h:33
#define DECLARE_CLASS_PTR(CLS)
Utility macro to forward-declare smart pointer types for a given class.
Definition: types.h:89