Example #1
0
        protected override void fillFromDataSet(DataSet ds, DataRow dr, List <TableInfo> tables)
        {
            if (tables.Exists(t => {
                return(t.TableName.ToUpper().Trim() == TableName.ToUpper().Trim());
            }))
            {
                // this table has already been added.
                return;
            }

            // pull info from datarow
            PrimaryKeySortType = dr["primary_key_sort_type"].ToString();
            CharacterSet       = dr["charset"].ToString();
            Collation          = dr["collation"].ToString();
            Engine             = dr["engine"].ToString();
            IsSelected         = Toolkit.ToBoolean(dr["is_selected"], false);
            RowCount           = Toolkit.ToInt32(dr["row_count"], 0);

            // look up all fields associated with this table
            DataTable dtTableField = ds.Tables["TableFieldInfo"];

            DataRow[] drTableFields = dtTableField.Select("parent_id = " + dr["id"]);
            foreach (DataRow dr2 in drTableFields)
            {
                Fields.Add(FieldInfo.GetInstance(this).FillFromDataSet(dr2, null, tables));
            }

            // look up all indexes associated with this table
            var drIndexes = ds.Tables["IndexInfo"].Select("parent_id = " + dr["id"]);

            IndexInfo idx = null;

            foreach (DataRow dr3 in drIndexes)
            {
                if (idx == null || idx.IndexName.ToLower() != dr3["index_name"].ToString().ToLower())
                {
                    idx = IndexInfo.GetInstance(this);
                    idx.FillFromDataSet(ds, dr3);
                    this.Indexes.Add(idx);
                }
            }


            DataRow[]      drConstraints = ds.Tables["ConstraintInfo"].Select("parent_id = " + dr["id"]);
            ConstraintInfo ci            = null;

            foreach (DataRow dr4 in drConstraints)
            {
                if (ci == null || ci.ConstraintName.ToLower() != dr4["constraint_name"].ToString().ToLower())
                {
                    ci = ConstraintInfo.GetInstance(this);
                    ci.FillFromDataSet(ds, dr4, tables);
                    Constraints.Add(ci);
                }
            }
        }
Example #2
0
        public ConstraintInfo Clone(TableInfo newParent)
        {
            ConstraintInfo ci = ConstraintInfo.GetInstance(newParent);

            ci.ConstraintName     = ConstraintName;
            ci.DataConnectionSpec = DataConnectionSpec;
            ci.OnDeleteAction     = this.OnDeleteAction;
            ci.OnUpdateAction     = this.OnUpdateAction;

            // TODO: is this ok? we're not cloning the references table...
            if (ci.ReferencesTable != ci.Table)
            {
                // self-referential.  no need to clone it.
                Debug.WriteLine("NOT cloning ci.ReferencesTable as it is self-referential");
            }
            else
            {
                // pointing at a different table, clone it
                ci.ReferencesTable = this.ReferencesTable.Clone(true, true, true);
            }

            ci.ReferencesTableName = this.ReferencesTableName;
            ci.SyncAction          = SyncAction;
            ci.Table     = newParent;
            ci.TableName = newParent.TableName;
            foreach (FieldInfo fiSrc in SourceFields)
            {
                ci.SourceFields.Add(fiSrc.Clone(newParent));
            }
            ci.SourceFieldNames = SourceFieldNames.ToList();

            foreach (FieldInfo fiRef in ReferencesFields)
            {
                ci.ReferencesFields.Add(fiRef.Clone(newParent));
            }
            ci.ReferencesFieldNames = ReferencesFieldNames.ToList();

            return(ci);
        }