failed to open database chat.db on Xcode's project(swift)
as I'm saying, I'm trying to open database(~/Library/Messages/chat.db) on a swift project in Xcode, but I got some warning like
(2024-04-10 17:12:11.867139+0800 listenFunction_v0[1564:74241] Metal API Validation Enabled
Error: authorization denied (code: 23))
I know it maybe existing some permission issues, and I added Xcode to full disk access, and I'm sure that permissions of chat.db are "rwx-rwx-rwx". I did everything I can, however it still warning same as I said, it doesn't work😭😭😭😭 I used to write the same code(same function, just taking sql query on chat.db) in AppleScript it worked as I hope, or execute the command line directly with the terminal. btw, I'm coding on macOS 12.2.1 and Xcode 13.4. I wish someone can help me solve this problem if possible😭😭😭😭😭
here is some of my code:
import SQLite
let messages = Table("messages")
let id = Expression<Int>("id")
let sender = Expression<String?>("sender")
let text = Expression<String>("text")
func performSQLQuery() {
do {
let dbPath = "/Users/Mac/Library/Messages/chat.db"
let db = try Connection(dbPath)
for message in try db.prepare(messages) {
print("ID: \(message[id]), Sender: \(message[sender]), Text: \(message[text])")
}
} catch {
print("Error: \(error)")
}
}
performSQLQuery()
MacBook Pro 13″, macOS 12.2