Skip to content

Commit eaedf4e

Browse files
committed
Added TableSize Reporting for SqlLite #58
1 parent 7afe143 commit eaedf4e

File tree

5 files changed

+81
-11
lines changed

5 files changed

+81
-11
lines changed

src/LemonTree.Pipeline.Tools.ModelCheck/Checks/Checks.cs

+41-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
using System;
2+
using System;
33
using System.Data;
44
using System.Diagnostics;
55
using System.Globalization;
@@ -399,7 +399,7 @@ select count(t_object.Object_Type) as ['Count'], t_object.Object_Type as ['Measu
399399

400400
#region process result table and calculate Issue number
401401

402-
402+
403403

404404

405405
#endregion
@@ -421,7 +421,42 @@ select count(t_object.Object_Type) as ['Count'], t_object.Object_Type as ['Measu
421421
return result;
422422
}
423423

424+
internal static Issue CheckTableSize(string model)
425+
{
426+
#region get result table
427+
428+
const string statisticSql = @"SELECT name ,SUM(pgsize)/1024 table_size FROM 'dbstat' GROUP BY name ORDER BY table_size desc;";
429+
430+
var resultTable = ModelAccess.RunSql(statisticSql);
431+
resultTable.DefaultView.Sort = "table_size";
432+
433+
434+
Console.WriteLine(ToMD(resultTable, header: true));
435+
436+
#endregion
437+
438+
439+
#region process result table and calculate Issue number
440+
441+
442+
#endregion
443+
444+
#region set Issue Level
445+
446+
Issue result = new Issue();
447+
448+
result.Level = IssueLevel.Information;
449+
result.Title = "Table Statistics";
450+
451+
452+
453+
result.Detail = ToMD(resultTable.DefaultView.ToTable(), header: true);
424454

455+
456+
#endregion
457+
458+
return result;
459+
}
425460
private static string ToMD(DataTable t, bool header)
426461
{
427462

@@ -440,8 +475,8 @@ private static string ToMD(DataTable t, bool header)
440475
{
441476

442477
sb.Append("|");
443-
sb.Append(c.ColumnName.Replace("'",""));
444-
478+
sb.Append(c.ColumnName.Replace("'", ""));
479+
445480
}
446481
sb.Append("|");
447482
sb.Append(Environment.NewLine);
@@ -466,7 +501,7 @@ private static string ToMD(DataTable t, bool header)
466501

467502
sb.Append("|");
468503
sb.Append(item);
469-
504+
470505
}
471506
sb.Append("|");
472507
sb.Append(Environment.NewLine);
@@ -477,6 +512,7 @@ private static string ToMD(DataTable t, bool header)
477512
return sb.ToString();
478513

479514
}
515+
480516
}
481517
}
482518

src/LemonTree.Pipeline.Tools.ModelCheck/CommandLineOptions/ModelCheckOptions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ internal class ModelCheckOptions:BaseOptions
1616

1717
[Option("FailOnWarnings", Required = false, HelpText = "If set the Exitcode will be 1 if there is at least on Check of Status Warning!")]
1818
public bool FailOnWarnings { get; set; }
19+
20+
[Option("TableSize", Required = false, HelpText = "If set the size of the tables in the database will be reported!")]
21+
public bool TableSize { get; set; }
1922
}
2023
}

src/LemonTree.Pipeline.Tools.ModelCheck/Program.cs

+23-5
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,33 @@ private static int RunModelCheck(ModelCheckOptions opts)
7575

7676
Console.WriteLine(issues.ToString());
7777

78+
StringBuilder sb = new StringBuilder();
79+
sb.AppendLine(issues.ToMd());
80+
sb.AppendLine("# Project Statistics");
81+
sb.AppendLine(Checks.Checks.CheckProjectStatitics(opts.Model).Detail);
82+
83+
if (opts.TableSize == true)
84+
{
85+
if (ModelAccess.IsSqlLite())
86+
{
87+
sb.AppendLine(Checks.Checks.CheckTableSize(opts.Model).Detail);
88+
}
89+
else
90+
{
91+
Console.WriteLine("Talbesize reporting only supported for SqlLite!");
92+
}
93+
}
94+
95+
96+
97+
7898
if (opts.Out != null)
7999
{
80-
StringBuilder sb = new StringBuilder();
81-
sb.AppendLine(issues.ToMd());
82-
sb.AppendLine("# Project Statistics");
83-
sb.AppendLine(Checks.Checks.CheckProjectStatitics(opts.Model).Detail);
84-
File.WriteAllText(opts.Out, sb.ToString());
100+
File.WriteAllText(opts.Out, sb.ToString());
85101
}
86102

103+
104+
87105
if (opts.FailOnErrors == true)
88106
{
89107
if (issues.HasErrors())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"LemonTree.Pipeline.Tools.ModelCheck": {
4+
"commandName": "Project",
5+
"commandLineArgs": "--model models\\model.qeax --tablesize"
6+
}
7+
}
8+
}

src/LemonTree.Pipeline.Tools/ModelAccess.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public static string GetWildcard()
113113
{
114114
throw new Exception("Model not set");
115115
}
116-
}
116+
}
117+
118+
public static bool IsSqlLite()
119+
{
120+
return eaDatabase is SqLiteDatabase;
121+
}
117122
}
118123
}

0 commit comments

Comments
 (0)