public void EnsureTable(DbDataReader dbReader) { var reader = (NpgsqlDataReader)dbReader; lock (lockObject) { var readerColumns = PostgreeSqlDatabase.GetColumns(reader); if (columns != null) { CheckColumns(columns, "original", readerColumns, "current"); return; } columns = readerColumns; if (historyMode) { if (!target.TableExists(tableName)) { target.CreateTable(tableName, columns); } else { var existingColumns = target.GetColumns(tableName); CheckColumns(existingColumns, "existing", columns, "new"); } } else { if (target.TableExists(tableName)) { target.DropTable("dbo." + tableName); } target.CreateTable(tableName, columns); } } }
public void BeginWrite(DataColumn[] newColumns) { columns = newColumns; if (historyMode) { if (!target.TableExists(tableName)) { target.CreateTable(tableName, newColumns); } else { var existingColumns = target.GetColumns(tableName); DatabaseHelpers.CheckColumnsAreEqual(existingColumns, "existing", newColumns, "new"); } } else { if (target.TableExists(tableName)) { target.DropTable("dbo." + tableName); } target.CreateTable(tableName, newColumns); } }