     }
     
     // MARK: - Not public
+    
+    private class Version {
+        let rowModel: RowModel
+        
+        lazy var databasePrimaryKey: PrimaryKey = self.rowModel.dynamicType.databasePrimaryKey
+        lazy var databaseDictionary: [String: SQLiteValueConvertible?] = self.rowModel.databaseDictionary
+        
+        // A primary key dictionary. Its values may be nil.
+        lazy var weakPrimaryKeyDictionary: [String: SQLiteValueConvertible?]? = {
+            switch self.databasePrimaryKey {
+            case .None:
+                return nil
+                
+            case .RowID(let column):
+                let databaseDictionary = self.databaseDictionary
+                if let value = databaseDictionary[column] {
+                    return [column: value]
+                } else {
+                    return nil
+                }
+                
+            case .Column(let column):
+                let databaseDictionary = self.databaseDictionary
+                if let value = databaseDictionary[column] {
+                    return [column: value]
+                } else {
+                    return nil
+                }
+                
+            case .Columns(let columns):
+                let databaseDictionary = self.databaseDictionary
+                var primaryKeyDictionary = [String: SQLiteValueConvertible?]()
+                for column in columns {
+                    if let value = databaseDictionary[column] {
+                        primaryKeyDictionary[column] = value
+                    } else {
+                        primaryKeyDictionary[column] = nil
+                    }
+                }
+                return primaryKeyDictionary
+            }
+        }()
+        
+        // A primary key dictionary. At least one of its values is not nil.
+        lazy var strongPrimaryKeyDictionary: [String: SQLiteValueConvertible?]? = {
+            guard let dictionary = self.weakPrimaryKeyDictionary else {
+                return nil
+            }
+            for case let value? in dictionary.values {
+                return dictionary // At least one non-nil value in the primary key dictionary is OK.
+            }
+            return nil
+        }()
+        
+        func updateRowModelWithInsertionChanges(changes: UpdateStatement.Changes) {
+            switch databasePrimaryKey {
+            case .RowID(let column):
+                if let optionalValue = databaseDictionary[column] {
+                    if optionalValue == nil {
+                        let row = Row(sqliteDictionary: [column: SQLiteValue.Integer(changes.insertedRowID!)])
+                        rowModel.updateFromDatabaseRow(row)
+                    }
+                } else {
+                    fatalError("databaseDictionary must return the value for the primary key `(column)`")
+                }
+            default:
+                return
+            }
+        }
+        
+        init(_ rowModel: RowModel) {
+            self.rowModel = rowModel
+        }
+    }
     
     // Attempts to build a primary key dictionary [String: SQLiteValueConvertible?].
     //

        }
        
        
        // The inserted values, and the primary key
        
        var insertedDic = databaseDictionary
        let primaryKey = self.dynamicType.databasePrimaryKey
        
        
        // Should we include the primary key in the insert statement?
        // We do, unless the key is a SQLite RowID, without any value.
        
        let rowIDColumn: String?
        switch primaryKey {
        case .RowID(let column):
            if let _ = insertedDic[column]! {
                rowIDColumn = nil
            } else {
                insertedDic.removeValueForKey(column)
                rowIDColumn = column
            }
        default:
            rowIDColumn = nil
        }
        
        
        // If there is nothing to insert, and primary key is not managed,
        // something is wrong.
        
        guard insertedDic.count > 0 || rowIDColumn != nil else {
            fatalError("Nothing to insert")
        }
        
        
        // INSERT INTO table ([id, ]name) VALUES ([:id, ]:name)
        
        let columns = insertedDic.keys
        let columnSQL = ",".join(columns.map { $0.sqliteQuotedIdentifier })
        let valuesSQL = ",".join([String](count: columns.count, repeatedValue: "?"))
        let verb: String
        if let conflictResolution = conflictResolution {
            switch conflictResolution {

        }
        
        
        // Extract strong primary key
        
        let version = Version(self)
        guard let primaryKeyDictionary = version.strongPrimaryKeyDictionary else {
            fatalError("No primaryKey")
        }
        
