Exemplo n.º 1
0
        protected override DBSchemaForeignKey LoadAForeignKey(DbConnection con, DBSchemaItemRef fkref)
        {
            DataTable          dtFK = GetForeignKeyData(con, fkref);
            DBSchemaForeignKey anFk = null;

            if (null != dtFK && dtFK.Rows.Count > 0)
            {
                anFk = new DBSchemaForeignKey();
                this.FillForeignKeyData(anFk, dtFK.Rows[0]);
            }
            return(anFk);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the meta data DataTable for a routine
        /// </summary>
        /// <param name="con"></param>
        /// <param name="routineref"></param>
        /// <returns></returns>
        protected override DataTable GetRoutineData(DbConnection con, DBSchemaItemRef routineref)
        {
            System.Data.OleDb.OleDbConnection olecon = (System.Data.OleDb.OleDbConnection)con;
            DataTable dt = olecon.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Procedures,
                                                      new object[] { null, null, routineref.Name, null });

            dt.TableName = "Routines";

            WriteCollectionData("Routines", new string[] { routineref.Name }, dt);

            return(dt);
        }
Exemplo n.º 3
0
        protected override DataTable GetForeignKeyColumns(DbConnection con, DBSchemaItemRef fkref)
        {
            DBSchemaMetaDataCollection colmscol = this.AssertGetCollectionForType(DBMetaDataCollectionType.IndexColumns);

            string sql = @"SELECT 
    CONSTRAINT_SCHEMA  AS FKSchema,
    CONSTRAINT_NAME AS FKConstraintName,
    TABLE_SCHEMA AS FKTableSchema,
    TABLE_NAME AS FKTable,
    COLUMN_NAME AS FKColumn,
    REFERENCED_TABLE_SCHEMA AS PKSchema, 
    REFERENCED_TABLE_NAME AS PKTable, 
    REFERENCED_COLUMN_NAME AS PKColumn
    
    FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE CONSTRAINT_NAME = {0} AND 
    TABLE_SCHEMA = {1} AND TABLE_NAME = {2}";


            using (DbCommand cmd = this.Database.CreateCommand(con, ""))
            {
                DbParameter pname = this.Database.AddCommandParameter(cmd, "name", DbType.String);
                //DbParameter pcatalog = this.Database.AddCommandParameter(cmd, "catalog", DbType.String);
                DbParameter pschema = this.Database.AddCommandParameter(cmd, "schema", DbType.String);
                DbParameter ptable  = this.Database.AddCommandParameter(cmd, "table", DbType.String);

                //we format here to get the native name from the parameter
                cmd.CommandText = string.Format(sql, pname.ParameterName, pschema.ParameterName, ptable.ParameterName);

                pname.Value = fkref.Name;
                if (fkref.Container != null)
                {
                    ptable.Value  = fkref.Container.Name;
                    pschema.Value = fkref.Container.Schema;
                }
                else
                {
                    ptable.Value  = "%";
                    pschema.Value = "%";
                }

                DataSet   ds = new DataSet();
                DataTable dt = ds.Tables.Add("ForeignKeys");
                this.Database.PopulateDataSet(ds, cmd, LoadOption.OverwriteChanges, "ForeignKeys");
                ds.AcceptChanges();
                try {
                    dt.WriteXml("C:\\SchemaOutput\\ForeignKeys" + fkref.Name + ".xml");
                }catch (Exception ex) { }
                return(dt);
            }
        }
Exemplo n.º 4
0
        protected override DataTable GetViewColumns(DbConnection con, DBSchemaItemRef vref)
        {
            string sql = "SELECT * FROM [" + vref.FullName.Replace(".", "].[") + "] WHERE 1=0";

            using (DbCommand cmd = this.Database.CreateCommand(con, sql))
            {
                using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly))
                {
                    DataTable dt = reader.GetSchemaTable();
                    dt.WriteXml("C:\\SchemaOutput\\ViewColumns_" + vref.Name.Replace(" ", "_") + ".xml");
                    return(dt);
                }
            }
        }
