mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Fix /top timespent on mysql backend, closes #423.
This commit is contained in:
parent
651268bce1
commit
8da596c0fd
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user