add sql logging define

This commit is contained in:
rtldg 2021-08-18 15:10:42 +00:00
parent 077cbe9a01
commit 2b4d77d281
8 changed files with 75 additions and 18 deletions

View File

@ -44,6 +44,8 @@
#define HUD_NOSOUNDS (1 << 11) // disables sounds on personal best, world record etc
#define HUD_NOPRACALERT (1 << 12) // hides practice mode chat alert
#define SHAVIT_LOG_QUERIES 0
// status
enum TimerStatus
{
@ -250,6 +252,56 @@ enum struct frame_cache_t
float fTickrate;
}
stock void Shavit_LogQuery(const char[] query)
{
#if SHAVIT_LOG_QUERIES
static File hLogFile;
if (hLogFile == null)
{
char sPlugin[PLATFORM_MAX_PATH];
GetPluginFilename(INVALID_HANDLE, sPlugin, sizeof(sPlugin));
ReplaceString(sPlugin, PLATFORM_MAX_PATH, ".smx", "");
ReplaceString(sPlugin, PLATFORM_MAX_PATH, "\\", "/");
int start = FindCharInString(sPlugin, '/', true);
char sFilename[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sFilename, sizeof(sFilename), "logs/%s_sql.log", sPlugin[start+1]);
hLogFile = OpenFile(sFilename, "a");
}
if (hLogFile)
{
LogToOpenFileEx(hLogFile, "%s", query);
}
#endif
}
methodmap Database2 < Database
{
public void Query(SQLQueryCallback callback, const char[] query, any data = 0, DBPriority prio = DBPrio_Normal)
{
Shavit_LogQuery(query);
this.Query(callback, query, data, prio);
}
}
methodmap Transaction2 < Transaction
{
public Transaction2()
{
return view_as<Transaction2>(new Transaction());
}
public int AddQuery(const char[] query, any data = 0)
{
Shavit_LogQuery(query);
return this.AddQuery(query, data);
}
}
#if defined USES_CHAT_COLORS
// hardcoded colors
char gS_GlobalColorNames[][] =
@ -323,6 +375,11 @@ stock Database GetTimerDatabaseHandle()
return db;
}
stock Database2 GetTimerDatabaseHandle2()
{
return view_as<Database2>(GetTimerDatabaseHandle());
}
// figures out if the database is a mysql database
stock bool IsMySQLDatabase(Database db)
{

View File

@ -81,7 +81,7 @@ DynamicHook gH_AcceptInput; // used for hooking player_speedmod's AcceptInput
Handle gH_PhysicsCheckForEntityUntouch;
// database handle
Database gH_SQL = null;
Database2 gH_SQL = null;
bool gB_MySQL = false;
int gI_MigrationsRequired;
int gI_MigrationsFinished;
@ -2995,7 +2995,7 @@ bool LoadMessages()
void SQL_DBConnect()
{
GetTimerSQLPrefix(gS_MySQLPrefix, 32);
gH_SQL = GetTimerDatabaseHandle();
gH_SQL = GetTimerDatabaseHandle2();
gB_MySQL = IsMySQLDatabase(gH_SQL);
// support unicode names
@ -3193,7 +3193,7 @@ public void SQL_TableMigrationIPAddresses_Callback(Database db, DBResultSet resu
return;
}
Transaction hTransaction = new Transaction();
Transaction2 hTransaction = new Transaction2();
int iQueries = 0;
while(results.FetchRow())

View File

@ -66,7 +66,7 @@ enum struct ranking_t
}
char gS_MySQLPrefix[32];
Database gH_SQL = null;
Database2 gH_SQL = null;
bool gB_HasSQLRANK = false; // whether the sql driver supports RANK()
bool gB_Stats = false;
@ -218,7 +218,7 @@ public void OnLibraryRemoved(const char[] name)
public void Shavit_OnDatabaseLoaded()
{
GetTimerSQLPrefix(gS_MySQLPrefix, 32);
gH_SQL = GetTimerDatabaseHandle();
gH_SQL = GetTimerDatabaseHandle2();
if(!IsMySQLDatabase(gH_SQL))
{
@ -743,7 +743,7 @@ public Action Command_RecalcAll(int client, int args)
{
ReplyToCommand(client, "- Started recalculating points for all maps. Check console for output.");
Transaction trans = new Transaction();
Transaction2 trans = new Transaction2();
char sQuery[1024];
FormatEx(sQuery, sizeof(sQuery), "UPDATE %splayertimes SET points = 0;", gS_MySQLPrefix);

View File

@ -286,7 +286,7 @@ TopMenu gH_AdminMenu = null;
TopMenuObject gH_TimerCommands = INVALID_TOPMENUOBJECT;
// database related things
Database gH_SQL = null;
Database2 gH_SQL = null;
char gS_MySQLPrefix[32];
bool gB_ClosestPos;
@ -488,7 +488,7 @@ public void OnPluginStart()
// database
GetTimerSQLPrefix(gS_MySQLPrefix, 32);
gH_SQL = GetTimerDatabaseHandle();
gH_SQL = GetTimerDatabaseHandle2();
LoadDHooks();

View File

@ -40,7 +40,7 @@
bool gB_Rankings = false;
// database handle
Database gH_SQL = null;
Database2 gH_SQL = null;
char gS_MySQLPrefix[32];
// cache
@ -109,7 +109,7 @@ public void OnPluginStart()
// database
GetTimerSQLPrefix(gS_MySQLPrefix, 32);
gH_SQL = GetTimerDatabaseHandle();
gH_SQL = GetTimerDatabaseHandle2();
if(gB_Late)
{

View File

@ -36,7 +36,7 @@
// #define DEBUG
// database handle
Database gH_SQL = null;
Database2 gH_SQL = null;
// base cvars
ConVar mp_do_warmup_period = null;
@ -113,7 +113,7 @@ public void OnPluginStart()
Convar.AutoExecConfig();
GetTimerSQLPrefix(gS_MySQLPrefix, 32);
gH_SQL = GetTimerDatabaseHandle();
gH_SQL = GetTimerDatabaseHandle2();
}
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)

View File

@ -58,7 +58,7 @@ Handle gH_OnWorstRecord = null;
Handle gH_OnFinishMessage = null;
// database handle
Database gH_SQL = null;
Database2 gH_SQL = null;
bool gB_Connected = false;
bool gB_MySQL = false;
@ -2144,11 +2144,11 @@ public int SubMenu_Handler(Menu menu, MenuAction action, int param1, int param2)
public void Shavit_OnDatabaseLoaded()
{
GetTimerSQLPrefix(gS_MySQLPrefix, 32);
gH_SQL = GetTimerDatabaseHandle();
gH_SQL = GetTimerDatabaseHandle2();
gB_MySQL = IsMySQLDatabase(gH_SQL);
char sQuery[1024];
Transaction hTransaction = new Transaction();
Transaction2 hTransaction = new Transaction2();
if(gB_MySQL)
{

View File

@ -40,7 +40,7 @@
EngineVersion gEV_Type = Engine_Unknown;
Database gH_SQL = null;
Database2 gH_SQL = null;
bool gB_Connected = false;
bool gB_MySQL = false;
bool gB_InsertedPrebuiltZones = false;
@ -3240,10 +3240,10 @@ void CreateZonePoints(float point[8][3], float offset = 0.0)
public void Shavit_OnDatabaseLoaded()
{
GetTimerSQLPrefix(gS_MySQLPrefix, 32);
gH_SQL = GetTimerDatabaseHandle();
gH_SQL = GetTimerDatabaseHandle2();
gB_MySQL = IsMySQLDatabase(gH_SQL);
Transaction hTransaction = new Transaction();
Transaction2 hTransaction = new Transaction2();
char sQuery[1024];
FormatEx(sQuery, 1024,