29.03.2020, 08:59
ALWAYS escape input by people to avoid SQL Injection.
Set `name` column as UNIQUE KEY, not only the searching will be faster but it will not continue searching if a row is found because it now knows there will never be duplicates.
In /changename:
In `OnPlayerNameChange` callback:
Set `name` column as UNIQUE KEY, not only the searching will be faster but it will not continue searching if a row is found because it now knows there will never be duplicates.
In /changename:
pawn Code:
mysql_format(..., "UPDATE IGNORE `users` SET `name` = '%e' WHERE `name` = '%s'", ...);
mysql_tquery(handle, query, "OnPlayerNameChange", "ds", playerid, params);
pawn Code:
// without `IGNORE` keyword, it would return error about duplicate key
// `IGNORE` literally ignores the error and does absolutely nothing (0 rows are affected)
// When the row is updated (sets the new name), the affected rows will be 1
if (!cache_affected_rows())
{
// already registered name, pick a new one
}
else
{
// SetPlayerName
}

