private void SetForeignKey(MySQLTableSchema oracleTable) { string sql = @"select tc.table_name, tc.constraint_name,kc.column_name,kc.referenced_table_name,kc.referenced_table_schema from information_schema.table_constraints tc,information_schema.key_column_usage kc where tc.constraint_type='FOREIGN KEY' and tc.constraint_name=kc.constraint_name and tc.table_schema=kc.table_schema and tc.table_name=kc.table_name and tc.table_name=@table_name and tc.table_schema=@table_schema"; MySqlParameter para0 = new MySqlParameter("@table_name", oracleTable.Name); MySqlParameter para1 = new MySqlParameter("@table_schema", this.DatabaseName); DbHelper helper = new DbHelper(this._connectionString); var table = helper.ListBySql(sql, para0, para1); oracleTable.ForiegnKeys = new List <Common.ForeignKey>(); foreach (DataRow row in table.Rows) { Common.ForeignKey key = new Common.ForeignKey(); key.Columns = new ColumnCollection(); string column_name = row["COLUMN_NAME"] + string.Empty; string constraint_name = row["CONSTRAINT_NAME"] + string.Empty; key.ConstraintName = constraint_name; key.Columns.Add(oracleTable.Columns.Find(it => it.Name == column_name)); string foreignTable = row["referenced_table_name"] + string.Empty; if (ContainForeignTable && key.ForeignTable == null && !string.IsNullOrEmpty(foreignTable)) { string referenced_schema = row["referenced_table_schema"] + string.Empty; var fac = new MySQLDataFactory(this._connectionString); fac.ContainForeignTable = false; fac._db_name = referenced_schema; key.ForeignTable = fac.GetTableSchema(foreignTable); } oracleTable.ForiegnKeys.Add(key); } }
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); }