private static void LoadColumnsBase(IDataReader dr, List<Table> tables) { Table table = null; while (dr.Read()) { var c = new Column { Name = (string) dr["COLUMN_NAME"], Type = (string) dr["DATA_TYPE"], IsNullable = (string) dr["IS_NULLABLE"] == "YES", Position = (int) dr["ORDINAL_POSITION"], IsRowGuidCol = (string) dr["IS_ROW_GUID_COL"] == "YES" }; switch (c.Type) { case "binary": case "char": case "nchar": case "nvarchar": case "varbinary": case "varchar": c.Length = (int) dr["CHARACTER_MAXIMUM_LENGTH"]; break; case "decimal": case "numeric": c.Precision = (byte) dr["NUMERIC_PRECISION"]; c.Scale = (int) dr["NUMERIC_SCALE"]; break; } if (table == null || table.Name != (string) dr["TABLE_NAME"] || table.Owner != (string) dr["TABLE_SCHEMA"]) // only do a lookup if the table we have isn't already the relevant one table = FindTableBase(tables, (string) dr["TABLE_NAME"], (string) dr["TABLE_SCHEMA"]); table.Columns.Add(c); } }
public ColumnDiff Compare(Column c) { return new ColumnDiff(this, c); }
public ColumnDiff(Column target, Column source) { Source = source; Target = target; }
public void Remove(Column c) { mItems.Remove(c); }
public void Add(Column c) { mItems.Add(c); }
public void TestImportAndExportIgnoringComputedData() { var t = new Table("dbo", "Status"); t.Columns.Add(new Column("id", "int", false, null)); t.Columns.Add(new Column("code", "char", 1, false, null)); t.Columns.Add(new Column("description", "varchar", 20, false, null)); var computedCol = new Column("computed", "varchar", false, null); computedCol.ComputedDefinition = "code + ' : ' + description"; t.Columns.Add(computedCol); t.Columns.Find("id").Identity = new Identity(1, 1); t.AddConstraint(new Constraint("PK_Status", "PRIMARY KEY", "id")); var conn = TestHelper.GetConnString("TESTDB"); DBHelper.DropDb(conn); DBHelper.CreateDb(conn); SqlConnection.ClearAllPools(); DBHelper.ExecBatchSql(conn, t.ScriptCreate()); var dataIn = @"1 R Ready 2 P Processing 3 F Frozen "; var filename = Path.GetTempFileName(); var writer = File.AppendText(filename); writer.Write(dataIn); writer.Flush(); writer.Close(); try { t.ImportData(conn, filename); var sw = new StringWriter(); t.ExportData(conn, sw); Assert.AreEqual(dataIn, sw.ToString()); } finally { File.Delete(filename); } }