public bool Display(ApplicationCommand cmd) { string[] columns = cmd.Columns; if (cmd.Has("dup")) { DuplicatedTable dup = new DuplicatedTable(tname, columns); if (dup.group.Rows.Count == 0) { cout.WriteLine("no duplicated record found"); return(true); } if (cmd.IsSchema) { Display(cmd, dup.group, 0); } else { dup.Dispaly(dt => Display(cmd, dt, 0)); } return(true); } SqlBuilder builder; int top = cmd.Top; if (tname.Provider.DpType == DbProviderType.Sqlite) { top = 0; } bool hasRowId = cmd.HasRowId; Locator locator = Locator.Empty; if (cmd.wildcard != null) { locator = LikeExpr(cmd.wildcard, cmd.Columns); } else if (cmd.where != null) { locator = new Locator(cmd.where); } builder = new SqlBuilder().SELECT().TOP(top); if (hasRowId) { builder.COLUMNS(UniqueTable.ROWID_COLUMN(tname)); } builder.COLUMNS(columns).FROM(tname).WHERE(locator); return(Display(cmd, builder, tname, top)); }
public bool Display(Command cmd) { SqlBuilder builder; int top = cmd.top; string[] columns = cmd.Columns; if (cmd.wildcard != null) { string where = LikeExpr(cmd.wildcard, cmd.Columns); builder = new SqlBuilder().SELECT.ROWID(cmd.HasRowId).COLUMNS().FROM(tname).WHERE(where); } else if (cmd.where != null) { var locator = new Locator(cmd.where); builder = new SqlBuilder().SELECT.TOP(top).ROWID(cmd.HasRowId).COLUMNS(columns).FROM(tname).WHERE(locator); } else if (cmd.Has("dup")) { DuplicatedTable dup = new DuplicatedTable(tname, columns); if (dup.group.Rows.Count == 0) { stdio.WriteLine("no duplicated record found"); return true; } if (cmd.IsSchema) { Display(cmd, dup.group, 0); } else { dup.Dispaly(dt => Display(cmd, dt, 0)); } return true; } else builder = new SqlBuilder().SELECT.TOP(top).ROWID(cmd.HasRowId).COLUMNS(columns).FROM(tname); return Display(cmd, builder, tname, top); }
public void clean(Command cmd, Configuration cfg) { if (cmd.HasHelp) { stdio.WriteLine("clean duplicated rows"); stdio.WriteLine("clean [path]|[pattern]| : clean current database or table, or search pattern"); stdio.WriteLine("options:"); stdio.WriteLine(" /col:c1,c2,.. : clean columns, compare column c1, c2, ..."); stdio.WriteLine(" /d : commit cleaning duplicated rows on database server, otherwise display # of duplicated rows"); stdio.WriteLine("example:"); stdio.WriteLine("clean match*s /col:c1,c2 : clean duplicated rows by comparing columns:c1 and c2"); stdio.WriteLine("clean : clean by comparing entire row"); return; } if (!Navigate(cmd.Path1)) return; if (pt.Item is TableName) { var tname = (TableName)pt.Item; var dup = new DuplicatedTable(tname, cmd.Columns); if (cmd.Has("d")) { int count = dup.Clean(); stdio.WriteLine("completed to clean {0} #rows at {1}", count, tname); } else { int count = dup.DuplicatedRowCount(); if (count == 0) stdio.WriteLine("no duplicated rows at {0}", tname); else stdio.WriteLine("{0} duplicated row(s) at {1}", count, tname); } return; } if (pt.Item is DatabaseName) { var dname = (DatabaseName)pt.Item; var m = new MatchedDatabase(dname, cmd.wildcard, cfg.compareExcludedTables); var T = m.MatchedTableNames; CancelableWork.CanCancel(cts => { foreach (var tn in T) { if (cts.IsCancellationRequested) return; if (cmd.Has("d")) { stdio.WriteLine("start to clean {0}", tn); var dup = new DuplicatedTable(tn, cmd.Columns); int count = dup.Clean(); stdio.WriteLine("cleaned {0} #rows", count); } else { stdio.WriteLine("start to query {0}", tn); var dup = new DuplicatedTable(tn, cmd.Columns); int count = dup.DuplicatedRowCount(); if (count == 0) stdio.WriteLine("distinct rows"); else stdio.WriteLine("{0} duplicated row(s)", count, tn); } } }); return; } stdio.ErrorFormat("select database or table first"); }