diff --git a/MCGalaxy/Commands/Chat/CmdInbox.cs b/MCGalaxy/Commands/Chat/CmdInbox.cs index 757b7ace2..30715b6ed 100644 --- a/MCGalaxy/Commands/Chat/CmdInbox.cs +++ b/MCGalaxy/Commands/Chat/CmdInbox.cs @@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Chatting { if (args.Length == 1) { Player.Message(p, "You need to provide either \"all\" or a number."); return; } else if (args[1].CaselessEq("all")) { - Database.Backend.ClearTable("Inbox" + p.name); + Database.Backend.DeleteRows("Inbox" + p.name); Player.Message(p, "Deleted all messages."); } else { DeleteByID(p, args[1], entries); @@ -81,7 +81,8 @@ namespace MCGalaxy.Commands.Chatting { } static void Output(Player p, string[] entry) { - TimeSpan delta = DateTime.Now - DateTime.Parse(entry[i_sent]); + DateTime time = DateTime.ParseExact(entry[i_sent], Database.DateFormat, null); + TimeSpan delta = DateTime.Now - time; string sender = PlayerInfo.GetColoredName(p, entry[i_from]); Player.Message(p, "From {0} &a{1} ago:", sender, delta.Shorten()); diff --git a/MCGalaxy/Commands/Information/CmdAbout.cs b/MCGalaxy/Commands/Information/CmdAbout.cs index 59bfbe5d6..8c478eeed 100644 --- a/MCGalaxy/Commands/Information/CmdAbout.cs +++ b/MCGalaxy/Commands/Information/CmdAbout.cs @@ -86,7 +86,7 @@ namespace MCGalaxy.Commands.Info { entry.OldRaw = Block.Invalid; foreach (string[] row in entries) { - DateTime time = DateTime.Parse(row[1]); + DateTime time = DateTime.ParseExact(row[1], Database.DateFormat, null); TimeSpan delta = time - BlockDB.Epoch; entry.TimeDelta = (int)delta.TotalSeconds; entry.Flags = BlockDBFlags.ManualPlace; diff --git a/MCGalaxy/Commands/Information/CmdOpStats.cs b/MCGalaxy/Commands/Information/CmdOpStats.cs index 8809f7869..3f6cc16a7 100644 --- a/MCGalaxy/Commands/Information/CmdOpStats.cs +++ b/MCGalaxy/Commands/Information/CmdOpStats.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Info { public override bool UseableWhenFrozen { get { return true; } } public override void Use(Player p, string message) { - string end = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + string end = DateTime.Now.ToString(Database.DateFormat); string start = "thismonth", name = null; string[] args = message.SplitSpaces(); diff --git a/MCGalaxy/Commands/Maintenance/CmdPlayerEdit.cs b/MCGalaxy/Commands/Maintenance/CmdPlayerEdit.cs index d8f1bba6a..03192db88 100644 --- a/MCGalaxy/Commands/Maintenance/CmdPlayerEdit.cs +++ b/MCGalaxy/Commands/Maintenance/CmdPlayerEdit.cs @@ -129,13 +129,13 @@ namespace MCGalaxy.Commands.Maintenance { static void SetDate(Player p, string[] args, string column, Player who, Action setter) { if (args.Length < 3) { - Player.Message(p, "Dates must be in the format: yyyy-mm-dd hh:mm:ss"); + Player.Message(p, "Dates must be in the format: " + Database.DateFormat); return; } DateTime date; if (!DateTime.TryParseExact(args[2], Database.DateFormat, null, 0, out date)) { - Player.Message(p, "Invalid date. (must be in format: yyyy-mm-dd hh:mm:ss"); + Player.Message(p, "Invalid date. It must be in format: " + Database.DateFormat); return; } diff --git a/MCGalaxy/Database/Backends/MySQL.cs b/MCGalaxy/Database/Backends/MySQL.cs index 54b48c5c8..483e35dd3 100644 --- a/MCGalaxy/Database/Backends/MySQL.cs +++ b/MCGalaxy/Database/Backends/MySQL.cs @@ -44,8 +44,8 @@ namespace MCGalaxy.SQL { public override void CreateDatabase() { - string syntax = "CREATE DATABASE if not exists `" + ServerConfig.MySQLDatabaseName + "`"; - Database.Do(syntax, true, null, null); + string sql = "CREATE DATABASE if not exists `" + ServerConfig.MySQLDatabaseName + "`"; + Database.Do(sql, true, null, null); } public override BulkTransaction CreateBulk() { @@ -106,14 +106,8 @@ namespace MCGalaxy.SQL { public override void RenameTable(string srcTable, string dstTable) { ValidateTable(srcTable); ValidateTable(dstTable); - string syntax = "RENAME TABLE `" + srcTable + "` TO `" + dstTable + "`"; - Database.Execute(syntax); - } - - public override void ClearTable(string table) { - ValidateTable(table); - string syntax = "TRUNCATE TABLE `" + table + "`"; - Database.Execute(syntax); + string sql = "RENAME TABLE `" + srcTable + "` TO `" + dstTable + "`"; + Database.Execute(sql, null); } protected override void CreateTableColumns(StringBuilder sql, ColumnDesc[] columns) { @@ -161,10 +155,9 @@ namespace MCGalaxy.SQL { public override void AddColumn(string table, ColumnDesc col, string colAfter) { ValidateTable(table); - string syntax = "ALTER TABLE `" + table + "` ADD COLUMN " - + col.Column + " " + col.FormatType(); - if (colAfter.Length > 0) syntax += " AFTER " + colAfter; - Database.Execute(syntax); + string sql = "ALTER TABLE `" + table + "` ADD COLUMN " + col.Column + " " + col.FormatType(); + if (colAfter.Length > 0) sql += " AFTER " + colAfter; + Database.Execute(sql, null); } public override void AddOrReplaceRow(string table, string columns, params object[] args) { diff --git a/MCGalaxy/Database/Backends/SQLite.cs b/MCGalaxy/Database/Backends/SQLite.cs index 28f2c46dd..c8509b374 100644 --- a/MCGalaxy/Database/Backends/SQLite.cs +++ b/MCGalaxy/Database/Backends/SQLite.cs @@ -67,8 +67,8 @@ namespace MCGalaxy.SQL { } public override List AllTables() { - const string syntax = "SELECT name from sqlite_master WHERE type='table'"; - List tables = Database.GetStrings(syntax); + const string sql = "SELECT name from sqlite_master WHERE type='table'"; + List tables = Database.GetStrings(sql); // exclude sqlite built-in database tables for (int i = tables.Count - 1; i >= 0; i--) { @@ -88,21 +88,15 @@ namespace MCGalaxy.SQL { List columns = new List(); Database.Iterate("PRAGMA table_info(`" + table + "`)", - columns, IterateColumnNames); + columns, IterateColumnNames, null); return columns; } public override void RenameTable(string srcTable, string dstTable) { ValidateTable(srcTable); ValidateTable(dstTable); - string syntax = "ALTER TABLE `" + srcTable + "` RENAME TO `" + dstTable + "`"; - Database.Execute(syntax); - } - - public override void ClearTable(string table) { - ValidateTable(table); - string syntax = "DELETE FROM `" + table + "`"; - Database.Execute(syntax); + string sql = "ALTER TABLE `" + srcTable + "` RENAME TO `" + dstTable + "`"; + Database.Execute(sql, null); } protected override void CreateTableColumns(StringBuilder sql, ColumnDesc[] columns) { @@ -136,12 +130,11 @@ namespace MCGalaxy.SQL { } public override void PrintSchema(string table, TextWriter w) { - const string syntax = "SELECT sql from sqlite_master WHERE tbl_name = @0 AND type = 'table'"; - List all = Database.GetStrings(syntax + CaselessWhereSuffix, table); + string sql = "SELECT sql from sqlite_master WHERE tbl_name = @0 AND type = 'table'"; + List all = Database.GetStrings(sql + CaselessWhereSuffix, table); for (int i = 0; i < all.Count; i++) { - string sql = all[i]; - sql = sql.Replace(" " + table, " `" + table + "`"); + sql = all[i].Replace(" " + table, " `" + table + "`"); sql = sql.Replace("CREATE TABLE `" + table + "`", "CREATE TABLE IF NOT EXISTS `" + table + "`"); w.WriteLine(sql + ";"); } @@ -149,8 +142,8 @@ namespace MCGalaxy.SQL { public override void AddColumn(string table, ColumnDesc col, string colAfter) { ValidateTable(table); - string syntax = "ALTER TABLE `" + table + "` ADD COLUMN " + col.Column + " " + col.FormatType(); - Database.Execute(syntax); + string sql = "ALTER TABLE `" + table + "` ADD COLUMN " + col.Column + " " + col.FormatType(); + Database.Execute(sql, null); } public override void AddOrReplaceRow(string table, string columns, params object[] args) { diff --git a/MCGalaxy/Database/IDatabaseBackend.cs b/MCGalaxy/Database/IDatabaseBackend.cs index d7d36663c..de43ffb0f 100644 --- a/MCGalaxy/Database/IDatabaseBackend.cs +++ b/MCGalaxy/Database/IDatabaseBackend.cs @@ -74,9 +74,6 @@ namespace MCGalaxy.SQL { /// Renames the source table to the given name. public abstract void RenameTable(string srcTable, string dstTable); - /// Removes all entries from the given table. - public abstract void ClearTable(string table); - /// Creates a new table in the database (unless it already exists). public virtual void CreateTable(string table, ColumnDesc[] columns) { ValidateTable(table); @@ -84,7 +81,7 @@ namespace MCGalaxy.SQL { sql.AppendLine("CREATE TABLE if not exists `" + table + "` ("); CreateTableColumns(sql, columns); sql.AppendLine(");"); - Database.Execute(sql.ToString()); + Database.Execute(sql.ToString(), null); } protected abstract void CreateTableColumns(StringBuilder sql, ColumnDesc[] columns); @@ -92,8 +89,8 @@ namespace MCGalaxy.SQL { /// Completely removes the given table. public virtual void DeleteTable(string table) { ValidateTable(table); - string syntax = "DROP TABLE `" + table + "`"; - Database.Execute(syntax); + string sql = "DROP TABLE `" + table + "`"; + Database.Execute(sql, null); } /// Prints/dumps the table schema of the given table. @@ -114,8 +111,8 @@ namespace MCGalaxy.SQL { public virtual void CopyAllRows(string srcTable, string dstTable) { ValidateTable(srcTable); ValidateTable(dstTable); - string syntax = "INSERT INTO `" + dstTable + "` SELECT * FROM `" + srcTable + "`"; - Database.Execute(syntax); + string sql = "INSERT INTO `" + dstTable + "` SELECT * FROM `" + srcTable + "`"; + Database.Execute(sql, null); } /// Iterates over read rows for the given table. @@ -124,9 +121,9 @@ namespace MCGalaxy.SQL { public virtual object ReadRows(string table, string columns, object arg, ReaderCallback callback, string modifier = "", params object[] args) { ValidateTable(table); - string syntax = "SELECT " + columns + " FROM `" + table + "`"; - if (modifier.Length > 0) syntax += " " + modifier; - return Database.Iterate(syntax, arg, callback, args); + string sql = "SELECT " + columns + " FROM `" + table + "`"; + if (modifier.Length > 0) sql += " " + modifier; + return Database.Iterate(sql, arg, callback, args); } /// Updates rows for the given table. @@ -134,18 +131,18 @@ namespace MCGalaxy.SQL { public virtual void UpdateRows(string table, string columns, string modifier = "", params object[] args) { ValidateTable(table); - string syntax = "UPDATE `" + table + "` SET " + columns; - if (modifier.Length > 0) syntax += " " + modifier; - Database.Execute(syntax, args); + string sql = "UPDATE `" + table + "` SET " + columns; + if (modifier.Length > 0) sql += " " + modifier; + Database.Execute(sql, args); } /// Deletes rows for the given table. /// modifier is optional SQL which can be used to delete only certain rows. public virtual void DeleteRows(string table, string modifier = "", params object[] args) { ValidateTable(table); - string syntax = "DELETE FROM `" + table + "`"; - if (modifier.Length > 0) syntax += " " + modifier; - Database.Execute(syntax, args); + string sql = "DELETE FROM `" + table + "`"; + if (modifier.Length > 0) sql += " " + modifier; + Database.Execute(sql, args); } /// Adds a row to the given table. diff --git a/MCGalaxy/Database/Stats/TopStat.cs b/MCGalaxy/Database/Stats/TopStat.cs index f2a9161e2..16a95aa89 100644 --- a/MCGalaxy/Database/Stats/TopStat.cs +++ b/MCGalaxy/Database/Stats/TopStat.cs @@ -17,6 +17,7 @@ */ using System; using System.Collections.Generic; +using MCGalaxy.SQL; namespace MCGalaxy.DB { @@ -112,7 +113,7 @@ namespace MCGalaxy.DB { } public static string FormatDate(string input) { - DateTime time = DateTime.Parse(input); + DateTime time = DateTime.ParseExact(input, Database.DateFormat, null); TimeSpan delta = DateTime.Now - time; return string.Format("{0:H:mm} on {0:d} ({1} ago)", time, delta.Shorten()); } diff --git a/MCGalaxy/Server/Tasks/UpgradeTasks.cs b/MCGalaxy/Server/Tasks/UpgradeTasks.cs index 0d3550244..f9aaf6f32 100644 --- a/MCGalaxy/Server/Tasks/UpgradeTasks.cs +++ b/MCGalaxy/Server/Tasks/UpgradeTasks.cs @@ -262,7 +262,6 @@ namespace MCGalaxy.Tasks { cmd.ExecuteNonQuery(); } } - bulk.Commit(); } }