/// <summary>Alter an existing table ensuring all columns exist.</summary> /// <param name="table">The table definition to write to the database.</param> private void AlterTable(DataTable table) { bool haveBegunTransaction = false; foreach (DataColumn column in table.Columns) { if (!columnNamesInDb.Contains(column.ColumnName)) { if (!haveBegunTransaction) { haveBegunTransaction = true; connection.BeginTransaction(); } // Column is missing from database file - write it. connection.AddColumn(Name, column.ColumnName, connection.GetDBDataTypeName(column.DataType)); columnNamesInDb.Add(column.ColumnName); } } // End the transaction that we started above. if (haveBegunTransaction) { connection.EndTransaction(); } }
/// <summary>Alter an existing table ensuring all columns exist.</summary> /// <param name="connection">The database connection to write to</param> private void AlterTable(IDatabaseConnection connection) { List <string> existingColumns = connection.GetTableColumns(Name); lock (lockObject) { foreach (Column col in Columns) { if (!existingColumns.Contains(col.Name)) { string dataTypeString; if (col.DatabaseDataType == null) { dataTypeString = "integer"; } else { dataTypeString = col.DatabaseDataType; } connection.AddColumn(Name, col.Name, dataTypeString); } } } }