public override void NotifyChangeDatabase(IDatabaseSource src) { if (src.Dialect.DialectCaps.UseDatabaseAsSchema) { Name = new NameWithSchema(src.DatabaseName, Name.Name); } }
public MultiTableUpdateScript GetLinkedDataScript(NameWithSchema basetable) { var res = new MultiTableUpdateScript(); if (ResultFields == null || !ResultFields.IsMultiTable()) { return(res); } var pks = new Dictionary <DmlfSource, List <DmlfColumnRef> >(); foreach (var row in Rows) { if (row.RowState != CdlRowState.Modified) { continue; } var changed = row.GetChangedColumnRefs(); if (changed.Length == 0) { continue; } var tbls = new List <DmlfSource>(); foreach (var ch in changed) { if (!tbls.Contains(ch.Source)) { tbls.Add(ch.Source); } } foreach (var src in tbls) { if (pks.ContainsKey(src)) { continue; } pks[src] = ResultFields.GetPrimaryKey(src); } foreach (var src in tbls) { var cols = new List <DmlfColumnRef>(); foreach (var ch in changed) { if (ch.Source != src) { continue; } cols.Add(ch); } var pk = pks[src]; res.Update(src == DmlfSource.BaseTable ? basetable : src.TableOrView, (from c in pk select c.ColumnName).ToArray(), row.Original.GetValuesByCols(pk.ToArray(), ResultFields), (from c in cols select c.ColumnName).ToArray(), row.GetValuesByCols(cols.ToArray())); } } return(res); }
private DataTable CachedLoadProgrammable(NameWithSchema obj) { var res = AnalyserCache.GetProgrammable(obj); if (res != null) { return(res); } res = AnalyserCache.GetProgrammable(null); if (res != null) { return(FilterProgrammable(res, obj)); } if (LoadMoreSpecificObjects) { res = LoadProgrammableTable(null); AnalyserCache.PutProgrammable(null, res); return(FilterProgrammable(res, obj)); } else { res = LoadProgrammableTable(obj); AnalyserCache.PutProgrammable(obj, res); return(res); } }
public void NotifyChangeDatabase(IDatabaseSource src) { if (src.Dialect.DialectCaps.UseDatabaseAsSchema) { Table = new NameWithSchema(src.DatabaseName, Table.Name); } }
public static bool GenerateRename(NameWithSchema oldName, NameWithSchema newName, Action <NameWithSchema, string> changeSchema, Action <NameWithSchema, string> rename, bool allowChangeSchema, bool allowRename, DbDiffOptions opts) { newName = GenerateNewName(oldName, newName, opts); if (DbDiffTool.EqualFullNames(oldName, newName, opts)) { return(true); } if (!EqualSchemas(oldName.Schema, newName.Schema, opts) && !allowChangeSchema) { return(false); } if (oldName.Name != newName.Name && !allowRename) { return(false); } if (!EqualSchemas(oldName.Schema, newName.Schema, opts)) { changeSchema(oldName, newName.Schema); } if (oldName.Name != newName.Name) { rename(new NameWithSchema(newName.Schema, oldName.Name), newName.Name); } return(true); }
public static bool GenerateRenameSpecificObject(SpecificObjectInfo oldObj, NameWithSchema newName, Action <SpecificObjectInfo, string> changeSchema, Action <SpecificObjectInfo, string> rename, bool allowChangeSchema, bool allowRename, DbDiffOptions opts) { newName = GenerateNewName(oldObj.FullName, newName, opts); if (DbDiffTool.EqualFullNames(oldObj.FullName, newName, opts)) { return(true); } if (!EqualSchemas(oldObj.FullName.Schema, newName.Schema, opts) && !allowChangeSchema) { return(false); } if (oldObj.FullName.Name != newName.Name && !allowRename) { return(false); } if (!EqualSchemas(oldObj.FullName.Schema, newName.Schema, opts)) { changeSchema(oldObj, newName.Schema); } if (oldObj.FullName.Name != newName.Name) { var tmpo = oldObj.CloneSpecificObject(); tmpo.FullName = new NameWithSchema(newName.Schema, oldObj.FullName.Name); rename(tmpo, newName.Name); } return(true); }
public void AddTable(NameWithSchema table, Point?pt) { if (m_diagram.FindTable(table) != null) { return; } DiagramTableItem item = new DiagramTableItem(m_diagram); if (pt == null) { item.MustBePlaced = true; } else { item.X = pt.Value.X; item.Y = pt.Value.Y; } try { m_denyDraw = true; m_conn.ClearCaches(); item.Table = (TableStructure)m_conn.GetTable(table).InvokeLoadStructure(TableStructureMembers.AllNoRefs); } finally { m_denyDraw = false; } m_diagram.Tables.Add(item); m_modified = true; drawPanel.Invalidate(); labDragAndDrop.Visible = m_diagram.Tables.Count == 0; Usage.AddSub("add_table", table.ToString()); }
protected override void DoRun() { var tables = Connection.GetSchema("Tables"); var columns = new List<DataRow>(); foreach (DataRow row in Connection.GetSchema("Columns").Rows) columns.Add(row); columns = new List<DataRow>(columns.SortedByKey<DataRow, int>(c => c.SafeInt("ORDINAL_POSITION"))); foreach (DataRow row in tables.Rows) { if (row.SafeString("TABLE_TYPE") != "BASE TABLE") continue; var table = new TableInfo(Result); table.FullName = new NameWithSchema(row.SafeString("TABLE_SCHEMA"), row.SafeString("TABLE_NAME")); Result.Tables.Add(table); _tables[table.FullName] = table; } foreach (DataRow row in columns) { if (row.SafeString("TABLE_TYPE") != "BASE TABLE") continue; var tname = new NameWithSchema(row.SafeString("TABLE_SCHEMA"), row.SafeString("TABLE_NAME")); var table = _tables[tname]; var col = new ColumnInfo(table); col.Name = row.SafeString("COLUMN_NAME"); col.NotNull = row.SafeString("IS_NULLABLE") == "NO"; col.DataType = row.SafeString("DATA_TYPE"); col.Length = row.SafeInt("CHARACTER_MAXIMUM_LENGTH"); col.Precision = row.SafeInt("NUMERIC_PRECISION"); col.Scale = row.SafeInt("NUMERIC_SCALE"); col.DefaultValue = row.SafeString("COLUMN_DEFAULT"); table.Columns.Add(col); } }
public TableWriter(IShellContext context, IConnectionProvider connection, NameWithSchema name, TableInfo inputRowFormat, CopyTableTargetOptions options, TableInfo destinationTableOverride = null, LinkedDatabaseInfo linkedInfo = null, DataFormatSettings sourceDataFormat = null) { _connectionProvider = connection; _linkedInfo = linkedInfo; _name = name; _inputRowFormat = inputRowFormat; _queue = new CdlDataQueue(inputRowFormat); _context = context; _inserter = connection.Factory.CreateBulkInserter(); _inserter.SourceDataFormat = sourceDataFormat; _connection = _connectionProvider.Connect(); _inserter.Connection = _connection; _inserter.Factory = connection.Factory; _inserter.LinkedInfo = _linkedInfo; var db = context.GetDatabaseStructure(connection.ProviderString); _inserter.DestinationTable = destinationTableOverride ?? db.FindTableLike(_name.Schema, _name.Name); _inserter.CopyOptions = options; _inserter.MessageLogger = _context; _inserter.ServiceProvider = context.ServiceProvider; _thread = new Thread(Run); _thread.Start(); }
protected void DoGetModificationsCore(string sql, string modifyColumn, string nameColumn, string schemaColumn = null, string idColumn = null) { var existingTables = new HashSet <string>(); using (var cmd = Connection.CreateCommand()) { cmd.CommandText = sql; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { string modify = reader.SafeString(modifyColumn); string name = reader.SafeString(nameColumn); string schema = schemaColumn != null?reader.SafeString(schemaColumn) : null; string objectId = idColumn != null?reader.SafeString(idColumn) : null; existingTables.Add(name); var fullName = new NameWithSchema(schema, name); var obj = Structure.FindTable(fullName); if (obj == null) { var item = new DatabaseChangeItem { Action = DatabaseChangeAction.Add, ObjectType = DatabaseObjectType.Table, ObjectId = objectId ?? CreateObjectId("table", schema, name), NewName = fullName, }; ChangeSet.Items.Add(item); } else { if (obj.ModifyInfo == null || obj.ModifyInfo != modify) { var item = new DatabaseChangeItem { Action = DatabaseChangeAction.Change, ObjectType = DatabaseObjectType.Table, OldName = ((NamedObjectInfo)obj).FullName, NewName = fullName, ObjectId = objectId ?? CreateObjectId("table", schema, name), }; ChangeSet.Items.Add(item); } } } } } if (idColumn != null) { AddDeletedObjectsById(Structure.Tables, existingTables); } else { AddDeletedObjectsByName(Structure.Tables, existingTables, "table"); } }
public void AllowIdentityInsert(NameWithSchema tableName, bool allow) { Commands.Add(new DmlfAllowIdentityInsert { TableName = tableName, AllowIdentityInsert = allow, }); }
public void RenameSpecificObject(SpecificObjectInfo obj, NameWithSchema name) { var o = Structure.FindOrCreateSpecificObject(obj); AddOperation(new AlterOperation_RenameSpecificObject { OldObject = o, NewName = name }); }
public static bool EqualFullNames(NameWithSchema lft, NameWithSchema rgt, DbDiffOptions options) { if (lft == null || rgt == null) { return(lft == rgt); } return(EqualSchemas(lft.Schema, rgt.Schema, options) && EqualNames(lft.Name, rgt.Name, options)); }
public void RenameTable(TableInfo table, NameWithSchema name) { var tbl = Structure.FindOrCreateTable(table.FullName); AddOperation(new AlterOperation_RenameTable { OldObject = tbl, NewName = name }); }
private bool RemoveName(NameWithSchema name) { var dct = new Dictionary <string, string>(); dct["schema"] = name.Schema; dct["name"] = name.Name; return(NameFilter.Accept(dct) == RemoveSelected); }
public static string SafeGetName(this NameWithSchema name) { if (name != null) { return(name.Name); } return(null); }
public void UpdateData(NameWithSchema table, DataScript script) { TableInfo tbl = Structure.FindOrCreateTable(table); AddOperation(new AlterOperation_UpdateData { ParentTable = tbl, Script = script }); }
public ReceiveArguments(NameWithSchema queueName) { if (queueName == null) { throw new ArgumentNullException(nameof(queueName)); } QueueName = queueName; }
public void DisableConstraint(NameWithSchema tableName, string constraintName, bool disable) { Commands.Add(new DmlfDisableConstraint { TableName = tableName, ConstraintName = constraintName, Disable = disable }); }
public void OnLogResult(NameWithSchema table, int updated, int inserted, int deleted) { Formatter .BeginRow(false) .Cell(table) .Cell(updated) .Cell(inserted) .Cell(deleted) .EndRow(false); }
public bool SimilarTo(NameWithSchema name) { var my = GetFullName(); if (my == null) { return(false); } return(my.Name.ToUpperInvariant() == name.Name.ToUpperInvariant()); }
public void LogResultError(NameWithSchema table, Exception err) { foreach (var proc in m_processors) { var p1 = proc as IDataSynInfoReportProcessor; if (p1 != null) { p1.OnLogResultError(table, err); } } }
private DataTable LoadConstraintsColsTable(NameWithSchema table) { string sql = SqlScripts.getconstraintcols; sql = sql.Replace("#RETURNALL#", table == null ? "1" : "0"); if (table != null) { sql = sql.Replace("#TABLE#", table.Name); } return(GetDbConn().LoadTableFromQuery(sql)); }
private DataTable LoadIndexColsTable(NameWithSchema table) { string sqlidxcols = StdScripts.getindexcols.Replace("#RETURNALL#", table == null ? "1" : "0"); if (table != null) { sqlidxcols = sqlidxcols.Replace("#TABLE#", table.Name).Replace("#SCHEMA#", table.Schema).Replace("#INDEX#", "%"); } sqlidxcols = ReplaceMsSqlPlaceholders(sqlidxcols); return(GetDbConn().LoadTableFromQuery(sqlidxcols)); }
public DiagramTableItem FindTable(NameWithSchema name) { foreach (DiagramTableItem item in Tables) { if (item.Table.FullName == name) { return(item); } } return(null); }
public void LogResult(NameWithSchema table, int updated, int inserted, int deleted) { foreach (var proc in m_processors) { var p1 = proc as IDataSynInfoReportProcessor; if (p1 != null) { p1.OnLogResult(table, updated, inserted, deleted); } } }
public void Update(NameWithSchema table, string[] condcols, object[] condvalues, string[] columns, object[] values) { Updates.Add(new UpdateAction { Table = table, CondCols = condcols, CondValues = condvalues, Columns = columns, Values = values }); }
private DataTable LoadSourceTable(NameWithSchema obj) { string sql = "SELECT TEXT, NAME FROM USER_SOURCE"; if (obj != null) { sql += " WHERE NAME='" + obj.Name + "'"; } sql += " ORDER BY LINE"; return(GetDbConn().LoadTableFromQuery(sql)); }
public static string QuoteFullName(this ISqlDialect dialect, NameWithSchema name) { if (name.Schema != null) { if (name.Schema.ToUpper() == "INFORMATION_SCHEMA") { return(String.Format("{0}.{1}", name.Schema, name.Name)); } return(String.Format("{0}.{1}", dialect.QuoteIdentifier(name.Schema), dialect.QuoteIdentifier(name.Name))); } return(dialect.QuoteIdentifier(name.Name)); }
public void OnLogResultError(NameWithSchema table, Exception err) { m_errors.Add(err); string cell = "(ERROR #" + m_errors.Count.ToString() + ")"; Formatter .BeginRow(false) .Cell(cell) .Cell(cell) .Cell(cell) .EndRow(false); }
private DataTable LoadProgrammableTable(NameWithSchema obj) { string sql = ReplaceMsSqlPlaceholders(StdScripts.loadprogrammable); if (obj != null) { sql = sql.Replace("#NAME#", obj.Name); sql = sql.Replace("#SCHEMA#", obj.Schema); } sql = sql.Replace("#RETURNALL#", obj != null ? "0" : "1"); return(GetDbConn().LoadTableFromQuery(sql)); }
private string AddUsrObjFilter(string sql, NameWithSchema table, string conj) { if (table != null) { sql += String.Format(" {0} obj.name='{1}'", conj, table.Name); if (table.Schema != null) { sql += String.Format(" AND usr.name='{0}'", table.Schema); } } return(sql); }
public abstract void SetDummyTable(NameWithSchema name);