fix insertMessages: use COUNT(*) instead of MessageRecord.fetchOne for existence check
MessageRecord.fetchOne decodes all columns but the query only selects id, causing "column not found: accountId". Use COUNT(*) which returns a plain Int. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -61,12 +61,11 @@ public final class MailStore: Sendable {
|
||||
try dbWriter.write { db in
|
||||
var inserted: [MessageRecord] = []
|
||||
for message in messages {
|
||||
// Check if a message with this (mailboxId, uid) already exists
|
||||
let exists = try MessageRecord.fetchOne(db, sql:
|
||||
"SELECT id FROM message WHERE mailboxId = ? AND uid = ?",
|
||||
let count = try Int.fetchOne(db, sql:
|
||||
"SELECT COUNT(*) FROM message WHERE mailboxId = ? AND uid = ?",
|
||||
arguments: [message.mailboxId, message.uid]
|
||||
)
|
||||
if exists == nil {
|
||||
) ?? 0
|
||||
if count == 0 {
|
||||
try message.insert(db)
|
||||
inserted.append(message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user