29#include <sptk5/db/PoolDatabaseConnection.h>
34#include <sptk5/db/MySQLStatement.h>
37#define ULONG_CAST (unsigned long)
52class SP_EXPORT MySQLConnection
53 :
public PoolDatabaseConnection
57 friend class MySQLStatement;
63 MYSQL* connection()
const
65 return m_connection.get();
72 void _openDatabase(
const String& connectionString)
override;
82 void _executeBatchSQL(
const sptk::Strings& batchSQL, Strings* errors)
override;
93 explicit MySQLConnection(
const String& connectionString =
"", std::chrono::seconds connectTimeout = std::chrono::seconds(60));
95 MySQLConnection(
const MySQLConnection&) =
delete;
97 MySQLConnection(MySQLConnection&&) =
delete;
99 MySQLConnection& operator=(
const MySQLConnection&) =
delete;
101 MySQLConnection& operator=(MySQLConnection&&) =
delete;
103 ~MySQLConnection()
override =
default;
108 void closeDatabase()
override;
113 bool active()
const override;
118 DBHandle handle()
const override;
123 String driverDescription()
const override;
135 static std::map<MySQLConnection*, std::shared_ptr<MySQLConnection>> s_mysqlConnections;
141 void driverBeginTransaction()
override;
147 void driverEndTransaction(
bool commit)
override;
153 String queryError(
const Query* query)
const override;
158 void queryAllocStmt(Query* query)
override;
163 void queryFreeStmt(Query* query)
override;
168 void queryCloseStmt(Query* query)
override;
173 void queryPrepare(Query* query)
override;
178 void queryExecute(Query* query)
override;
183 int queryColCount(Query* query)
override;
188 void queryBindParameters(Query* query)
override;
193 void queryOpen(Query* query)
override;
198 void queryFetch(Query* query)
override;
199 void queryColAttributes(Query* query, int16_t column, int16_t descType, int32_t& value)
override;
200 void queryColAttributes(Query* query, int16_t column, int16_t descType,
char* buff,
int len)
override;
207 String paramMark(
unsigned paramIndex)
override;
210 std::shared_ptr<MYSQL> m_connection;
211 mutable std::mutex m_mutex;
216 void initConnection();
221 void executeCommand(
const String& command);
224#define throwMySQLException(info) throw DatabaseException(string(info) + ":" + string(mysql_error(m_connection.get())))
234SP_DRIVER_EXPORT
void* mysql_create_connection(
const char* connectionString,
size_t connectionTimeoutSeconds);
235SP_DRIVER_EXPORT
void mysql_destroy_connection(
void* connection);
DatabaseObjectType
Definition: PoolDatabaseConnection.h:70