mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -04:00
Use Backend.DeleteTable instead of hardcoding DROP TABLE everywhere.
This commit is contained in:
parent
f68ff9dfca
commit
5c8edae438
@ -70,14 +70,14 @@ namespace MCGalaxy.Commands {
|
||||
if (args.Length == 1) {
|
||||
Player.SendChatFrom(who, who.ColoredName + " %Shad their color removed.", false);
|
||||
who.color = who.group.color;
|
||||
Database.Execute("UPDATE Players SET color = '' WHERE name = @0", who.name);
|
||||
Database.Execute("UPDATE Players SET color = '' WHERE Name = @0", who.name);
|
||||
} else {
|
||||
string color = Colors.Parse(args[1]);
|
||||
if (color == "") { Player.Message(p, "There is no color \"" + args[1] + "\"."); return; }
|
||||
else if (color == who.color) { Player.Message(p, who.DisplayName + " already has that color."); return; }
|
||||
Player.SendChatFrom(who, who.ColoredName + " %Shad their color changed to " + color + Colors.Name(color) + "%S.", false);
|
||||
who.color = color;
|
||||
Database.Execute("UPDATE Players SET color = @1 WHERE name = @0", who.name, color);
|
||||
Database.Execute("UPDATE Players SET color = @1 WHERE Name = @0", who.name, color);
|
||||
}
|
||||
Entities.GlobalDespawn(who, true);
|
||||
Entities.GlobalSpawn(who, true);
|
||||
|
@ -58,5 +58,11 @@ namespace MCGalaxy.SQL {
|
||||
string syntax = "INSERT INTO `" + dstTable + "` SELECT * FROM `" + srcTable + "`";
|
||||
Database.Execute(syntax);
|
||||
}
|
||||
|
||||
/// <summary> Completely removes the given table from the database. </summary>
|
||||
public virtual void DeleteTable(string table) {
|
||||
string syntax = "DROP TABLE `" + table + "`";
|
||||
Database.Execute(syntax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ PRIMARY KEY(player)
|
||||
Database.Execute("INSERT INTO Economy (player, money) SELECT Players.Name, Players.Money FROM Players");
|
||||
} else {
|
||||
//this will only be needed when the server shuts down while it was copying content (or some other error)
|
||||
Database.Execute("DROP TABLE Economy");
|
||||
Database.Backend.DeleteTable("Economy");
|
||||
goto retry;
|
||||
}
|
||||
players.Dispose(); eco.Dispose();
|
||||
|
@ -74,7 +74,7 @@ namespace MCGalaxy {
|
||||
string updateSyntax = "UPDATE `Portals" + dst + "` SET ExitMap=@1 WHERE ExitMap=@0";
|
||||
Database.Execute(updateSyntax, src, dst);
|
||||
}
|
||||
|
||||
|
||||
if (Database.TableExists("Messages" + src)) {
|
||||
Database.Backend.RenameTable("Messages" + src, "Messages" + dst);
|
||||
}
|
||||
@ -136,15 +136,18 @@ namespace MCGalaxy {
|
||||
BotsFile.DeleteBots(name);
|
||||
|
||||
//safe against SQL injections because the levelname (message) is first being checked if it exists
|
||||
Database.Execute("DROP TABLE `Block" + name + "`");
|
||||
Database.Backend.DeleteTable("Block" + name);
|
||||
object locker = ThreadSafeCache.DBCache.Get(name);
|
||||
lock (locker) {
|
||||
if (Database.TableExists("Portals" + name))
|
||||
Database.Execute("DROP TABLE `Portals" + name + "`");
|
||||
if (Database.TableExists("Messages" + name))
|
||||
Database.Execute("DROP TABLE `Messages" + name + "`");
|
||||
if (Database.TableExists("Zone" + name))
|
||||
Database.Execute("DROP TABLE `Zone" + name + "`");
|
||||
if (Database.TableExists("Portals" + name)) {
|
||||
Database.Backend.DeleteTable("Portals" + name);
|
||||
}
|
||||
if (Database.TableExists("Messages" + name)) {
|
||||
Database.Backend.DeleteTable("Messages" + name);
|
||||
}
|
||||
if (Database.TableExists("Zone" + name)) {
|
||||
Database.Backend.DeleteTable("Zone" + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,8 +202,8 @@ namespace MCGalaxy {
|
||||
|
||||
//Delete old
|
||||
List<string> tables = GetTables();
|
||||
foreach (string name in tables)
|
||||
Database.Execute("DROP TABLE `" + name + "`");
|
||||
foreach (string table in tables)
|
||||
Database.Backend.DeleteTable(table);
|
||||
|
||||
// Import data
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
|
@ -80,7 +80,7 @@ SELECT Time, Name, Cmd, Cmdmsg FROM Playercmds WHERE {0};";
|
||||
foreach (string cmd in Server.Opstats)
|
||||
Database.Execute(string.Format(insertSyntax, "cmd = '" + cmd + "'"));
|
||||
Database.Execute(string.Format(insertSyntax, "cmd = 'review' AND cmdmsg = 'next'"));
|
||||
Database.Execute("DROP TABLE Playercmds");
|
||||
Database.Backend.DeleteTable("Playercmds");
|
||||
}
|
||||
|
||||
// Here, since SQLite is a NEW thing from 5.3.0.0, we do not have to check for existing tables in SQLite.
|
||||
|
Loading…
x
Reference in New Issue
Block a user