-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
insertMany(_ encodables: [Encodable])
fails when optional fields (nullable) have nil
as its value on different fields among them.
Getting this message/error:
2022-04-28 09:23:36.842911-0400 SQliteBug[28203:735825] [logging] all VALUES must have the same number of terms in "INSERT INTO "person" ("name", "email") VALUES (?, ?), (?)"
Error The operation couldn’t be completed. (SQLite.Result error 0.)
Build Information
- SQLite.swift v.0.13.3, revision: 4d543d8
- Xcode 13.3.1. macOS Big Sur 11.6.5 / macOS Monterey 12.3.1
- How do do you integrate SQLite.swift in your project?
- Swift Package manager
General guidelines
- To reproduce the issue you can check this repo I created exclusively for this issue: https://github.com/duhnnie/SQLite.swift-Issue
- Or you can paste this code on your Swift project with SQLite.swift:
import SQLite
import Foundation
struct Person: Codable {
let id: Int?
let name: String
let email: String?
init(id: Int? = nil, name: String, email: String? = nil) {
self.id = id
self.name = name
self.email = email
}
}
let db = try Connection(NSHomeDirectory() + "/dbtest.sqlite")
let person = Table("person")
let id = Expression<Int64>("id")
let name = Expression<String>("name")
let email = Expression<String?>("email")
let createTable = person.create(ifNotExists: true) { t in
t.column(id, primaryKey: true)
t.column(name)
t.column(email)
}
try db.run(createTable)
let person1 = Person(name: "John", email: "[email protected]")
let person2 = Person(name: "David", email: nil)
let personsArray = [person1, person2]
do {
let insert = try person.insertMany(personsArray)
try db.run(insert)
} catch {
print("Error \(error.localizedDescription)")
}
Thanks in advance.
Metadata
Metadata
Assignees
Labels
No labels