- return res;
- }
-
- ModuleSQL* Parent()
- {
- return (ModuleSQL*)(Module*)creator;
- }
-
- void DoBlockingQuery(SQLQuery* req)
- {
- /* Parse the command string and dispatch it to mysql */
- if (CheckConnection() && !mysql_real_query(connection, req->query.data(), req->query.length()))
- {
- /* Successfull query */
- MYSQL_RES* res = mysql_use_result(connection);
- unsigned long rows = mysql_affected_rows(connection);
- MySQLresult* r = new MySQLresult(req, res, rows);
- Parent()->Dispatcher->LockQueue();
- Parent()->rq.push_back(r);
- Parent()->Dispatcher->NotifyParent();
- Parent()->Dispatcher->UnlockQueue();
- }
- else
- {
- /* XXX: See /usr/include/mysql/mysqld_error.h for a list of
- * possible error numbers and error messages */
- SQLerror e(SQL_QREPLY_FAIL, ConvToStr(mysql_errno(connection)) + std::string(": ") + mysql_error(connection));
- MySQLresult* r = new MySQLresult(req, e);
- Parent()->Dispatcher->LockQueue();
- Parent()->rq.push_back(r);
- Parent()->Dispatcher->NotifyParent();
- Parent()->Dispatcher->UnlockQueue();
- }
- }
-
- bool CheckConnection()
- {
- if (mysql_ping(connection) != 0)
- {
- return Connect();
- }
- else return true;
- }
-
- std::string GetError()
- {
- return mysql_error(connection);
- }
-
- void Close()
- {
- mysql_close(connection);
- }
-
- void submit(SQLQuery* q)
- {
- Parent()->Dispatcher->LockQueue();
- Parent()->qq.push_back(QueueItem(q, this));
- Parent()->Dispatcher->UnlockQueueWakeup();