Restructure 2.1.3 Released
- Date
A bug was found where if a statement was reused and one of the bindings went from a non-nil value to a nil value, the binding would not update. For example:
try restructure.execute(query: "CREATE TABLE foo (name TEXT NULL)")
let statement = try restructure.prepare(query: "INSERT INTO foo (name) VALUES (:name)")
let encoder = StatementEncoder()
struct Foo {
name: String?
}
statement.reset()
try enconder.encode(Foo(name: "Bar"), to: statement)
statement.step()
statement.reset()
try enconder.encode(Foo(name: nil), to: statement)
statement.step()
In this case, both records would have a name of “Bar”.
This bug comes from the use of KeyedEncodingContainerProtocol
. I assumed that implementing encodeNil
would be enough
for handling nil values, but the code needs to also implement the encodeIfPresent
methods.
Also, along with being on Github, I’ve also added Restructure to the Swift Package Index.