mirror of
https://github.com/Jackzmc/sourcemod-plugins.git
synced 2025-05-06 15:13:20 +00:00
Only create transaction when we use it
This commit is contained in:
parent
d397b1e10d
commit
1148a2b689
1 changed files with 5 additions and 4 deletions
|
@ -158,8 +158,9 @@ public Action Timer_PushLogs(Handle h) {
|
|||
static char query[1024];
|
||||
static Log log;
|
||||
int length = logs.Length;
|
||||
Transaction transaction = new Transaction();
|
||||
|
||||
if(length > 0) {
|
||||
Transaction transaction = new Transaction();
|
||||
for(int i = 0; i < length; i++) {
|
||||
logs.GetArray(i, log, sizeof(log));
|
||||
g_db.Format(query, sizeof(query), "INSERT INTO `activity_log` (`timestamp`, `server`, `type`, `client`, `target`, `message`) VALUES (%d, NULLIF('%s', ''), '%s', NULLIF('%s', ''), NULLIF('%s', ''), NULLIF('%s', ''))",
|
||||
|
@ -173,11 +174,11 @@ public Action Timer_PushLogs(Handle h) {
|
|||
transaction.AddQuery(query);
|
||||
}
|
||||
logs.Resize(logs.Length - length);
|
||||
g_db.Execute(transaction, _, SQL_TransactionFailed, length, DBPrio_Low);
|
||||
}
|
||||
g_db.Execute(transaction, _, SQL_TransactionFailed, length, DBPrio_Low);
|
||||
return Plugin_Continue;
|
||||
}
|
||||
public void SQL_TransactionFailed(Database db, any data, int numQueries, const char[] error, int failIndex, any[] queryData) {
|
||||
void SQL_TransactionFailed(Database db, any data, int numQueries, const char[] error, int failIndex, any[] queryData) {
|
||||
LogError("Push transaction failed: %s at query %d/%d", error, failIndex, numQueries);
|
||||
}
|
||||
|
||||
|
@ -301,4 +302,4 @@ public any Native_AddLog(Handle plugin, int numParams) {
|
|||
if(GetNativeString(4, message, sizeof(message)) != SP_ERROR_NONE) return false;
|
||||
AddLog(type, clientName, targetName, message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue