mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Make more things use Database.Backend
This commit is contained in:
parent
6d55e90700
commit
13cd3a56b3
@ -65,8 +65,7 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
//safe against SQL injections because no user input is given here
|
||||
if (num == -1) {
|
||||
string syntax = Server.useMySQL ? "TRUNCATE TABLE `Inbox" + p.name + "`" : "DELETE FROM `Inbox" + p.name + "`";
|
||||
Database.Execute(syntax);
|
||||
Database.Backend.ClearTable("Inbox" + p.name);
|
||||
} else {
|
||||
DataRow row = Inbox.Rows[num];
|
||||
string syntax = "DELETE FROM `Inbox" + p.name + "` WHERE PlayerFrom=@0 AND TimeSent=@1";
|
||||
|
@ -38,7 +38,7 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
message = parts[1];
|
||||
//DB
|
||||
if (message.Length >= 256 && Server.useMySQL) {
|
||||
if (message.Length >= 256 && Database.Backend.EnforcesTextLength) {
|
||||
Player.Message(p, "Message was too long. It has been trimmed to:");
|
||||
Player.Message(p, message.Substring(0, 255));
|
||||
message = message.Substring(0, 255);
|
||||
|
@ -42,10 +42,7 @@ namespace MCGalaxy.Commands.World {
|
||||
|
||||
if (args[0] == "clear") {
|
||||
Player.Message(p, "Clearing &cALL %Sblock changes for &d{0}...", lvl.name);
|
||||
if (Server.useMySQL)
|
||||
Database.Execute("TRUNCATE TABLE `Block" + lvl.name + "`");
|
||||
else
|
||||
Database.Execute("DELETE FROM `Block" + lvl.name + "`");
|
||||
Database.Backend.ClearTable("Block" + lvl.name);
|
||||
Player.Message(p, "Cleared &cALL %Sblock changes for &d" + lvl.name);
|
||||
} else if (args[0] == "disable") {
|
||||
lvl.UseBlockDB = false;
|
||||
|
@ -25,6 +25,9 @@ namespace MCGalaxy.SQL {
|
||||
/// (such as database name or file location) </summary>
|
||||
public abstract string ConnectionString { get; }
|
||||
|
||||
/// <summary> Whether this backend enforces the character length in VARCHAR columns. </summary>
|
||||
public abstract bool EnforcesTextLength { get; }
|
||||
|
||||
/// <summary> Returns a new BulkTransaction instance, which can be used to execute
|
||||
/// many sql statements as one single transaction. </summary>
|
||||
public abstract BulkTransaction CreateBulk();
|
||||
@ -42,5 +45,11 @@ namespace MCGalaxy.SQL {
|
||||
|
||||
/// <summary> Returns whether a table (case sensitive) exists by that name. </summary>
|
||||
public abstract bool TableExists(string table);
|
||||
|
||||
/// <summary> Renames the source table to the given name. </summary>
|
||||
public abstract void RenameTable(string srcTable, string dstTable);
|
||||
|
||||
/// <summary> Removes all entries from the given table. </summary>
|
||||
public abstract void ClearTable(string table);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ namespace MCGalaxy.SQL {
|
||||
public override string ConnectionString {
|
||||
get { return String.Format(connFormat, Server.MySQLHost, Server.MySQLPort,
|
||||
Server.MySQLUsername, Server.MySQLPassword, Server.DatabasePooling); }
|
||||
}
|
||||
}
|
||||
public override bool EnforcesTextLength { get { return true; } }
|
||||
|
||||
public override BulkTransaction CreateBulk() {
|
||||
return new MySQLBulkTransaction(ConnectionString);
|
||||
@ -50,5 +51,15 @@ namespace MCGalaxy.SQL {
|
||||
using (DataTable results = Database.Fill(syntax, table, Server.MySQLDatabaseName))
|
||||
return results.Rows.Count > 0;
|
||||
}
|
||||
|
||||
public override void RenameTable(string srcTable, string dstTable) {
|
||||
string syntax = "RENAME TABLE `" + srcTable + "` TO `" + dstTable + "`";
|
||||
Database.Execute(syntax);
|
||||
}
|
||||
|
||||
public override void ClearTable(string table) {
|
||||
string syntax = "TRUNCATE TABLE `" + table + "`";
|
||||
Database.Execute(syntax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ namespace MCGalaxy.SQL {
|
||||
public override string ConnectionString {
|
||||
get { return String.Format(connFormat, Server.DatabasePooling); }
|
||||
}
|
||||
public override bool EnforcesTextLength { get { return false; } }
|
||||
|
||||
public override BulkTransaction CreateBulk() {
|
||||
return new SQLiteBulkTransaction(ConnectionString);
|
||||
@ -49,5 +50,15 @@ namespace MCGalaxy.SQL {
|
||||
using (DataTable results = Database.Fill(syntax, table))
|
||||
return results.Rows.Count > 0;
|
||||
}
|
||||
|
||||
public override void RenameTable(string srcTable, string dstTable) {
|
||||
string syntax = "ALTER TABLE `" + srcTable + "` RENAME TO `" + dstTable + "`";
|
||||
Database.Execute(syntax);
|
||||
}
|
||||
|
||||
public override void ClearTable(string table) {
|
||||
string syntax = "DELETE FROM `" + table + "`";
|
||||
Database.Execute(syntax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,24 +55,19 @@ namespace MCGalaxy {
|
||||
}
|
||||
BotsFile.MoveBots(src, dst);
|
||||
|
||||
//safe against SQL injections because foundLevel is being checked and,
|
||||
//newName is being split and partly checked on illegal characters reserved for Windows.
|
||||
string syntax = Server.useMySQL
|
||||
? "RENAME TABLE `{2}{0}` TO `{2}{1}`" : "ALTER TABLE `{2}{0}` RENAME TO `{2}{1}`";
|
||||
Database.Execute(String.Format(syntax, src, dst, "Block"));
|
||||
|
||||
Database.Backend.RenameTable("Block" + src, "Block" + dst);
|
||||
object locker = ThreadSafeCache.DBCache.Get(src);
|
||||
lock (locker) {
|
||||
if (Database.TableExists("Portals" + src)) {
|
||||
Database.Execute(String.Format(syntax, src, dst, "Portals"));
|
||||
Database.Backend.RenameTable("Portals" + src, "Portals" + dst);
|
||||
string updateSyntax = "UPDATE `Portals" + dst + "` SET ExitMap=@1 WHERE ExitMap=@0";
|
||||
Database.Execute(updateSyntax, src, dst);
|
||||
}
|
||||
if (Database.TableExists("Messages" + src)) {
|
||||
Database.Execute(String.Format(syntax, src, dst, "Messages"));
|
||||
Database.Backend.RenameTable("Messages" + src, "Messages" + dst);
|
||||
}
|
||||
if (Database.TableExists("Zone" + src)) {
|
||||
Database.Execute(String.Format(syntax, src, dst, "Zone"));
|
||||
Database.Backend.RenameTable("Zone" + src, "Zone" + dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user