コード例 #1
0
        private void SetForeignKey(OracleTableSchema oracleTable)
        {
            if (oracleTable == null)
            {
                return;
            }
            if (oracleTable.Columns == null || oracleTable.Columns.Count <= 0)
            {
                SetColumns(oracleTable);
            }
            string          sql    = @"SELECT UCC.CONSTRAINT_NAME, UCC.COLUMN_NAME,UC1.TABLE_NAME FOREIGN_TABLE_NAME
  FROM USER_CONSTRAINTS UC
  LEFT JOIN USER_CONS_COLUMNS UCC
    ON UC.CONSTRAINT_NAME = UCC.CONSTRAINT_NAME
  LEFT JOIN USER_CONSTRAINTS UC1 ON UC.R_CONSTRAINT_NAME=UC1.CONSTRAINT_NAME
 WHERE UC.CONSTRAINT_TYPE = 'R'
   AND UC.TABLE_NAME =:TABLE_NAME";
            OracleParameter para   = new OracleParameter("TABLE_NAME", oracleTable.Name.ToUpper());
            DbHelper        helper = new DbHelper(this._connectionString);
            var             table  = helper.ListBySql(sql, para);

            oracleTable.ForiegnKeys = new List <Common.ForeignKey>();

            foreach (DataRow row in table.Rows)
            {
                string column_name     = row["COLUMN_NAME"] + string.Empty;
                string constraint_name = row["CONSTRAINT_NAME"] + string.Empty;

                Common.ForeignKey key = new Common.ForeignKey();
                key.Columns        = new ColumnCollection();
                key.ConstraintName = constraint_name;
                if (key.ForeignTable == null && ContainForeignTable)
                {
                    string forignTable = row["FOREIGN_TABLE_NAME"] + string.Empty;
                    var    fac         = new OracleDataFactory(this._connectionString);
                    fac.ContainForeignTable = false;
                    key.ForeignTable        = fac.GetTableSchema(forignTable);
                }
                key.Columns.Add(oracleTable.Columns.Find(it => it.Name == column_name));
                oracleTable.ForiegnKeys.Add(key);
            }
        }
コード例 #2
0
        public static DataFactory GetDataFactory(ConnectionSetting setting)
        {
            DataFactory factory = null;

            switch (setting.Provider)
            {
            case DatabaseType.Oracle:
                factory = new OracleProvider.OracleDataFactory(setting.ConnectionString);
                break;

            case DatabaseType.Mssql:
                factory = new MssqlProvider.SqlServerDataFactory(setting.ConnectionString);
                break;

            case DatabaseType.MySQL:
                factory = new MySQLProvider.MySQLDataFactory(setting.ConnectionString);
                break;

            default:
                break;
            }
            return(factory);
        }