In Xcode 13, this would throw an error SQLError(code: 14, message: "unable to open database file")
. Turns out in Xcode 14, the last folder name (UUID().uuidString
) is treated as file name and a new file gets created when calling open.
What changed in Xcode 14? And is it possible to configure sqlite3_open_v2
so it will fail for a directory path instead of creating a file unexpectedly?
let temp = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
dbURL = temp.appendingPathComponent(UUID().uuidString, isDirectory: true)
var connectionPointer: OpaquePointer?
let flags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX
let code = sqlite3_open_v2(dbURL.absoluteString, &connectionPointer, flags, nil)
if code != SQLITE_OK {
throw SQLError.lastError(in: connectionPointer!)
}
Edit:
Tried using the SQLITE_OPEN_URI
flag to see if it would enable a more rigorous check of the URL passed in. But it did not help.