m_ReconnectTimer->SetInterval(10);
m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&IdoMysqlConnection::ReconnectTimerHandler, this));
m_ReconnectTimer->Start();
+ m_ReconnectTimer->Reschedule(0);
ASSERT(mysql_thread_safe());
}
void IdoMysqlConnection::Stop(void)
{
+ m_QueryQueue.Enqueue(boost::bind(&IdoMysqlConnection::Disconnect, this));
+ m_QueryQueue.Join();
+}
+
+void IdoMysqlConnection::AssertOnWorkQueue(void)
+{
+ VERIFY(boost::this_thread::get_id() == m_QueryQueue.GetThreadId());
+}
+
+void IdoMysqlConnection::Disconnect(void)
+{
+ AssertOnWorkQueue();
+
boost::mutex::scoped_lock lock(m_ConnectionMutex);
if (!m_Connected)
}
void IdoMysqlConnection::TxTimerHandler(void)
+{
+ m_QueryQueue.Enqueue(boost::bind(&IdoMysqlConnection::NewTransaction, this));
+}
+
+void IdoMysqlConnection::NewTransaction(void)
{
boost::mutex::scoped_lock lock(m_ConnectionMutex);
void IdoMysqlConnection::ReconnectTimerHandler(void)
{
+ m_QueryQueue.Enqueue(boost::bind(&IdoMysqlConnection::Reconnect, this));
+}
+
+void IdoMysqlConnection::Reconnect(void)
+{
+ AssertOnWorkQueue();
+
{
boost::mutex::scoped_lock lock(m_ConnectionMutex);
Array::Ptr IdoMysqlConnection::Query(const String& query)
{
+ AssertOnWorkQueue();
+
Log(LogDebug, "db_ido_mysql", "Query: " + query);
if (mysql_query(&m_Connection, query.CStr()) != 0)
DbReference IdoMysqlConnection::GetLastInsertID(void)
{
+ AssertOnWorkQueue();
+
return DbReference(mysql_insert_id(&m_Connection));
}
String IdoMysqlConnection::Escape(const String& s)
{
+ AssertOnWorkQueue();
+
ssize_t length = s.GetLength();
char *to = new char[s.GetLength() * 2 + 1];
Dictionary::Ptr IdoMysqlConnection::FetchRow(MYSQL_RES *result)
{
+ AssertOnWorkQueue();
+
MYSQL_ROW row;
MYSQL_FIELD *field;
unsigned long *lengths, i;
}
void IdoMysqlConnection::ExecuteQuery(const DbQuery& query)
+{
+ m_QueryQueue.Enqueue(boost::bind(&IdoMysqlConnection::InternalExecuteQuery, this, query));
+}
+
+void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query)
{
boost::mutex::scoped_lock lock(m_ConnectionMutex);
}
void IdoMysqlConnection::CleanUpExecuteQuery(const String& table, const String& time_key, double time_value)
+{
+ m_QueryQueue.Enqueue(boost::bind(&IdoMysqlConnection::InternalCleanUpExecuteQuery, this, table, time_key, time_value));
+}
+
+void IdoMysqlConnection::InternalCleanUpExecuteQuery(const String& table, const String& time_key, double time_value)
{
boost::mutex::scoped_lock lock(m_ConnectionMutex);
bool FieldToEscapedString(const String& key, const Value& value, Value *result);
void InternalActivateObject(const DbObject::Ptr& dbobj);
+ void Disconnect(void);
+ void NewTransaction(void);
+ void Reconnect(void);
+
+ void AssertOnWorkQueue(void);
+
void TxTimerHandler(void);
void ReconnectTimerHandler(void);
+ void InternalExecuteQuery(const DbQuery& query);
+ void InternalCleanUpExecuteQuery(const String& table, const String& time_key, double time_value);
+
void ClearConfigTables(void);
void ClearConfigTable(const String& table);
};