Skip to content

Commit

Permalink
Fix Database.TableExists rarely returning a false positive in MySQL b…
Browse files Browse the repository at this point in the history
…ackend

If table 'InboxTestA' existed, then Database.TableExists('InboxTest_') would wrongly return true

This would hence cause an error to get logged every time 'Test_' user logged in (when MySQL was being used as the SQL backend)
  • Loading branch information
UnknownShadow200 committed Jan 1, 2022
1 parent 422426e commit 0bab641
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions MCGalaxy/Database/Backends/MySQL.cs
Expand Up @@ -85,8 +85,12 @@ public sealed class MySQLBackend : IDatabaseBackend {

static object IterateExists(IDataRecord record, object arg) { return ""; }
public override bool TableExists(string table) {
return Database.Iterate("SHOW TABLES LIKE '" + table + "'",
null, IterateExists) != null;
// "SHOW TABLES LIKE '[table]'" SQL statement is insufficient
// because "table" might include characters such as _, %, etc
string column = "Tables_in_" + Server.Config.MySQLDatabaseName;

return Database.Iterate("SHOW TABLES WHERE " + column + " = @0",
null, IterateExists, table) != null;
}

public override List<string> AllTables() {
Expand Down

0 comments on commit 0bab641

Please sign in to comment.