private Model.View GetNewView(SQLDMO.View dmoView) { Model.View view = new Model.View(dmoView.Name, Script.GetSingluar(dmoView.Name), false); // Columns int ordinalPosition = 0; List<SQLDMO.Column> dmoColumns = new List<SQLDMO.Column>(); SQLDMO.SQLObjectList sqlObjectList = dmoView.ListColumns(); foreach (SQLDMO.Column dmoColumn in sqlObjectList) { dmoColumns.Add(dmoColumn); } dmoColumns.Sort(new SortComparer<SQLDMO.Column>("ID", System.ComponentModel.ListSortDirection.Ascending)); foreach (SQLDMO.Column dmoColumn in dmoColumns) { if (UnsupportedDataTypes.ToLower().IndexOf("'" + dmoColumn.PhysicalDatatype.ToLower() + "'") >= 0) { continue; } Column column = new Column(dmoColumn.Name, Script.GetSingluar(dmoColumn.Name), false, dmoColumn.Name, view, ordinalPosition, dmoColumn.AllowNulls, dmoColumn.PhysicalDatatype, dmoColumn.Length, false, dmoColumn.Identity, dmoColumn.Default, true); view.AddColumn(column); ordinalPosition++; } return view; }
private Model.StoredProcedure GetNewStoredProcedure(SQLDMO.StoredProcedure dmoStoredProcedure) { Model.StoredProcedure storedProcedure = new Model.StoredProcedure(dmoStoredProcedure.Name, Script.GetSingluar(dmoStoredProcedure.Name), false); storedProcedure.Enabled = false; // Columns //int ordinalPosition = 0; //SQLDMO.Column[] dmoColumns = GetColumns(dmoStoredProcedure); //foreach (SQLDMO.Column dmoColumn in dmoColumns) //{ /*if (UnsupportedDataTypes.ToLower().IndexOf("'" + dmoColumn.PhysicalDatatype.ToLower() + "'") >= 0) { continue; } Column column = new Column(dmoColumn.Name, Script.GetSingluar(dmoColumn.Name), dmoColumn.Name, storedProcedure, ordinalPosition, dmoColumn.AllowNulls, dmoColumn.PhysicalDatatype, dmoColumn.Length, dmoColumn.InPrimaryKey, false, false, dmoColumn.Identity); storedProcedure.Columns.Add(column); ordinalPosition++;*/ //} // Parameters SQLDMO.QueryResults queryResults = dmoStoredProcedure.EnumParameters(); for (int i = 1; i <= queryResults.Rows; i++) { //Model.StoredProcedure.Parameter parameter = new Model.StoredProcedure.Parameter(queryResults.GetColumnString(i, 1), queryResults.GetColumnString(i, 1).Replace("@", ""), queryResults.GetColumnString(i, 2)); //storedProcedure.AddParameter(parameter); } return storedProcedure; }
private Model.Table GetNewTable(SQLDMO.Table dmoTable) { Model.Table table = new Model.Table(dmoTable.Name, Script.GetSingluar(dmoTable.Name), false); // Columns int ordinalPosition = 0; List<SQLDMO.Column> dmoColumns = new List<SQLDMO.Column>(); foreach (SQLDMO.Column dmoColumn in dmoTable.Columns) { dmoColumns.Add(dmoColumn); } foreach (SQLDMO.Column dmoColumn in dmoColumns) { if (UnsupportedDataTypes.ToLower().IndexOf("'" + dmoColumn.PhysicalDatatype.ToLower() + "'") >= 0) { continue; } Column column = new Column(dmoColumn.Name, Script.GetSingluar(dmoColumn.Name), false, dmoColumn.Name, table, ordinalPosition, dmoColumn.AllowNulls, dmoColumn.PhysicalDatatype, dmoColumn.Length, dmoColumn.InPrimaryKey, dmoColumn.Identity, dmoColumn.Default, dmoColumn.IsComputed); table.AddColumn(column); ordinalPosition++; } // Index foreach (SQLDMO.Index dmoIndex in dmoTable.Indexes) { string indexType; if (dmoIndex.Type == SQLDMO.SQLDMO_INDEX_TYPE.SQLDMOIndex_DRIPrimaryKey) { continue; } if (dmoIndex.Type == SQLDMO.SQLDMO_INDEX_TYPE.SQLDMOIndex_DRIUniqueKey) { continue; } else { continue; //throw new Exception("IndexType " + dmoIndex.Type + " Not Defined"); } // Create Alias string indexAlias = indexType + "_"; SQLDMO.SQLObjectList indexes = dmoIndex.ListIndexedColumns(); for (int i = 1; i <= indexes.Count; i++) { SQLDMO._Column dmoColumn = (SQLDMO._Column)indexes.Item(i); indexAlias += dmoColumn.Name; if (i < indexes.Count) { indexAlias += "And"; } } Index index = new Index(dmoIndex.Name, Script.GetSingluar(indexAlias), false, indexType, table); // Fill Columns for (int i = 1; i <= indexes.Count; i++) { SQLDMO._Column dmoColumn = (SQLDMO._Column)indexes.Item(i); Column indexColumn = new Column(dmoColumn.Name, Script.GetSingluar(dmoColumn.Name), false); index.AddColumn(indexColumn); } table.AddIndex(index); } // Indexes -- that should be keys foreach (SQLDMO.Index dmoIndex in dmoTable.Indexes) { string keyType; if (dmoIndex.Type == SQLDMO.SQLDMO_INDEX_TYPE.SQLDMOIndex_DRIPrimaryKey) { keyType = DatabaseConstant.KeyType.Primary; } if (dmoIndex.Type == SQLDMO.SQLDMO_INDEX_TYPE.SQLDMOIndex_DRIUniqueKey) { keyType = DatabaseConstant.KeyType.Unique; } else { continue; //throw new Exception("KeyType " + dmoIndex.Type + " Not Defined"); } // Create Alias string keyAlias = keyType + "_"; SQLDMO.SQLObjectList indexes = dmoIndex.ListIndexedColumns(); for (int i = 1; i <= indexes.Count; i++) { SQLDMO._Column dmoColumn = dmoTable.Columns.Item(indexes.Item(i)); keyAlias += dmoColumn.Name; if (i < indexes.Count) { keyAlias += "And"; } } Key key = new Key(dmoIndex.Name, Script.GetSingluar(keyAlias), false, keyType, table); // Fill Columns for (int i = 1; i <= indexes.Count; i++) { Column keyColumn = new Column(indexes.Item(i).ToString(), Script.GetSingluar(indexes.Item(i).ToString()), false); key.AddColumn(keyColumn); } table.AddKey(key); } // Keys foreach (SQLDMO.Key dmoKey in dmoTable.Keys) { string keyType; if (dmoKey.Type == SQLDMO.SQLDMO_KEY_TYPE.SQLDMOKey_Primary) { keyType = DatabaseConstant.KeyType.Primary; } else if (dmoKey.Type == SQLDMO.SQLDMO_KEY_TYPE.SQLDMOKey_Foreign) { keyType = DatabaseConstant.KeyType.Foreign; } else if (dmoKey.Type == SQLDMO.SQLDMO_KEY_TYPE.SQLDMOKey_Unique) { keyType = DatabaseConstant.KeyType.Unique; } else if (dmoKey.Type == SQLDMO.SQLDMO_KEY_TYPE.SQLDMOKey_Unknown) { continue; } else { throw new Exception("KeyType " + dmoKey.Type.ToString() + " Not Defined"); } // Create Alias string keyAlias = keyType + "_"; for (int i = 1; i <= dmoKey.KeyColumns.Count; i++) { SQLDMO._Column dmoColumn = dmoTable.Columns.Item(dmoKey.KeyColumns.Item(i)); keyAlias += dmoColumn.Name; if (i < dmoKey.KeyColumns.Count) { keyAlias += "And"; } } Key key = new Key(dmoKey.Name, Script.GetSingluar(keyAlias), false, keyType, table); // Fill Columns for (int i = 1; i <= dmoKey.KeyColumns.Count; i++) { Column keyColumn = new Column(dmoKey.KeyColumns.Item(i), Script.GetSingluar(dmoKey.KeyColumns.Item(i)), false); key.AddColumn(keyColumn); } if (keyType == DatabaseConstant.KeyType.Foreign) { // Fill References key.ReferencedTable = new Model.Table(dmoKey.ReferencedTable, Script.GetSingluar(dmoKey.ReferencedTable), false); if (dmoKey.ReferencedKey != null) { key.ReferencedKey = new Key(dmoKey.ReferencedKey, Script.GetSingluar(dmoKey.ReferencedKey), false); } // Fill Referenced Columns for (int i = 1; i <= dmoKey.KeyColumns.Count; i++) { Column referencedKeyColumn = new Column(dmoKey.ReferencedColumns.Item(i), Script.GetSingluar(dmoKey.ReferencedColumns.Item(i)), false); key.AddReferencedColumn(referencedKeyColumn); } } table.AddKey(key); } return table; }