private static void _DisplayTable(UniqueTable udt, bool more, ApplicationCommand cmd) { DataTable table = udt.Table; if (table == null) { return; } if (cmd.Has("json")) { cout.WriteLine(table.WriteJson(JsonStyle.Normal, excludeTableName: false)); return; } #if WINDOWS if (cmd.Has("edit")) { var editor = new Windows.TableEditor(udt); editor.ShowDialog(); return; } #endif int maxColumnWidth = Config.console.table.grid.MaxColumnWidth; table.ToConsole(vertical: cmd.IsVertical, more: more, outputDbNull: true, maxColumnWidth); }
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 void Run() { if (cmd.Has("zip")) { ProcessZipArchive(); } else if (cmd.Has("resource")) { ImportResourceData(); } else if (cmd.Has("extract-string")) { ExtractStringList(); } else { cerr.WriteLine("invalid command options"); } }
public void ExportInsertOrUpdateData(SqlScriptType type) { var option = new SqlScriptGenerationOption { HasIfExists = cmd.HasIfExists, InsertWithoutColumns = cmd.Has("no-columns"), }; if (tname != null) { var node = mgr.GetCurrentNode <Locator>(); int count = 0; using (var writer = SqlFileName.CreateStreamWriter(cmd.Append)) { //cout.WriteLine($"start to generate {tname} script to file: \"{SqlFileName}\""); Locator locator = null; string WHERE = ""; if (node != null) { locator = mgr.GetCombinedLocator(node); WHERE = $" WHERE {locator}"; } long cnt = tname.GetTableRowCount(locator); count = Tools.ForceLongToInteger(cnt); using (var progress = new ProgressBar { Count = count }) { count = Compare.GenerateRows(type, writer, new TableSchema(tname), locator, option, progress); } cout.WriteLine($"{type} clauses (SELECT * FROM {tname}{WHERE}) generated to \"{SqlFileName}\", Done on rows({cnt})"); } } else if (dname != null) { //cout.WriteLine($"start to generate {dname} script to file: \"{SqlFileName}\""); using (var writer = SqlFileName.CreateStreamWriter(cmd.Append)) { var md = new MatchedDatabase(dname, cmd); TableName[] tnames = md.TableNames(); if (tnames.Length > 5 && !cin.YesOrNo($"Are you sure to export {tnames.Length} tables on {dname} (y/n)?")) { return; } CancelableWork.CanCancel(cts => { foreach (var tn in tnames) { if (cts.IsCancellationRequested) { return; } long cnt = tn.GetTableRowCount(); if (cnt > cfg.MaxRows) { if (!cin.YesOrNo($"Are you sure to export {cnt} rows on {tn.ShortName} (y/n)?")) { cout.WriteLine("\n{0,10} skipped", tn.ShortName); continue; } } int count = Tools.ForceLongToInteger(cnt); using (var progress = new ProgressBar { Count = count }) { count = Compare.GenerateRows(type, writer, new TableSchema(tn), null, option, progress); } cout.WriteLine($"{count,10} row(s) generated on {tn.ShortName}"); } cout.WriteLine($"completed to generate {type} clauses to \"{SqlFileName}\""); }); } } else { cerr.WriteLine("warning: table or database is not selected"); } }
private static void _DisplayColumnNodes(ApplicationCommand cmd, TableName tname) { TableSchema schema = new TableSchema(tname); cout.WriteLine("TABLE: {0}", tname.Path); bool hasJson = cmd.Has("json"); VAL lines = new VAL(); int i = 0; int count = 0; int h = 0; foreach (IColumn column in schema.Columns) { if (IsMatch(cmd.wildcard, column.ColumnName)) { count++; List <string> L = new List <string>(); if (column.IsIdentity) { L.Add("++"); } if (column.IsPrimary) { L.Add("pk"); } string fk = string.Empty; ColumnSchema col = column as ColumnSchema; if (col.IsForeignKey) { L.Add("fk"); if (cmd.HasForeignKey) { fk = $"-> {col.PK_Schema}.[{col.PK_Table}].[{col.PK_Column}]"; } } string keys = string.Join(",", L); if (!hasJson) { cout.WriteLine("{0,5} {1,26} {2,-16} {3,10} {4,10} {5}", sub(++i), string.Format("[{0}]", column.ColumnName), column.GetSQLType(), keys, column.Nullable ? "null" : "not null", fk); } else { VAL line = new VAL(); if (keys != "") { line.AddMember("Key", keys); } line.AddMember("Column", column.ColumnName); line.AddMember("Type", column.GetSQLType()); if (column.Nullable) { line.AddMember("Null", column.Nullable); } lines.Add(line); } h = PagePause(cmd, ++h); } } if (!hasJson) { cout.WriteLine("\t{0} Column(s)", count); } else { cout.WriteLine(lines.ToJson()); } }