Exemple #1
0
 /// <summary>
 /// Updates an existing database table to 'match' a schema by adding any missing columns.
 /// </summary>
 /// <param name="adapter">Open adapter to a database.</param>
 /// <param name="schema">The schema to use to update the database.</param>
 /// <returns>True if table is successfully updated to match schema.</returns>
 public static bool UpdateTableToMatchSchema(IDbAdapter adapter, DataTable schema)
 {
     // Check if we need to update the db schema and/or this result schema.
     var dbTable = adapter.GetSchema(schema.TableName);
     if (!schema.SchemaEquals(dbTable))
     {
         try
         {
             // Insert any missing columns into the database.
             adapter.AddColumnsToTableToMatchSchema(dbTable.TableName, schema);
             return true;
         }
         catch (DbException ex)
         {
             Log.Error("Failed to initialize database writer: " + ex.Message);
             return false;
         }
     }
     Log.Debug("Database table already matches schema; nothing to update.");
     return true;
 }
Exemple #2
0
        /// <summary>
        /// Updates an existing database table to 'match' a schema by adding any missing columns.
        /// </summary>
        /// <param name="adapter">Open adapter to a database.</param>
        /// <param name="schema">The schema to use to update the database.</param>
        /// <returns>True if table is successfully updated to match schema.</returns>
        public static bool UpdateTableToMatchSchema(IDbAdapter adapter, DataTable schema)
        {
            // Check if we need to update the db schema and/or this result schema.
            var dbTable = adapter.GetSchema(schema.TableName);

            if (!schema.SchemaEquals(dbTable))
            {
                try
                {
                    // Insert any missing columns into the database.
                    adapter.AddColumnsToTableToMatchSchema(dbTable.TableName, schema);
                    return(true);
                }
                catch (DbException ex)
                {
                    Log.Error("Failed to initialize database writer: " + ex.Message);
                    return(false);
                }
            }
            Log.Debug("Database table already matches schema; nothing to update.");
            return(true);
        }