sdk/dotnet/src/Microsoft.Datasync.Client.SQLiteStore/OfflineSQLiteStore.cs
/// <summary>
/// Creates or updates the table definition in the SQLite database to the provided definition.
/// </summary>
/// <param name="tableDefinition"></param>
Creates or updates the table definition in the SQLite database to the provided definition.
Creates or updates the table definition in the SQLite database to the provided definition .
protected void CreateTableFromDefinition(TableDefinition tableDefinition)
        {
            var idColumn = tableDefinition.Columns.First(c => c.IsIdColumn);
            var columnDefinitions = tableDefinition.Columns.Where(c => !c.IsIdColumn);
            string createTableSql = SqlStatements.CreateTableFromColumns(tableDefinition.TableName, idColumn, columnDefinitions);
            ExecuteNonQueryInternal(createTableSql);
            string tableInfoSql = SqlStatements.GetTableInformation(tableDefinition.TableName);
            IDictionary<string, JObject> existingColumns = ExecuteQueryInternal(tableInfoSql).ToDictionary(c => c.Value<string>("name"), StringComparer.OrdinalIgnoreCase);
            foreach (var column in tableDefinition.Columns.Where(c => !existingColumns.ContainsKey(c.Name)))
            {
                string addColumnSql = SqlStatements.AddColumnToTable(tableDefinition.TableName, column);
                ExecuteNonQueryInternal(addColumnSql);
            }
            foreach (var column in existingColumns.Keys.Where(c => !tableDefinition.ContainsKey(c)))
            {
                string dropColumnSql = SqlStatements.DropColumnFromTable(tableDefinition.TableName, column);
                ExecuteNonQueryInternal(dropColumnSql);
            }
        }
protected void CreateTableFromDefinition ( TableDefinition tableDefinition ) { var idColumn = tableDefinition . Columns . First ( c => c . IsIdColumn ) ; var columnDefinitions = tableDefinition . Columns . Where ( c => ! c . IsIdColumn ) ; string createTableSql = SqlStatements . CreateTableFromColumns ( tableDefinition . TableName , idColumn , columnDefinitions ) ; ExecuteNonQueryInternal ( createTableSql ) ; string tableInfoSql = SqlStatements . GetTableInformation ( tableDefinition . TableName ) ; IDictionary < string , JObject > existingColumns = ExecuteQueryInternal ( tableInfoSql ) . ToDictionary ( c => c . Value < string > ( " " ) , StringComparer . OrdinalIgnoreCase ) ; foreach ( var column in tableDefinition . Columns . Where ( c => ! existingColumns . ContainsKey ( c . Name ) ) ) { string addColumnSql = SqlStatements . AddColumnToTable ( tableDefinition . TableName , column ) ; ExecuteNonQueryInternal ( addColumnSql ) ; } foreach ( var column in existingColumns . Keys . Where ( c => ! tableDefinition . ContainsKey ( c ) ) ) { string dropColumnSql = SqlStatements . DropColumnFromTable ( tableDefinition . TableName , column ) ; ExecuteNonQueryInternal ( dropColumnSql ) ; } }
Creates or updates the table definition in the SQLite database to the provided definition.
Creates or updates the table definition in the SQLite database to the provided definition .
// Process changes to the table definition - column(s) added // Process changes to the table definition - column(s) removed // TODO: Detect changes in the SQLite definition (column types) and throw an exception if the store type does not match.
tableDefinition
TableDefinition
None