mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 06:15:37 +03:00
Committed implementation of request am42697
This commit is contained in:
parent
f7691a51c6
commit
b7076fc572
@ -77,7 +77,7 @@ static cell AMX_NATIVE_CALL SQL_Connect(AMX *amx, cell *params)
|
|||||||
SQL_Connection *sql = (SQL_Connection *)GetHandle(params[1], Handle_Connection);
|
SQL_Connection *sql = (SQL_Connection *)GetHandle(params[1], Handle_Connection);
|
||||||
if (!sql)
|
if (!sql)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid info tuple handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ static cell AMX_NATIVE_CALL SQL_PrepareQuery(AMX *amx, cell *params)
|
|||||||
IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
|
IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
|
||||||
if (!pDb)
|
if (!pDb)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid database handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ static cell AMX_NATIVE_CALL SQL_Execute(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +144,9 @@ static cell AMX_NATIVE_CALL SQL_Execute(AMX *amx, cell *params)
|
|||||||
memset(&qInfo->info, 0, sizeof(QueryInfo));
|
memset(&qInfo->info, 0, sizeof(QueryInfo));
|
||||||
|
|
||||||
if (!qInfo->pQuery->Execute(&qInfo->info, qInfo->error, 254))
|
if (!qInfo->pQuery->Execute(&qInfo->info, qInfo->error, 254))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -154,7 +156,7 @@ static cell AMX_NATIVE_CALL SQL_QueryError(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +170,7 @@ static cell AMX_NATIVE_CALL SQL_MoreResults(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +185,7 @@ static cell AMX_NATIVE_CALL SQL_IsNull(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +214,7 @@ static cell AMX_NATIVE_CALL SQL_ReadResult(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +275,7 @@ static cell AMX_NATIVE_CALL SQL_NextRow(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +297,7 @@ static cell AMX_NATIVE_CALL SQL_AffectedRows(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +309,7 @@ static cell AMX_NATIVE_CALL SQL_NumResults(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +328,7 @@ static cell AMX_NATIVE_CALL SQL_NumColumns(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +348,7 @@ static cell AMX_NATIVE_CALL SQL_FieldNumToName(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,12 +374,24 @@ static cell AMX_NATIVE_CALL SQL_FieldNumToName(AMX *amx, cell *params)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell AMX_NATIVE_CALL SQL_GetQueryString(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
|
if (!qInfo)
|
||||||
|
{
|
||||||
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MF_SetAmxString(amx, params[2], qInfo->pQuery->GetQueryString(), params[3]);
|
||||||
|
}
|
||||||
|
|
||||||
static cell AMX_NATIVE_CALL SQL_FieldNameToNum(AMX *amx, cell *params)
|
static cell AMX_NATIVE_CALL SQL_FieldNameToNum(AMX *amx, cell *params)
|
||||||
{
|
{
|
||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +407,9 @@ static cell AMX_NATIVE_CALL SQL_FieldNameToNum(AMX *amx, cell *params)
|
|||||||
char *namewa = MF_GetAmxString(amx, params[2], 0, &len);
|
char *namewa = MF_GetAmxString(amx, params[2], 0, &len);
|
||||||
unsigned int columnId;
|
unsigned int columnId;
|
||||||
if (!rs->FieldNameToNum(namewa, &columnId))
|
if (!rs->FieldNameToNum(namewa, &columnId))
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return columnId;
|
return columnId;
|
||||||
}
|
}
|
||||||
@ -450,6 +466,7 @@ AMX_NATIVE_INFO g_BaseSqlNatives[] =
|
|||||||
{"SQL_FieldNameToNum", SQL_FieldNameToNum},
|
{"SQL_FieldNameToNum", SQL_FieldNameToNum},
|
||||||
{"SQL_GetAffinity", SQL_GetAffinity},
|
{"SQL_GetAffinity", SQL_GetAffinity},
|
||||||
{"SQL_SetAffinity", SQL_SetAffinity},
|
{"SQL_SetAffinity", SQL_SetAffinity},
|
||||||
|
{"SQL_GetQueryString", SQL_GetQueryString},
|
||||||
|
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
|
@ -84,6 +84,10 @@ namespace SourceMod
|
|||||||
* Same as above, except result handles are not freed for you.
|
* Same as above, except result handles are not freed for you.
|
||||||
*/
|
*/
|
||||||
virtual bool ExecuteR(QueryInfo *info, char *error, size_t maxlength) =0;
|
virtual bool ExecuteR(QueryInfo *info, char *error, size_t maxlength) =0;
|
||||||
|
/**
|
||||||
|
* Returns the query string.
|
||||||
|
*/
|
||||||
|
virtual const char *GetQueryString() =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ISQLDriver;
|
class ISQLDriver;
|
||||||
|
@ -46,6 +46,11 @@ bool MysqlQuery::Execute(QueryInfo *info, char *error, size_t maxlength)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *MysqlQuery::GetQueryString()
|
||||||
|
{
|
||||||
|
return m_QueryString;
|
||||||
|
}
|
||||||
|
|
||||||
bool MysqlQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength)
|
bool MysqlQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -17,6 +17,7 @@ namespace SourceMod
|
|||||||
void FreeHandle();
|
void FreeHandle();
|
||||||
bool Execute(QueryInfo *info, char *error, size_t maxlength);
|
bool Execute(QueryInfo *info, char *error, size_t maxlength);
|
||||||
bool ExecuteR(QueryInfo *info, char *error, size_t maxlength);
|
bool ExecuteR(QueryInfo *info, char *error, size_t maxlength);
|
||||||
|
const char *GetQueryString();
|
||||||
private:
|
private:
|
||||||
MysqlDatabase *m_pDatabase;
|
MysqlDatabase *m_pDatabase;
|
||||||
char *m_QueryString;
|
char *m_QueryString;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* to add multiple entries.
|
* to add multiple entries.
|
||||||
*/
|
*/
|
||||||
#define MODULE_NAME "MySQL"
|
#define MODULE_NAME "MySQL"
|
||||||
#define MODULE_VERSION "1.75"
|
#define MODULE_VERSION "1.76"
|
||||||
#define MODULE_AUTHOR "AMX Mod X Dev Team"
|
#define MODULE_AUTHOR "AMX Mod X Dev Team"
|
||||||
#define MODULE_URL "http://www.amxmodx.org/"
|
#define MODULE_URL "http://www.amxmodx.org/"
|
||||||
#define MODULE_LOGTAG "MySQL"
|
#define MODULE_LOGTAG "MySQL"
|
||||||
|
@ -52,7 +52,7 @@ static cell AMX_NATIVE_CALL SQL_ThreadQuery(AMX *amx, cell *params)
|
|||||||
SQL_Connection *cn = (SQL_Connection *)GetHandle(params[1], Handle_Connection);
|
SQL_Connection *cn = (SQL_Connection *)GetHandle(params[1], Handle_Connection);
|
||||||
if (!cn)
|
if (!cn)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid info tuple handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ static cell AMX_NATIVE_CALL SQL_PrepareQuery(AMX *amx, cell *params)
|
|||||||
IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
|
IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
|
||||||
if (!pDb)
|
if (!pDb)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid database handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ static cell AMX_NATIVE_CALL SQL_Execute(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +149,9 @@ static cell AMX_NATIVE_CALL SQL_Execute(AMX *amx, cell *params)
|
|||||||
memset(&qInfo->info, 0, sizeof(QueryInfo));
|
memset(&qInfo->info, 0, sizeof(QueryInfo));
|
||||||
|
|
||||||
if (!qInfo->pQuery->Execute(&qInfo->info, qInfo->error, 254))
|
if (!qInfo->pQuery->Execute(&qInfo->info, qInfo->error, 254))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -159,7 +161,7 @@ static cell AMX_NATIVE_CALL SQL_QueryError(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +175,7 @@ static cell AMX_NATIVE_CALL SQL_MoreResults(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +190,7 @@ static cell AMX_NATIVE_CALL SQL_IsNull(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +219,7 @@ static cell AMX_NATIVE_CALL SQL_ReadResult(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +280,7 @@ static cell AMX_NATIVE_CALL SQL_NextRow(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +302,7 @@ static cell AMX_NATIVE_CALL SQL_AffectedRows(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +314,7 @@ static cell AMX_NATIVE_CALL SQL_NumResults(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,7 +333,7 @@ static cell AMX_NATIVE_CALL SQL_NumColumns(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +353,7 @@ static cell AMX_NATIVE_CALL SQL_FieldNumToName(AMX *amx, cell *params)
|
|||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,12 +379,24 @@ static cell AMX_NATIVE_CALL SQL_FieldNumToName(AMX *amx, cell *params)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell AMX_NATIVE_CALL SQL_GetQueryString(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
|
if (!qInfo)
|
||||||
|
{
|
||||||
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MF_SetAmxString(amx, params[2], qInfo->pQuery->GetQueryString(), params[3]);
|
||||||
|
}
|
||||||
|
|
||||||
static cell AMX_NATIVE_CALL SQL_FieldNameToNum(AMX *amx, cell *params)
|
static cell AMX_NATIVE_CALL SQL_FieldNameToNum(AMX *amx, cell *params)
|
||||||
{
|
{
|
||||||
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query);
|
||||||
if (!qInfo)
|
if (!qInfo)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,7 +412,9 @@ static cell AMX_NATIVE_CALL SQL_FieldNameToNum(AMX *amx, cell *params)
|
|||||||
char *namewa = MF_GetAmxString(amx, params[2], 0, &len);
|
char *namewa = MF_GetAmxString(amx, params[2], 0, &len);
|
||||||
unsigned int columnId;
|
unsigned int columnId;
|
||||||
if (!rs->FieldNameToNum(namewa, &columnId))
|
if (!rs->FieldNameToNum(namewa, &columnId))
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return columnId;
|
return columnId;
|
||||||
}
|
}
|
||||||
@ -455,6 +471,7 @@ AMX_NATIVE_INFO g_BaseSqlNatives[] =
|
|||||||
{"SQL_FieldNameToNum", SQL_FieldNameToNum},
|
{"SQL_FieldNameToNum", SQL_FieldNameToNum},
|
||||||
{"SQL_GetAffinity", SQL_GetAffinity},
|
{"SQL_GetAffinity", SQL_GetAffinity},
|
||||||
{"SQL_SetAffinity", SQL_SetAffinity},
|
{"SQL_SetAffinity", SQL_SetAffinity},
|
||||||
|
{"SQL_GetQueryString", SQL_GetQueryString},
|
||||||
|
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
// Module info
|
// Module info
|
||||||
#define MODULE_NAME "SQLite"
|
#define MODULE_NAME "SQLite"
|
||||||
#define MODULE_VERSION "1.75"
|
#define MODULE_VERSION "1.76"
|
||||||
#define MODULE_AUTHOR "AMX Mod X Dev Team"
|
#define MODULE_AUTHOR "AMX Mod X Dev Team"
|
||||||
#define MODULE_URL "http://www.amxmodx.org/"
|
#define MODULE_URL "http://www.amxmodx.org/"
|
||||||
#define MODULE_LOGTAG "SQLITE"
|
#define MODULE_LOGTAG "SQLITE"
|
||||||
|
@ -84,6 +84,10 @@ namespace SourceMod
|
|||||||
* Same as above, except result handles are not freed for you.
|
* Same as above, except result handles are not freed for you.
|
||||||
*/
|
*/
|
||||||
virtual bool ExecuteR(QueryInfo *info, char *error, size_t maxlength) =0;
|
virtual bool ExecuteR(QueryInfo *info, char *error, size_t maxlength) =0;
|
||||||
|
/**
|
||||||
|
* Returns the query string.
|
||||||
|
*/
|
||||||
|
virtual const char *GetQueryString() =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ISQLDriver;
|
class ISQLDriver;
|
||||||
|
@ -47,6 +47,11 @@ bool SqliteQuery::Execute(QueryInfo *info, char *error, size_t maxlength)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *SqliteQuery::GetQueryString()
|
||||||
|
{
|
||||||
|
return m_QueryString;
|
||||||
|
}
|
||||||
|
|
||||||
bool SqliteQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength)
|
bool SqliteQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -24,6 +24,7 @@ namespace SourceMod
|
|||||||
void FreeHandle();
|
void FreeHandle();
|
||||||
bool Execute(QueryInfo *info, char *error, size_t maxlength);
|
bool Execute(QueryInfo *info, char *error, size_t maxlength);
|
||||||
bool ExecuteR(QueryInfo *info, char *error, size_t maxlength);
|
bool ExecuteR(QueryInfo *info, char *error, size_t maxlength);
|
||||||
|
const char *GetQueryString();
|
||||||
private:
|
private:
|
||||||
SqliteDatabase *m_pDatabase;
|
SqliteDatabase *m_pDatabase;
|
||||||
SqliteResultSet *m_LastRes;
|
SqliteResultSet *m_LastRes;
|
||||||
|
@ -52,7 +52,7 @@ static cell AMX_NATIVE_CALL SQL_ThreadQuery(AMX *amx, cell *params)
|
|||||||
SQL_Connection *cn = (SQL_Connection *)GetHandle(params[1], Handle_Connection);
|
SQL_Connection *cn = (SQL_Connection *)GetHandle(params[1], Handle_Connection);
|
||||||
if (!cn)
|
if (!cn)
|
||||||
{
|
{
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid info tuple handle: %d", params[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +194,11 @@ native SQL_GetAffinity(driver[], maxlen);
|
|||||||
*/
|
*/
|
||||||
native SQL_SetAffinity(const driver[]);
|
native SQL_SetAffinity(const driver[]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the original query string that a query handle used.
|
||||||
|
*/
|
||||||
|
native SQL_GetQueryString(Handle:query, buffer[], maxlength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function can be used to find out if a table in a Sqlite database exists.
|
* This function can be used to find out if a table in a Sqlite database exists.
|
||||||
* (updated for newer API)
|
* (updated for newer API)
|
||||||
|
@ -78,7 +78,11 @@ PrintQueryData(Handle:query)
|
|||||||
{
|
{
|
||||||
new columns = SQL_NumColumns(query)
|
new columns = SQL_NumColumns(query)
|
||||||
new rows = SQL_NumResults(query)
|
new rows = SQL_NumResults(query)
|
||||||
|
static querystring[2048]
|
||||||
|
|
||||||
|
SQL_GetQueryString(query, querystring, 2047)
|
||||||
|
|
||||||
|
server_print("Original query string: %s", querystring)
|
||||||
server_print("Query columns: %d rows: %d", columns, rows)
|
server_print("Query columns: %d rows: %d", columns, rows)
|
||||||
|
|
||||||
new num
|
new num
|
||||||
|
Loading…
Reference in New Issue
Block a user