Fix /top timespent on mysql backend, closes #423.

This commit is contained in:
UnknownShadow200 2017-05-12 11:14:23 +10:00
parent 651268bce1
commit 8da596c0fd
3 changed files with 25 additions and 9 deletions

View File

@ -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) {

View File

@ -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())
{
using (StreamReader reader = new StreamReader(sql)) {
ImportBulk(reader);
}
}
static void ImportBulk(StreamReader reader) {
BulkTransaction helper = null;
List<string> buffer = new List<string>();
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();
}
}