stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.7k stars 1.56k forks source link

Fix insertMany([Encodable]) failing due to asymmetric setters #1138

Closed geoffmacd closed 2 years ago

geoffmacd commented 2 years ago

Fixes #1130, original PR (by me) was #1048

The problem was if you are trying to INSERT many rows, and some of those rows have different quantity of setters due to optional values, the INSERT query will fail with all VALUES must have the same number of terms in "INSERT INTO...

We needed to either guarantee that each Encodable will have the same number of setters OR force equivalent numbers of setters by adding NULL where the optional value is nil. This can be done with the encodeIfPresent methods on KeyedEncodingContainerProtocol in SQLiteKeyedEncodingContainer

withzombies commented 2 years ago

Would it be possible to cut a new release with this change?