2014-08-04 10:29:31 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// MySQL Module
|
|
|
|
//
|
|
|
|
|
2006-04-23 01:10:06 +00:00
|
|
|
#ifndef _INCLUDE_MYSQL_THREADING_H
|
|
|
|
#define _INCLUDE_MYSQL_THREADING_H
|
|
|
|
|
|
|
|
#include "IThreader.h"
|
|
|
|
#include "ISQLDriver.h"
|
2015-09-30 17:08:39 +00:00
|
|
|
#include <amtl/am-string.h>
|
2014-08-10 10:27:05 +00:00
|
|
|
#include <sh_stack.h>
|
2006-04-23 01:10:06 +00:00
|
|
|
|
|
|
|
struct QueuedResultInfo
|
|
|
|
{
|
|
|
|
AmxQueryInfo amxinfo;
|
|
|
|
bool connect_success;
|
|
|
|
bool query_success;
|
2006-10-01 19:46:56 +00:00
|
|
|
float queue_time;
|
2006-04-23 01:10:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AtomicResult :
|
|
|
|
public IResultSet,
|
|
|
|
public IResultRow
|
|
|
|
{
|
|
|
|
friend class MysqlThread;
|
|
|
|
public:
|
|
|
|
AtomicResult();
|
|
|
|
~AtomicResult();
|
|
|
|
public:
|
|
|
|
//free the handle if necessary (see IQuery).
|
|
|
|
virtual void FreeHandle();
|
|
|
|
virtual unsigned int RowCount();
|
|
|
|
virtual unsigned int FieldCount();
|
|
|
|
virtual const char *FieldNumToName(unsigned int num);
|
|
|
|
virtual bool FieldNameToNum(const char *name, unsigned int *columnId);
|
|
|
|
virtual bool IsDone();
|
|
|
|
virtual IResultRow *GetRow();
|
|
|
|
virtual void NextRow();
|
2007-04-24 15:46:33 +00:00
|
|
|
virtual void Rewind();
|
2007-10-22 21:31:02 +00:00
|
|
|
virtual bool NextResultSet();
|
2006-04-23 01:10:06 +00:00
|
|
|
public:
|
|
|
|
virtual const char *GetString(unsigned int columnId);
|
|
|
|
virtual const char *GetStringSafe(unsigned int columnId);
|
|
|
|
virtual double GetDouble(unsigned int columnId);
|
|
|
|
virtual float GetFloat(unsigned int columnId);
|
|
|
|
virtual int GetInt(unsigned int columnId);
|
|
|
|
virtual bool IsNull(unsigned int columnId);
|
|
|
|
virtual const char *GetRaw(unsigned int columnId, size_t *length);
|
|
|
|
public:
|
|
|
|
void CopyFrom(IResultSet *rs);
|
|
|
|
private:
|
|
|
|
void _InternalClear();
|
|
|
|
private:
|
|
|
|
unsigned int m_RowCount;
|
|
|
|
unsigned int m_FieldCount;
|
2006-06-04 19:26:43 +00:00
|
|
|
size_t m_AllocSize;
|
2014-08-10 10:27:05 +00:00
|
|
|
ke::AString **m_Table;
|
2006-04-23 01:10:06 +00:00
|
|
|
unsigned int m_CurRow;
|
|
|
|
bool m_IsFree;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MysqlThread : public IThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MysqlThread();
|
|
|
|
~MysqlThread();
|
|
|
|
public:
|
2006-10-01 19:46:56 +00:00
|
|
|
void SetInfo(const char *host, const char *user, const char *pass, const char *db, int port, unsigned int max_timeout);
|
2014-04-18 20:04:32 +00:00
|
|
|
void SetCharacterSet(const char *charset);
|
2006-04-23 01:10:06 +00:00
|
|
|
void SetQuery(const char *query);
|
|
|
|
void SetCellData(cell data[], ucell len);
|
|
|
|
void SetForward(int forward);
|
|
|
|
void Invalidate();
|
|
|
|
void Execute();
|
|
|
|
public:
|
|
|
|
void RunThread(IThreadHandle *pHandle);
|
|
|
|
void OnTerminate(IThreadHandle *pHandle, bool cancel);
|
|
|
|
private:
|
2014-08-10 10:27:05 +00:00
|
|
|
ke::AString m_query;
|
|
|
|
ke::AString m_host;
|
|
|
|
ke::AString m_user;
|
|
|
|
ke::AString m_pass;
|
|
|
|
ke::AString m_db;
|
2006-10-01 19:46:56 +00:00
|
|
|
unsigned int m_max_timeout;
|
2014-08-10 10:27:05 +00:00
|
|
|
ke::AString m_charset;
|
2006-04-23 01:10:06 +00:00
|
|
|
int m_port;
|
|
|
|
cell *m_data;
|
|
|
|
ucell m_datalen;
|
|
|
|
size_t m_maxdatalen;
|
|
|
|
int m_fwd;
|
|
|
|
QueuedResultInfo m_qrInfo;
|
|
|
|
AtomicResult m_atomicResult;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //_INCLUDE_MYSQL_THREADING_H
|
2007-10-30 00:09:18 +00:00
|
|
|
|