diff --git a/dlls/mysqlx/basic_sql.cpp b/dlls/mysqlx/basic_sql.cpp index 08f9ff9b..f5d41010 100644 --- a/dlls/mysqlx/basic_sql.cpp +++ b/dlls/mysqlx/basic_sql.cpp @@ -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); 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; } @@ -111,7 +111,7 @@ static cell AMX_NATIVE_CALL SQL_PrepareQuery(AMX *amx, cell *params) IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database); 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; } @@ -135,7 +135,7 @@ static cell AMX_NATIVE_CALL SQL_Execute(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -144,7 +144,9 @@ static cell AMX_NATIVE_CALL SQL_Execute(AMX *amx, cell *params) memset(&qInfo->info, 0, sizeof(QueryInfo)); if (!qInfo->pQuery->Execute(&qInfo->info, qInfo->error, 254)) + { return 0; + } 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); 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; } @@ -168,7 +170,7 @@ static cell AMX_NATIVE_CALL SQL_MoreResults(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -183,7 +185,7 @@ static cell AMX_NATIVE_CALL SQL_IsNull(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -212,7 +214,7 @@ static cell AMX_NATIVE_CALL SQL_ReadResult(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -273,7 +275,7 @@ static cell AMX_NATIVE_CALL SQL_NextRow(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -295,7 +297,7 @@ static cell AMX_NATIVE_CALL SQL_AffectedRows(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -307,7 +309,7 @@ static cell AMX_NATIVE_CALL SQL_NumResults(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -326,7 +328,7 @@ static cell AMX_NATIVE_CALL SQL_NumColumns(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -346,7 +348,7 @@ static cell AMX_NATIVE_CALL SQL_FieldNumToName(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -372,12 +374,24 @@ static cell AMX_NATIVE_CALL SQL_FieldNumToName(AMX *amx, cell *params) 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) { AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -393,7 +407,9 @@ static cell AMX_NATIVE_CALL SQL_FieldNameToNum(AMX *amx, cell *params) char *namewa = MF_GetAmxString(amx, params[2], 0, &len); unsigned int columnId; if (!rs->FieldNameToNum(namewa, &columnId)) + { return -1; + } return columnId; } @@ -450,6 +466,7 @@ AMX_NATIVE_INFO g_BaseSqlNatives[] = {"SQL_FieldNameToNum", SQL_FieldNameToNum}, {"SQL_GetAffinity", SQL_GetAffinity}, {"SQL_SetAffinity", SQL_SetAffinity}, + {"SQL_GetQueryString", SQL_GetQueryString}, {NULL, NULL}, }; diff --git a/dlls/mysqlx/mysql/ISQLDriver.h b/dlls/mysqlx/mysql/ISQLDriver.h index 7ae106cd..05b6bd8c 100644 --- a/dlls/mysqlx/mysql/ISQLDriver.h +++ b/dlls/mysqlx/mysql/ISQLDriver.h @@ -84,6 +84,10 @@ namespace SourceMod * Same as above, except result handles are not freed for you. */ virtual bool ExecuteR(QueryInfo *info, char *error, size_t maxlength) =0; + /** + * Returns the query string. + */ + virtual const char *GetQueryString() =0; }; class ISQLDriver; diff --git a/dlls/mysqlx/mysql/MysqlQuery.cpp b/dlls/mysqlx/mysql/MysqlQuery.cpp index 9c3f2bd8..0057e725 100644 --- a/dlls/mysqlx/mysql/MysqlQuery.cpp +++ b/dlls/mysqlx/mysql/MysqlQuery.cpp @@ -46,6 +46,11 @@ bool MysqlQuery::Execute(QueryInfo *info, char *error, size_t maxlength) return res; } +const char *MysqlQuery::GetQueryString() +{ + return m_QueryString; +} + bool MysqlQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength) { int err; diff --git a/dlls/mysqlx/mysql/MysqlQuery.h b/dlls/mysqlx/mysql/MysqlQuery.h index a672508a..ed60f602 100644 --- a/dlls/mysqlx/mysql/MysqlQuery.h +++ b/dlls/mysqlx/mysql/MysqlQuery.h @@ -17,6 +17,7 @@ namespace SourceMod void FreeHandle(); bool Execute(QueryInfo *info, char *error, size_t maxlength); bool ExecuteR(QueryInfo *info, char *error, size_t maxlength); + const char *GetQueryString(); private: MysqlDatabase *m_pDatabase; char *m_QueryString; diff --git a/dlls/mysqlx/sdk/moduleconfig.h b/dlls/mysqlx/sdk/moduleconfig.h index d59f93e1..f33f92a5 100755 --- a/dlls/mysqlx/sdk/moduleconfig.h +++ b/dlls/mysqlx/sdk/moduleconfig.h @@ -15,7 +15,7 @@ * to add multiple entries. */ #define MODULE_NAME "MySQL" -#define MODULE_VERSION "1.75" +#define MODULE_VERSION "1.76" #define MODULE_AUTHOR "AMX Mod X Dev Team" #define MODULE_URL "http://www.amxmodx.org/" #define MODULE_LOGTAG "MySQL" diff --git a/dlls/mysqlx/threading.cpp b/dlls/mysqlx/threading.cpp index 49a22b30..02a272a5 100644 --- a/dlls/mysqlx/threading.cpp +++ b/dlls/mysqlx/threading.cpp @@ -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); 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; } diff --git a/dlls/sqlite/basic_sql.cpp b/dlls/sqlite/basic_sql.cpp index 36cebfc3..e6940a82 100644 --- a/dlls/sqlite/basic_sql.cpp +++ b/dlls/sqlite/basic_sql.cpp @@ -116,7 +116,7 @@ static cell AMX_NATIVE_CALL SQL_PrepareQuery(AMX *amx, cell *params) IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database); 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; } @@ -140,7 +140,7 @@ static cell AMX_NATIVE_CALL SQL_Execute(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -149,7 +149,9 @@ static cell AMX_NATIVE_CALL SQL_Execute(AMX *amx, cell *params) memset(&qInfo->info, 0, sizeof(QueryInfo)); if (!qInfo->pQuery->Execute(&qInfo->info, qInfo->error, 254)) + { return 0; + } 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); 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; } @@ -173,7 +175,7 @@ static cell AMX_NATIVE_CALL SQL_MoreResults(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -188,7 +190,7 @@ static cell AMX_NATIVE_CALL SQL_IsNull(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -217,7 +219,7 @@ static cell AMX_NATIVE_CALL SQL_ReadResult(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -278,7 +280,7 @@ static cell AMX_NATIVE_CALL SQL_NextRow(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -300,7 +302,7 @@ static cell AMX_NATIVE_CALL SQL_AffectedRows(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -312,7 +314,7 @@ static cell AMX_NATIVE_CALL SQL_NumResults(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -331,7 +333,7 @@ static cell AMX_NATIVE_CALL SQL_NumColumns(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -351,7 +353,7 @@ static cell AMX_NATIVE_CALL SQL_FieldNumToName(AMX *amx, cell *params) AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -377,12 +379,24 @@ static cell AMX_NATIVE_CALL SQL_FieldNumToName(AMX *amx, cell *params) 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) { AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); 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; } @@ -398,7 +412,9 @@ static cell AMX_NATIVE_CALL SQL_FieldNameToNum(AMX *amx, cell *params) char *namewa = MF_GetAmxString(amx, params[2], 0, &len); unsigned int columnId; if (!rs->FieldNameToNum(namewa, &columnId)) + { return -1; + } return columnId; } @@ -455,6 +471,7 @@ AMX_NATIVE_INFO g_BaseSqlNatives[] = {"SQL_FieldNameToNum", SQL_FieldNameToNum}, {"SQL_GetAffinity", SQL_GetAffinity}, {"SQL_SetAffinity", SQL_SetAffinity}, + {"SQL_GetQueryString", SQL_GetQueryString}, {NULL, NULL}, }; diff --git a/dlls/sqlite/sdk/moduleconfig.h b/dlls/sqlite/sdk/moduleconfig.h index 5eb03110..e401b3ca 100755 --- a/dlls/sqlite/sdk/moduleconfig.h +++ b/dlls/sqlite/sdk/moduleconfig.h @@ -5,7 +5,7 @@ // Module info #define MODULE_NAME "SQLite" -#define MODULE_VERSION "1.75" +#define MODULE_VERSION "1.76" #define MODULE_AUTHOR "AMX Mod X Dev Team" #define MODULE_URL "http://www.amxmodx.org/" #define MODULE_LOGTAG "SQLITE" diff --git a/dlls/sqlite/sqlitepp/ISQLDriver.h b/dlls/sqlite/sqlitepp/ISQLDriver.h index 7ae106cd..05b6bd8c 100644 --- a/dlls/sqlite/sqlitepp/ISQLDriver.h +++ b/dlls/sqlite/sqlitepp/ISQLDriver.h @@ -84,6 +84,10 @@ namespace SourceMod * Same as above, except result handles are not freed for you. */ virtual bool ExecuteR(QueryInfo *info, char *error, size_t maxlength) =0; + /** + * Returns the query string. + */ + virtual const char *GetQueryString() =0; }; class ISQLDriver; diff --git a/dlls/sqlite/sqlitepp/SqliteQuery.cpp b/dlls/sqlite/sqlitepp/SqliteQuery.cpp index fb7a00ae..092540b1 100644 --- a/dlls/sqlite/sqlitepp/SqliteQuery.cpp +++ b/dlls/sqlite/sqlitepp/SqliteQuery.cpp @@ -47,6 +47,11 @@ bool SqliteQuery::Execute(QueryInfo *info, char *error, size_t maxlength) return res; } +const char *SqliteQuery::GetQueryString() +{ + return m_QueryString; +} + bool SqliteQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength) { int err; diff --git a/dlls/sqlite/sqlitepp/SqliteQuery.h b/dlls/sqlite/sqlitepp/SqliteQuery.h index 0ddd8390..0585c203 100644 --- a/dlls/sqlite/sqlitepp/SqliteQuery.h +++ b/dlls/sqlite/sqlitepp/SqliteQuery.h @@ -24,6 +24,7 @@ namespace SourceMod void FreeHandle(); bool Execute(QueryInfo *info, char *error, size_t maxlength); bool ExecuteR(QueryInfo *info, char *error, size_t maxlength); + const char *GetQueryString(); private: SqliteDatabase *m_pDatabase; SqliteResultSet *m_LastRes; diff --git a/dlls/sqlite/threading.cpp b/dlls/sqlite/threading.cpp index de7080a6..24d279ed 100644 --- a/dlls/sqlite/threading.cpp +++ b/dlls/sqlite/threading.cpp @@ -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); 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; } diff --git a/plugins/include/sqlx.inc b/plugins/include/sqlx.inc index c3b8f4cc..9655ff62 100644 --- a/plugins/include/sqlx.inc +++ b/plugins/include/sqlx.inc @@ -194,6 +194,11 @@ native SQL_GetAffinity(driver[], maxlen); */ 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. * (updated for newer API) diff --git a/plugins/testsuite/sqlxtest.sma b/plugins/testsuite/sqlxtest.sma index 98d07c1a..2e684d1f 100644 --- a/plugins/testsuite/sqlxtest.sma +++ b/plugins/testsuite/sqlxtest.sma @@ -78,7 +78,11 @@ PrintQueryData(Handle:query) { new columns = SQL_NumColumns(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) new num