Example #1
0
 public override void NotifyChangeDatabase(IDatabaseSource src)
 {
     if (src.Dialect.DialectCaps.UseDatabaseAsSchema)
     {
         Name = new NameWithSchema(src.DatabaseName, Name.Name);
     }
 }
Example #2
0
        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);
        }
Example #3
0
        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);
            }
        }
Example #4
0
 public void NotifyChangeDatabase(IDatabaseSource src)
 {
     if (src.Dialect.DialectCaps.UseDatabaseAsSchema)
     {
         Table = new NameWithSchema(src.DatabaseName, Table.Name);
     }
 }
Example #5
0
 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);
 }
Example #6
0
 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);
 }
Example #7
0
        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());
        }
Example #8
0
        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);
            }
        }
Example #9
0
        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();
        }
Example #10
0
        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");
            }
        }
Example #11
0
 public void AllowIdentityInsert(NameWithSchema tableName, bool allow)
 {
     Commands.Add(new DmlfAllowIdentityInsert
     {
         TableName           = tableName,
         AllowIdentityInsert = allow,
     });
 }
Example #12
0
        public void RenameSpecificObject(SpecificObjectInfo obj, NameWithSchema name)
        {
            var o = Structure.FindOrCreateSpecificObject(obj);

            AddOperation(new AlterOperation_RenameSpecificObject {
                OldObject = o, NewName = name
            });
        }
Example #13
0
 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));
 }
Example #14
0
        public void RenameTable(TableInfo table, NameWithSchema name)
        {
            var tbl = Structure.FindOrCreateTable(table.FullName);

            AddOperation(new AlterOperation_RenameTable {
                OldObject = tbl, NewName = name
            });
        }
Example #15
0
        private bool RemoveName(NameWithSchema name)
        {
            var dct = new Dictionary <string, string>();

            dct["schema"] = name.Schema;
            dct["name"]   = name.Name;
            return(NameFilter.Accept(dct) == RemoveSelected);
        }
Example #16
0
 public static string SafeGetName(this NameWithSchema name)
 {
     if (name != null)
     {
         return(name.Name);
     }
     return(null);
 }
Example #17
0
        public void UpdateData(NameWithSchema table, DataScript script)
        {
            TableInfo tbl = Structure.FindOrCreateTable(table);

            AddOperation(new AlterOperation_UpdateData {
                ParentTable = tbl, Script = script
            });
        }
Example #18
0
        public ReceiveArguments(NameWithSchema queueName)
        {
            if (queueName == null)
            {
                throw new ArgumentNullException(nameof(queueName));
            }

            QueueName = queueName;
        }
Example #19
0
 public void DisableConstraint(NameWithSchema tableName, string constraintName, bool disable)
 {
     Commands.Add(new DmlfDisableConstraint
     {
         TableName      = tableName,
         ConstraintName = constraintName,
         Disable        = disable
     });
 }
Example #20
0
 public void OnLogResult(NameWithSchema table, int updated, int inserted, int deleted)
 {
     Formatter
     .BeginRow(false)
     .Cell(table)
     .Cell(updated)
     .Cell(inserted)
     .Cell(deleted)
     .EndRow(false);
 }
Example #21
0
        public bool SimilarTo(NameWithSchema name)
        {
            var my = GetFullName();

            if (my == null)
            {
                return(false);
            }
            return(my.Name.ToUpperInvariant() == name.Name.ToUpperInvariant());
        }
Example #22
0
 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);
         }
     }
 }
Example #23
0
        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));
        }
Example #24
0
        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));
        }
Example #25
0
 public DiagramTableItem FindTable(NameWithSchema name)
 {
     foreach (DiagramTableItem item in Tables)
     {
         if (item.Table.FullName == name)
         {
             return(item);
         }
     }
     return(null);
 }
Example #26
0
 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);
         }
     }
 }
Example #27
0
 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
     });
 }
Example #28
0
        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));
        }
Example #29
0
 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));
 }
Example #30
0
        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);
        }
Example #31
0
        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));
        }
Example #32
0
 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);
 }
Example #33
0
 public abstract void SetDummyTable(NameWithSchema name);