Skip to content

Commit 0500b86

Browse files
authored
Asynchronous SET NAMES utf8mb4 (#1052)
1 parent 421423f commit 0500b86

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

game/addons/sourcemod/scripting/sbpp_comms.sp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,9 +1380,15 @@ public void GotDatabase(Database db, const char[] error, any data)
13801380
}
13811381

13821382
// Set character set to UTF8MB4 in the database
1383-
char query[128];
1384-
Format(query, sizeof(query), "SET NAMES utf8mb4");
1385-
db.Query(Query_ErrorCheck, query);
1383+
// Use SQL_SetCharset to ensure charset is set synchronously before any operations
1384+
if (!db.SetCharset("utf8mb4"))
1385+
{
1386+
LogError("Failed to set database charset to utf8mb4");
1387+
// Fallback to async method
1388+
char query[128];
1389+
Format(query, sizeof(query), "SET NAMES utf8mb4");
1390+
db.Query(Query_ErrorCheck, query);
1391+
}
13861392

13871393
// Process queue
13881394
SQLiteDB.Query(Query_ProcessQueue,

game/addons/sourcemod/scripting/sbpp_main.sp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,15 @@ public void GotDatabase(Database db, const char[] error, any data)
10901090

10911091
char query[1024];
10921092

1093-
Format(query, sizeof(query), "SET NAMES utf8mb4");
1094-
DB.Query(ErrorCheckCallback, query);
1093+
// Set character set to UTF8MB4 in the database
1094+
// Use SetCharset to ensure charset is set synchronously before any operations
1095+
if (!DB.SetCharset("utf8mb4"))
1096+
{
1097+
LogToFile(logFile, "Failed to set database charset to utf8mb4, trying async method");
1098+
// Fallback to async method
1099+
Format(query, sizeof(query), "SET NAMES utf8mb4");
1100+
DB.Query(ErrorCheckCallback, query);
1101+
}
10951102

10961103
InsertServerInfo();
10971104

0 commit comments

Comments
 (0)