mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -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,
|
new TopStat("TimeSpent", PlayerData.DBTable,
|
||||||
PlayerData.ColumnTimeSpent,
|
PlayerData.ColumnTimeSpent,
|
||||||
() => "Most time spent", FormatTimespan,
|
() => "Most time spent", FormatTimespan,
|
||||||
false, " CAST(TimeSpent as BIGINT) "),
|
false, " CAST(TimeSpent as unsigned) "),
|
||||||
};
|
};
|
||||||
|
|
||||||
public static string FormatInteger(string input) {
|
public static string FormatInteger(string input) {
|
||||||
|
@ -117,10 +117,18 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
internal static void ImportSql(Stream sql) {
|
internal static void ImportSql(Stream sql) {
|
||||||
// Import data (we only have CREATE TABLE and INSERT INTO statements)
|
// 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>();
|
List<string> buffer = new List<string>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
helper = Database.Backend.CreateBulk();
|
||||||
while (!reader.EndOfStream) {
|
while (!reader.EndOfStream) {
|
||||||
string cmd = NextStatement(reader, buffer);
|
string cmd = NextStatement(reader, buffer);
|
||||||
if (cmd == null || cmd.Length == 0) continue;
|
if (cmd == null || cmd.Length == 0) continue;
|
||||||
@ -129,9 +137,17 @@ namespace MCGalaxy {
|
|||||||
if (index > -1) ParseCreate(ref cmd, index);
|
if (index > -1) ParseCreate(ref cmd, index);
|
||||||
|
|
||||||
//Run the command in the transaction.
|
//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();
|
helper.Commit();
|
||||||
|
} finally {
|
||||||
|
if (helper != null) helper.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user