Exemplo n.º 5
0
        protected override DataTable GetIndexData(DbConnection con, DBSchemaItemRef idxref)
        {
            DBSchemaMetaDataCollection idxcol = this.AssertGetCollectionForType(DBMetaDataCollectionType.Indexes);
            string table;

            if (idxref.Container != null)
            {
                table = idxref.Container.Name;
            }
            else
            {
                table = null;
            }
            return(this.GetCollectionData(con, idxcol, idxref.Schema, idxref.Name));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the meta data DataTable for the specified index
        /// </summary>
        /// <param name="con"></param>
        /// <param name="idxref"></param>
        /// <returns></returns>
        protected override DataTable GetIndexData(DbConnection con, DBSchemaItemRef idxref)
        {
            System.Data.OleDb.OleDbConnection olecon = (System.Data.OleDb.OleDbConnection)con;
            string table = null;

            if (null != idxref.Container)
            {
                table = idxref.Container.Name;
            }

            DataTable data = olecon.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Indexes, new object[] { null, null, idxref.Name, null, table });

            data.TableName = "Indexes";
            WriteCollectionData("Indexes", new string[] { idxref.Name }, data);

            return(data);
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        public void CreateClientServer()
        {
            DBSchemaItemRef table = tables.Where(x => x.Name.ToLower() == TzAccount.ClientServer.Table.ToLower()).FirstOrDefault();

            if (table == null)
            {
                DBQuery create;
                create = DBQuery.Create.Table(base.Schema, TzAccount.ClientServer.Table)
                         .Add(TzAccount.ClientServer.ClientID)
                         .Add(TzAccount.ClientServer.ServerID);
                db.ExecuteNonQuery(create);
            }
            else
            {
                throw new System.Exception("'Client Server' table Name exist");
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        public void CreateScriptIntend()
        {
            DBSchemaItemRef table = tables.Where(x => x.Name.ToLower() == TzAccount.ScriptIntend.Table.ToLower()).FirstOrDefault();

            if (table == null)
            {
                DBQuery create;
                create = DBQuery.Create.Table(base.Schema, TzAccount.ScriptIntend.Table)
                         .Add(TzAccount.ScriptIntend.ScriptID)
                         .Add(TzAccount.ScriptIntend.Intend)

                ;
                db.ExecuteNonQuery(create);
            }
            else
            {
                throw new System.Exception("'Script intend' table Name exist");
            }
        }
Exemplo n.º 9
0
        protected override void FillIndexData(DBSchemaIndex anindex, DataRow dataRow)
        {
            DataColumn catalog = GetColumn(dataRow.Table, "CATALOG", false);
            DataColumn schema  = GetColumn(dataRow.Table, "OWNER", false);
            DataColumn name    = GetColumn(dataRow.Table, "INDEX_NAME", true);

            DataColumn tblcatalog = GetColumn(dataRow.Table, "TABLE_CATALOG", false);
            DataColumn tblschema  = GetColumn(dataRow.Table, "TABLE_OWNER", false);
            DataColumn tblname    = GetColumn(dataRow.Table, "TABLE_NAME", true);

            anindex.Catalog = GetColumnStringValue(dataRow, catalog);
            anindex.Schema  = GetColumnStringValue(dataRow, schema);
            anindex.Name    = GetColumnStringValue(dataRow, name);

            DBSchemaItemRef tblref = new DBSchemaItemRef(DBSchemaTypes.Table,
                                                         GetColumnStringValue(dataRow, tblcatalog), GetColumnStringValue(dataRow, tblschema), GetColumnStringValue(dataRow, tblname));

            anindex.TableReference = tblref;
        }
Exemplo n.º 10
0
        /// <summary>
        /// populates the meta data for a specific foreign key
        /// </summary>
        /// <param name="fk"></param>
        /// <param name="dtFKRow"></param>
        protected override void FillForeignKeyData(DBSchemaForeignKey fk, DataRow dtFKRow)
        {
            DataTable dt = dtFKRow.Table;

            DataColumn schemacol  = GetColumn(dt, "FK_SCHEMA", false);
            DataColumn catalogcol = GetColumn(dt, "FK_CATALOG", false);
            DataColumn namecol    = GetColumn(dt, "FK_NAME", true);

            DataColumn pkcatalogcol = GetColumn(dt, "PK_CATALOG_NAME", false);
            DataColumn pkschemacol  = GetColumn(dt, "PK_SCHEMA_NAME", false);
            DataColumn pktablecol   = GetColumn(dt, "PK_TABLE_NAME", true);
            DataColumn pkcolumncol  = GetColumn(dt, "PK_COLUMN_NAME", true);

            DataColumn fkcatalogcol = GetColumn(dt, "FK_CATALOG_NAME", false);
            DataColumn fkschemacol  = GetColumn(dt, "FK_SCHEMA_NAME", false);
            DataColumn fktablecol   = GetColumn(dt, "FK_TABLE_NAME", false);
            DataColumn fkcolumncol  = GetColumn(dt, "FK_COLUMN_NAME", false);

            fk.Catalog = GetColumnStringValue(dtFKRow, catalogcol);
            fk.Schema  = GetColumnStringValue(dtFKRow, schemacol);
            fk.Name    = GetColumnStringValue(dtFKRow, namecol);

            DBSchemaItemRef pktable = new DBSchemaItemRef(DBSchemaTypes.Table,
                                                          GetColumnStringValue(dtFKRow, pkcatalogcol),
                                                          GetColumnStringValue(dtFKRow, pkschemacol),
                                                          GetColumnStringValue(dtFKRow, pktablecol));

            DBSchemaItemRef fktable = new DBSchemaItemRef(DBSchemaTypes.Table,
                                                          GetColumnStringValue(dtFKRow, fkcatalogcol),
                                                          GetColumnStringValue(dtFKRow, fkschemacol),
                                                          GetColumnStringValue(dtFKRow, fktablecol));

            fk.ForeignKeyTable = fktable;
            fk.PrimaryKeyTable = pktable;

            DBSchemaForeignKeyMapping map = new DBSchemaForeignKeyMapping();

            map.ForeignColumn = GetColumnStringValue(dtFKRow, fkcolumncol);
            map.PrimaryColumn = GetColumnStringValue(dtFKRow, pkcolumncol);

            fk.Mappings.Add(map);
        }
Exemplo n.º 11
0
        protected override DataTable GetTableColumns(DbConnection con, DBSchemaItemRef tableref)
        {
            DBSchemaMetaDataCollection colmscol = this.AssertGetCollectionForType(DBMetaDataCollectionType.Columns);
            DataTable dt = this.GetCollectionData(con, colmscol, tableref.Schema, tableref.Name);

            DBSchemaMetaDataCollection pks = this.AssertGetCollectionForName("PrimaryKeys");
            DataTable pkcols = this.GetCollectionData(con, pks, tableref.Schema, tableref.Name);

            if (pkcols.Rows.Count > 0)
            {
                string owner     = pkcols.Rows[0]["OWNER"].ToString();
                string indexname = pkcols.Rows[0]["INDEX_NAME"].ToString();
                DBSchemaMetaDataCollection ix = this.AssertGetCollectionForType(DBMetaDataCollectionType.IndexColumns);

                pkcols = this.GetCollectionData(con, ix, owner, indexname);

                FillPrimaryKeys(dt, pkcols);
            }
            return(dt);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Loads all the indexes for a specific database connection
        /// </summary>
        /// <param name="con"></param>
        /// <param name="addtocollection"></param>
        /// <returns></returns>
        protected int LoadIndexRefs(DbConnection con, List <DBSchemaItemRef> addtocollection)
        {
            int        count   = 0;
            DataTable  dt      = con.GetSchema(SchemaIndexesName);
            DataColumn catalog = dt.Columns["INDEX_CATALOG"];
            DataColumn schema  = dt.Columns["INDEX_SCHEMA"];
            DataColumn name    = dt.Columns["INDEX_NAME"];

            foreach (DataRow row in dt.Rows)
            {
                DBSchemaItemRef iref = new DBSchemaItemRef();
                iref.Catalog = row[catalog].ToString();
                iref.Schema  = row[schema].ToString();
                iref.Name    = row[name].ToString();
                iref.Type    = DBSchemaTypes.Index;

                addtocollection.Add(iref);
                count++;
            }
            return(count);
        }
Exemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        public void CreateServer()
        {
            DBSchemaItemRef table = tables.Where(x => x.Name.ToLower() == TzAccount.Server.Table.ToLower()).FirstOrDefault();

            if (table == null)
            {
                DBQuery create;
                create = DBQuery.Create.Table(base.Schema, TzAccount.Server.Table)
                         .Add(TzAccount.Server.ServerID)
                         .Add(TzAccount.Server.ServerName)
                         .Add(TzAccount.Server.Host)
                         .Add(TzAccount.Server.Port)
                         .Add(TzAccount.Server.UserID)
                         .Add(TzAccount.Server.Password)
                         .Add(TzAccount.Server.DB);
                db.ExecuteNonQuery(create);
            }
            else
            {
                throw new System.Exception("Server table Name exist");
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Overriden because default behaviour for the Get Tables collection returns views too.
        /// </summary>
        /// <param name="con"></param>
        /// <param name="intoCollection"></param>
        protected override void LoadTableRefs(DbConnection con, IList <DBSchemaItemRef> intoCollection)
        {
            DBSchemaMetaDataCollection tblcollection = this.AssertGetCollectionForType(DBMetaDataCollectionType.Tables);
            DataTable data = this.GetCollectionData(con, tblcollection);

            DataColumn catalogcol = GetColumn(data, "TABLE_CATALOG", true);
            DataColumn schemacol  = GetColumn(data, "TABLE_SCHEMA", true);
            DataColumn namecol    = GetColumn(data, "TABLE_NAME", true);
            DataColumn typecol    = GetColumn(data, "TABLE_TYPE", true);

            foreach (DataRow row in data.Rows)
            {
                if (GetColumnStringValue(row, typecol).Equals("BASE TABLE", StringComparison.OrdinalIgnoreCase))
                {
                    DBSchemaItemRef tbl = this.LoadAnItemRef(row, catalogcol, schemacol, namecol, DBSchemaTypes.Table);
                    if (null != tbl)
                    {
                        intoCollection.Add(tbl);
                    }
                }
            }
        }
Exemplo n.º 15
0
        private ISchemaEditor GetSchemaEditor(DBSchemaItemRef itemref)
        {
            ISchemaEditor ed = null;

            switch (itemref.Type)
            {
            case DBSchemaTypes.Table:
                ed = new Controls.SchemaTableEditor();
                break;

            case DBSchemaTypes.View:
                ed = new Controls.SchemaViewEditor();
                break;

            case DBSchemaTypes.StoredProcedure:
                ed = new Controls.SchemaSprocEditor();
                break;

            case DBSchemaTypes.Function:
                ed = new Controls.SchemaFunctionEditor();
                break;

            case DBSchemaTypes.Index:
                ed = new Controls.SchemaIndexEditor();
                break;

            case (DBSchemaTypes.ForeignKey):
                ed = new Controls.SchemaForeignKeyEditor();
                break;

            case DBSchemaTypes.CommandScripts:
                break;

            default:
                break;
            }
            return(ed);
        }
Exemplo n.º 16
0
        protected virtual void EditNode(TreeNode node)
        {
            DBSchemaItemRef itemref  = (DBSchemaItemRef)node.Tag;
            string          fullname = itemref.ToString();

            if (this.tabControl1.TabPages.ContainsKey(fullname))
            {
                this.tabControl1.SelectedTab = this.tabControl1.TabPages[fullname];
            }
            else
            {
                ISchemaEditor editor = this.GetSchemaEditor(itemref);
                if (editor != null)
                {
                    try
                    {
                        DBSchemaItem item = this.provider.GetSchema(itemref);
                        editor.Item = item;

                        Control ctl  = editor.UIControl;
                        string  full = itemref.ToString();
                        this.tabControl1.TabPages.Add(full, itemref.Name);
                        TabPage pg = this.tabControl1.TabPages[full];
                        Perceiveit.Data.SchemaTests.Controls.EditorWraper wrapper = new Perceiveit.Data.SchemaTests.Controls.EditorWraper();
                        wrapper.InnerEditor   = editor;
                        wrapper.RequestClose += new EventHandler(wrapper_RequestClose);
                        pg.Controls.Add(wrapper);
                        ctl.Dock     = DockStyle.Fill;
                        wrapper.Dock = DockStyle.Fill;
                        this.tabControl1.SelectedTab = pg;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Could not load the schema editor :" + ex.Message + "\r\n\r\n" + ex.StackTrace);
                    }
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        ///
        /// </summary>
        public void CreateField()
        {
            DBSchemaItemRef table = tables.Where(x => x.Name.ToLower() == TzAccount.Field.Table.ToLower()).FirstOrDefault();

            if (table == null)
            {
                DBQuery create;
                create = DBQuery.Create.Table(base.Schema, TzAccount.Field.Table)
                         .Add(TzAccount.Field.TableID)
                         .Add(TzAccount.Field.FieldID)
                         .Add(TzAccount.Field.FieldName)
                         .Add(TzAccount.Field.FieldType)
                         .Add(TzAccount.Field.Length)
                         .Add(TzAccount.Field.IsNullable)
                         .Add(TzAccount.Field.ISPrimaryKey)
                ;
                db.ExecuteNonQuery(create);
            }
            else
            {
                throw new System.Exception("'Fields' table Name exist");
            }
        }
Exemplo n.º 18
0
        protected override DataTable GetForeignKeyData(DbConnection con, DBSchemaItemRef fkref)
        {
            string table = null;

            if (fkref.Container != null)
            {
                table = fkref.Container.Name;
            }

            DBSchemaMetaDataCollection fkcol = this.AssertGetCollectionForType(DBMetaDataCollectionType.ForeignKeys);
            DataTable dtFK = this.GetCollectionData(con, fkcol, fkref.Catalog, fkref.Schema, table, null);

            for (int i = dtFK.Rows.Count - 1; i >= 0; i--)
            {
                DataRow row = dtFK.Rows[i];
                if (row["constraint_name"].ToString().Equals(fkref.Name, StringComparison.OrdinalIgnoreCase) == false)
                {
                    row.Delete();
                }
            }
            dtFK.AcceptChanges();

            return(dtFK);
        }
Exemplo n.º 19
0
        protected override void FillIndexData(DBSchemaIndex anindex, DataRow dataRow)
        {
            DataColumn catalog = GetColumn(dataRow.Table, "index_catalog", false);
            DataColumn schema  = GetColumn(dataRow.Table, "index_schema", false);
            DataColumn name    = GetColumn(dataRow.Table, "index_name", true);

            DataColumn tblcatalog = GetColumn(dataRow.Table, "table_catalog", false);
            DataColumn tblschema  = GetColumn(dataRow.Table, "table_schema", false);
            DataColumn tblname    = GetColumn(dataRow.Table, "table_name", true);
            DataColumn unique     = GetColumn(dataRow.Table, "unique", false);
            DataColumn pk         = GetColumn(dataRow.Table, "primary", false);

            anindex.Catalog      = GetColumnStringValue(dataRow, catalog);
            anindex.Schema       = GetColumnStringValue(dataRow, schema);
            anindex.Name         = GetColumnStringValue(dataRow, name);
            anindex.IsPrimaryKey = GetColumnBoolValue(dataRow, pk);
            anindex.IsUnique     = GetColumnBoolValue(dataRow, unique);


            DBSchemaItemRef tblref = new DBSchemaItemRef(DBSchemaTypes.Table,
                                                         GetColumnStringValue(dataRow, tblcatalog), GetColumnStringValue(dataRow, tblschema), GetColumnStringValue(dataRow, tblname));

            anindex.TableReference = tblref;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Loads all the indexes in this providers data connection for the specified table
        /// </summary>
        /// <param name="con"></param>
        /// <param name="fortable"></param>
        /// <param name="intoCollection"></param>
        protected override void LoadIndexRefs(DbConnection con, IList <DBSchemaItemRef> intoCollection, DBSchemaItemRef fortable)
        {
            DBSchemaMetaDataCollection idxcollection =
                this.AssertGetCollectionForType(DBMetaDataCollectionType.Indexes);

            DataTable data = this.GetCollectionData(con, idxcollection, fortable.Schema, fortable.Name, string.Empty);
            int       i    = data.Rows.Count;

            DataColumn catalogcol = GetColumn(data, "catalog", false);
            DataColumn schemacol  = GetColumn(data, "owner", false);
            DataColumn namecol    = GetColumn(data, "index_name", true);

            DataColumn tablecatalogcol = GetColumn(data, "table_catalog", false);
            DataColumn tableschemacol  = GetColumn(data, "table_owner", false);
            DataColumn tablenamecol    = GetColumn(data, "table_name", true);

            this.LoadItemRefsWithContainer(data, intoCollection,
                                           catalogcol, schemacol, namecol, DBSchemaTypes.Index,
                                           tablecatalogcol, tableschemacol, tablenamecol, DBSchemaTypes.Table);
        }
Exemplo n.º 21
0
        protected override void LoadForeignKeyRefs(DbConnection con, IList <DBSchemaItemRef> intoCollection, DBSchemaItemRef fortable)
        {
            DBSchemaMetaDataCollection viewcollection =
                this.AssertGetCollectionForType(DBMetaDataCollectionType.ForeignKeys);
            DataTable data = this.GetCollectionData(con, viewcollection, fortable.Schema, fortable.Name, null);

            DataColumn catalogcol = GetColumn(data, "foreign_key_catalog", false);
            DataColumn schemacol  = GetColumn(data, "foreign_key_owner", false);
            DataColumn namecol    = GetColumn(data, "foreign_key_constraint_name", true);

            DataColumn containercatalogcol = GetColumn(data, "foreign_key_table_catalog", false);
            DataColumn containerschemacol  = GetColumn(data, "foreign_key_table_owner", false);
            DataColumn containernamecol    = GetColumn(data, "foreign_key_table_name", true);

            this.LoadItemRefsWithContainer(data, intoCollection,
                                           catalogcol, schemacol, namecol, DBSchemaTypes.ForeignKey,
                                           containercatalogcol, containerschemacol, containernamecol, DBSchemaTypes.Table);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Loads all the indexes in this providers data connection for the specified table
        /// </summary>
        /// <param name="con"></param>
        /// <param name="fortable"></param>
        /// <param name="intoCollection"></param>
        protected override void LoadIndexRefs(DbConnection con, IList <DBSchemaItemRef> intoCollection, DBSchemaItemRef fortable)
        {
            IEnumerable <DBSchemaItemRef> ixs = this.GetAllIndexs();

            foreach (DBSchemaItemRef ixref in ixs)
            {
                if (ixref.Container != null && ixref.Container.Equals(fortable))
                {
                    intoCollection.Add(ixref);
                }
            }
        }
Exemplo n.º 23
0
        //
        // overrides
        //

        #region protected override void LoadIndexRefs(DbConnection con, IList<DBSchemaItemRef> intoCollection, DBSchemaItemRef fortable)

        protected override void LoadIndexRefs(DbConnection con, IList <DBSchemaItemRef> intoCollection, DBSchemaItemRef fortable)
        {
            //Cannot get SqlClient to limit the returned indexes to a single table so
            //we need to load all of them and then restrict to the required table.
            List <DBSchemaItemRef> all = new List <DBSchemaItemRef>();

            base.LoadIndexRefs(con, all);

            foreach (DBSchemaItemRef iref in all)
            {
                if (iref.Container != null && iref.Container.Equals(fortable))
                {
                    intoCollection.Add(iref);
                    iref.Container = fortable;
                }
            }
        }
Exemplo n.º 24
0
        //
        // ForeignKeys - complete
        //

        #region protected override DBSchemaForeignKey LoadAForeignKey(DbConnection con, DBSchemaItemRef fkref)
        /// <summary>
        /// returns the base method results
        /// </summary>
        /// <param name="con"></param>
        /// <param name="fkref"></param>
        /// <returns></returns>
        protected override DBSchemaForeignKey LoadAForeignKey(DbConnection con, DBSchemaItemRef fkref)
        {
            return(base.LoadAForeignKey(con, fkref));
        }
Exemplo n.º 25
0
        protected override void LoadIndexRefs(DbConnection con, IList <DBSchemaItemRef> intoCollection, DBSchemaItemRef fortable)
        {
            DBSchemaMetaDataCollection viewcollection =
                this.AssertGetCollectionForType(DBMetaDataCollectionType.Indexes);
            DataTable data = this.GetCollectionData(con, viewcollection, fortable.Catalog, fortable.Schema, fortable.Name, null);

            DataColumn catalogcol = GetColumn(data, "index_catalog", false);
            DataColumn schemacol  = GetColumn(data, "index_schema", false);
            DataColumn namecol    = GetColumn(data, "index_name", true);

            DataColumn tablecatalogcol = GetColumn(data, "table_catalog", false);
            DataColumn tableschemacol  = GetColumn(data, "table_schema", false);
            DataColumn tablenamecol    = GetColumn(data, "table_name", true);

            //If there are no explicit schema columns for the containing table then use the column for the index.
            if (null == tableschemacol && null != schemacol)
            {
                tableschemacol = schemacol;
            }
            if (null == tablecatalogcol && null != catalogcol)
            {
                tablecatalogcol = catalogcol;
            }

            this.LoadItemRefsWithContainer(data, intoCollection,
                                           catalogcol, schemacol, namecol, DBSchemaTypes.Index,
                                           tablecatalogcol, tableschemacol, tablenamecol, DBSchemaTypes.Table);
        }
Exemplo n.º 26
0
        protected override DataTable GetRoutineParams(DbConnection con, DBSchemaItemRef routineref)
        {
            DBSchemaMetaDataCollection routinecol = this.AssertGetCollectionForType(DBMetaDataCollectionType.ProcedureParameters);

            return(this.GetCollectionData(con, routinecol, routineref.Schema, routineref.Name));
        }
Exemplo n.º 27
0
        //
        // Table overrides
        //

        #region protected override DBSchemaTable LoadATable(DbConnection con, DBSchemaItemRef tableref)
        /// <summary>
        /// Loads the info on a specific table
        /// </summary>
        /// <param name="con"></param>
        /// <param name="tableref"></param>
        /// <returns></returns>
        protected override DBSchemaTable LoadATable(DbConnection con, DBSchemaItemRef tableref)
        {
            DataTable dtTable = GetTableData(con, tableref);

            DBSchemaTable atable = null;

            if (null != dtTable && dtTable.Rows.Count > 0)
            {
                atable = new DBSchemaTable();
                this.FillTableData(atable, dtTable.Rows[0]);

                DataTable dtColumns = this.GetTableColumns(con, tableref);
                if (null != dtColumns)
                {
                    this.FillTableColumns(atable.Columns, dtColumns);
                }

                DBSchemaItemRefCollection idxs = new DBSchemaItemRefCollection();
                DBSchemaItemRefCollection fks  = new DBSchemaItemRefCollection();

                this.LoadForeignKeyRefs(con, fks, tableref);
                this.LoadIndexRefs(con, idxs, tableref);

                DBSchemaIndexCollection indexes = new DBSchemaIndexCollection();
                foreach (DBSchemaItemRef idx in idxs)
                {
                    DBSchemaIndex same;
                    DBSchemaIndex anindex = this.LoadAnIndex(con, idx);
                    if (indexes.TryGetIndex(idx, out same))
                    {
                        same.Columns.AddRange(anindex.Columns);
                    }
                    else
                    {
                        indexes.Add(anindex);
                    }
                }
                foreach (DBSchemaIndex idx in indexes)
                {
                    if (idx.IsPrimaryKey)
                    {
                        foreach (DBSchemaIndexColumn idxcol in idx.Columns)
                        {
                            DBSchemaTableColumn tblcol;
                            if (atable.Columns.TryGetColumn(idxcol.ColumnName, out tblcol))
                            {
                                tblcol.PrimaryKey = true;
                            }
                        }
                    }
                }
                DBSchemaForeignKeyCollection foreignkeys = new DBSchemaForeignKeyCollection();
                foreach (DBSchemaItemRef fk in fks)
                {
                    DBSchemaForeignKey aForeignKey = this.LoadAForeignKey(con, fk);
                    foreignkeys.Add(aForeignKey);
                }

                atable.ForeignKeys = foreignkeys;
                atable.Indexes     = indexes;
            }
            return(atable);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Loads all the foreign keys for a specific table
        /// </summary>
        /// <param name="con"></param>
        /// <param name="intoCollection"></param>
        /// <param name="fortable"></param>
        protected override void LoadForeignKeyRefs(DbConnection con, IList <DBSchemaItemRef> intoCollection, DBSchemaItemRef fortable)
        {
            System.Data.OleDb.OleDbConnection olecon = (System.Data.OleDb.OleDbConnection)con;
            DataTable data = olecon.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Foreign_Keys,
                                                        new object[] { null, null, null, null, null, fortable.Name });

            data.TableName = "Foreign Keys";

            WriteCollectionData("Foreign Keys", new string[] { }, data);

            DataColumn catalogcol = GetColumn(data, "FK_CATALOG", false);
            DataColumn schemacol  = GetColumn(data, "FK_SCHEMA", false);
            DataColumn namecol    = GetColumn(data, "FK_NAME", true);

            DataColumn containercatalogcol = GetColumn(data, "FK_TABLE_CATALOG", false);
            DataColumn containerschemacol  = GetColumn(data, "FK_TABLE_SCHEMA", false);
            DataColumn containernamecol    = GetColumn(data, "FK_TABLE_NAME", true);

            this.LoadItemRefsWithContainer(data, intoCollection,
                                           catalogcol, schemacol, namecol, DBSchemaTypes.ForeignKey,
                                           containercatalogcol, containerschemacol, containernamecol, DBSchemaTypes.Table);
        }
Exemplo n.º 29
0
 protected override string GetFullName(DBSchemaItemRef iref)
 {
     return("\"" + iref.FullName.Replace(".", "\".\"") + "\"");
 }
Exemplo n.º 30
0
 /// <summary>
 /// Ignored
 /// </summary>
 /// <param name="con"></param>
 /// <param name="fkref"></param>
 /// <returns></returns>
 protected override DataTable GetForeignKeyColumns(DbConnection con, DBSchemaItemRef fkref)
 {
     // Should be done in the FillForeignData
     return(null);
 }