diff --git a/MCGalaxy/Commands/Information/CmdTop.cs b/MCGalaxy/Commands/Information/CmdTop.cs index 441536d1e..eee442509 100644 --- a/MCGalaxy/Commands/Information/CmdTop.cs +++ b/MCGalaxy/Commands/Information/CmdTop.cs @@ -49,7 +49,7 @@ namespace MCGalaxy.Commands.Info { string strLimit = " LIMIT " + offset + "," + limit; DataTable db = Database.Backend.GetRows(stat.Table, "DISTINCT Name, " + stat.Column, - "ORDER BY " + stat.OrderBy + strLimit); + "ORDER BY" + stat.OrderBy + strLimit); Player.Message(p, "&a{0}:", stat.Title()); for (int i = 0; i < db.Rows.Count; i++) { diff --git a/MCGalaxy/Database/Stats/TopStat.cs b/MCGalaxy/Database/Stats/TopStat.cs index 3efef7597..15df282ff 100644 --- a/MCGalaxy/Database/Stats/TopStat.cs +++ b/MCGalaxy/Database/Stats/TopStat.cs @@ -39,7 +39,7 @@ namespace MCGalaxy.DB { OrderBy = orderBy; if (OrderBy == null) OrderBy = " " + col + " "; - OrderBy += (ascending ? " asc" : " desc"); + OrderBy += (ascending ? "asc" : "desc"); } /// List of stats that can be ordered. @@ -85,7 +85,7 @@ namespace MCGalaxy.DB { new TopStat("TimeSpent", PlayerData.DBTable, PlayerData.ColumnTimeSpent, () => "Most time spent", FormatTimespan, - false, " CAST(TimeSpent as BIGINT) "), + false, " CAST(TimeSpent as unsigned) "), }; public static string FormatInteger(string input) { diff --git a/MCGalaxy/Server/BackupDB.cs b/MCGalaxy/Server/BackupDB.cs index b4863e0c3..8f53bacea 100644 --- a/MCGalaxy/Server/BackupDB.cs +++ b/MCGalaxy/Server/BackupDB.cs @@ -117,10 +117,18 @@ namespace MCGalaxy { internal static void ImportSql(Stream sql) { // Import data (we only have CREATE TABLE and INSERT INTO statements) - using (StreamReader reader = new StreamReader(sql)) - using (BulkTransaction helper = Database.Backend.CreateBulk()) - { - List buffer = new List(); + + using (StreamReader reader = new StreamReader(sql)) { + ImportBulk(reader); + } + } + + static void ImportBulk(StreamReader reader) { + BulkTransaction helper = null; + List buffer = new List(); + + try { + helper = Database.Backend.CreateBulk(); while (!reader.EndOfStream) { string cmd = NextStatement(reader, buffer); if (cmd == null || cmd.Length == 0) continue; @@ -129,9 +137,17 @@ namespace MCGalaxy { if (index > -1) ParseCreate(ref cmd, index); //Run the command in the transaction. - helper.Execute(cmd); + if (helper.Execute(cmd)) continue; + + // Something went wrong.. commit what we've imported so far. + // We need to recreate connection otherwise every helper.Execute fails + helper.Commit(); + helper.Dispose(); + helper = Database.Backend.CreateBulk(); } helper.Commit(); + } finally { + if (helper != null) helper.Dispose(); } } @@ -164,7 +180,7 @@ namespace MCGalaxy { char[] sepChars = new char[] { '\t', ' ' }; // chars that separate part of a column definition char[] startChars = new char[] { '`', '(', ' ', ',', '\t' }; // chars that can start a column definition string before = cmd.Substring(0, priIndex); - before = before.Substring(0, before.LastIndexOfAny(sepChars)); // get rid of column type + before = before.Substring(0, before.LastIndexOfAny(sepChars)); // get rid of column type int nameStart = before.LastIndexOfAny(startChars) + 1; string name = before.Substring(nameStart);