forked from ClassiCube/MCGalaxy-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CmdBiggestTables.cs
44 lines (36 loc) · 1.42 KB
/
CmdBiggestTables.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
reference System.Data.dll
reference System.dll
reference System.Xml.dll
using System;
using System.Collections.Generic;
using System.Data;
using MCGalaxy.SQL;
namespace MCGalaxy {
public sealed class CmdBiggestTables : Command {
public override string name { get { return "BiggestTables"; } }
public override string type { get { return CommandTypes.Information; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
struct TableEntry { public string Name; public int Count; }
public override void Use(Player p, string message) {
List<string> tables = Database.Backend.AllTables();
TableEntry[] entries = new TableEntry[tables.Count];
for (int i = 0; i < tables.Count; i++) {
try {
DataTable maxTable = Database.Backend.GetRows(tables[i], "MAX(_ROWID_)", "LIMIT 1");
if (maxTable.Rows.Count == 0) continue;
string row = maxTable.Rows[0]["MAX(_ROWID_)"].ToString();
maxTable.Dispose();
int count;
if (!int.TryParse(row, out count) || count == 0) continue;
entries[i] = new TableEntry() { Name = tables[i], Count = count };
} catch {
}
}
Array.Sort<TableEntry>(entries, (a, b) => b.Count.CompareTo(a.Count));
for (int i = 0; i < Math.Min(20, entries.Length); i++) {
Player.Message(p, "Table {0} has {1} entries", entries[i].Name, entries[i].Count);
}
}
public override void Help(Player p) { }
}
}