Skip to content

Commit

Permalink
Fix charset (#536)
Browse files Browse the repository at this point in the history
* Use "SET NAMES" SQL query to set charset to utf8mb4

SQL_SetCharset seems to be bugged and defaults to latin1

* unset debug mode
  • Loading branch information
Groruk committed Nov 23, 2018
1 parent 94d55b5 commit 14b887e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
19 changes: 4 additions & 15 deletions game/addons/sourcemod/scripting/sbpp_comms.sp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max

g_hFwd_OnPlayerPunished = CreateGlobalForward("SourceComms_OnBlockAdded", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_String);

MarkNativeAsOptional("SQL_SetCharset");
RegPluginLibrary("sourcecomms++");
return APLRes_Success;
}
Expand Down Expand Up @@ -1261,20 +1260,10 @@ public void GotDatabase(Database db, const char[] error, any data)
return;
}

// Set character set to UTF-8 in the database
if (GetFeatureStatus(FeatureType_Native, "SQL_SetCharset") == FeatureStatus_Available)
{
db.SetCharset("utf8");
}
else
{
char query[128];
FormatEx(query, sizeof(query), "SET NAMES 'UTF8'");
#if defined LOG_QUERIES
LogToFile(logQuery, "Set encoding. QUERY: %s", query);
#endif
db.Query(Query_ErrorCheck, query);
}
// Set character set to UTF8MB4 in the database
char query[128];
Format(query, sizeof(query), "SET NAMES utf8mb4");
db.Query(Query_ErrorCheck, query);

// Process queue
SQLiteDB.Query(Query_ProcessQueue,
Expand Down
4 changes: 2 additions & 2 deletions game/addons/sourcemod/scripting/sbpp_main.sp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,8 @@ public void GotDatabase(Database db, const char[] error, any data)

char query[1024];

DB.SetCharset("utf8");
Format(query, sizeof(query), "SET NAMES utf8mb4");
DB.Query(ErrorCheckCallback, query);

InsertServerInfo();

Expand Down Expand Up @@ -2537,7 +2538,6 @@ stock void UTIL_InsertBan(int time, const char[] Name, const char[] Authid, cons
%d, ' ')",
DatabasePrefix, Ip, Authid, banName, (time * 60), (time * 60), banReason, DatabasePrefix, AdminAuthid, AdminAuthid[8], AdminIp, serverID);
}

DB.Query(VerifyInsert, Query, dataPack, DBPrio_High);
}

Expand Down

0 comments on commit 14b887e

Please sign in to comment.