///-------------------------------------------------------------------------------- /// <summary>This loads information from a SQL foreign key.</summary> /// /// <param name="sqlForeignKey">The input sql foreign key.</param> ///-------------------------------------------------------------------------------- public void LoadForeignKey(ForeignKey sqlForeignKey) { try { // load the basic foreign key information SqlForeignKeyName = sqlForeignKey.Name; DbID = sqlForeignKey.ID; ReferencedKey = sqlForeignKey.ReferencedKey; ReferencedTable = sqlForeignKey.ReferencedTable; ReferencedTableSchema = sqlForeignKey.ReferencedTableSchema; IsChecked = sqlForeignKey.IsChecked; IsSystemNamed = sqlForeignKey.IsSystemNamed; CreateDate = sqlForeignKey.CreateDate; DateLastModified = sqlForeignKey.DateLastModified; Urn = sqlForeignKey.Urn; State = sqlForeignKey.State.ToString(); // load information for each property foreach (Microsoft.SqlServer.Management.Smo.Property loopProperty in sqlForeignKey.Properties) { if (DebugHelper.DebugAction == DebugAction.Stop) { return; } if (loopProperty.Expensive == false && loopProperty.IsNull == false && !String.IsNullOrEmpty(loopProperty.Value.ToString())) { if (loopProperty.Name == "ID" || loopProperty.Name == "IsEnabled") { SqlProperty property = new SqlProperty(); property.SqlPropertyID = Guid.NewGuid(); property.SqlForeignKey = this; property.LoadProperty(loopProperty); SqlPropertyList.Add(property); } } } // load information for each extended property //foreach (ExtendedProperty loopProperty in sqlForeignKey.ExtendedProperties) //{ // SqlExtendedProperty property = new SqlExtendedProperty(); // property.SqlExtendedPropertyID = Guid.NewGuid(); // property.SqlForeignKey = this; // property.LoadExtendedProperty(loopProperty); // SqlExtendedPropertyList.Add(property); //} // load information for each column foreach (ForeignKeyColumn loopColumn in sqlForeignKey.Columns) { if (DebugHelper.DebugAction == DebugAction.Stop) { return; } SqlForeignKeyColumn column = new SqlForeignKeyColumn(); column.SqlForeignKeyColumnID = Guid.NewGuid(); column.SqlForeignKey = this; column.LoadColumn(loopColumn); SqlForeignKeyColumnList.Add(column); } } catch (ApplicationAbortException) { throw; } catch (Exception ex) { bool reThrow = BusinessConfiguration.HandleException(ex); if (reThrow) { throw; } } }
///-------------------------------------------------------------------------------- /// <summary>This loads information from a MySQL foreign key.</summary> /// /// <param name="sqlConnection">The input sql connection</param> /// <param name="variables">Database level variables</param> /// <param name="key">The key row data</param> /// <param name="keyColumns">The key columns table data</param> ///-------------------------------------------------------------------------------- public void LoadMySQLForeignKey(MySqlConnection sqlConnection, NameObjectCollection variables, DataRow key, DataTable keyColumns) { try { // load foreign key information foreach (DataColumn column in key.Table.Columns) { if (DebugHelper.DebugAction == DebugAction.Stop) { return; } // load important properties into foreign key, the rest as additional sql properties switch (column.ColumnName) { case "constraint_name": SqlForeignKeyName = key[column.ColumnName].GetString(); break; case "referenced_table_name": ReferencedTable = key[column.ColumnName].GetString(); break; case "referenced_table_schema": ReferencedTableSchema = key[column.ColumnName].GetString(); break; default: SqlProperty property = new SqlProperty(); property.SqlPropertyID = Guid.NewGuid(); property.SqlForeignKey = this; property.LoadMySQLProperty(column.ColumnName, null, key[column.ColumnName].GetString()); SqlPropertyList.Add(property); break; } } // load information for each column if (keyColumns != null) { foreach (DataRow row in keyColumns.Rows) { if (DebugHelper.DebugAction == DebugAction.Stop) { return; } if (row["TABLE_NAME"].GetString() == SqlTable.SqlTableName && row["CONSTRAINT_NAME"].GetString() == SqlForeignKeyName) { SqlForeignKeyColumn column = new SqlForeignKeyColumn(); column.SqlForeignKeyColumnID = Guid.NewGuid(); column.SqlForeignKey = this; column.LoadMySQLColumn(sqlConnection, variables, row); SqlForeignKeyColumnList.Add(column); } } } } catch (ApplicationAbortException) { throw; } catch (Exception ex) { bool reThrow = BusinessConfiguration.HandleException(ex); if (reThrow) { throw; } } }