How can i resolve warning message 'BUG IN CLIENT OF libsqlite3.dylib: database integrity compromised by API violation' in Sqlite.swift?
Asked Answered
I

2

9

i'm using Sqlite.swift

when i restart app in simulator, i want to remove existing database and make new database. (because of initializing database... i change the database column a lot.)

but there is warning message.

[logging] BUG IN CLIENT OF libsqlite3.dylib: database integrity compromised by API violation: vnode unlinked while in use:

i know it's about integrity... but i don't know how can i resolve the problem.

here is my code. when you click the button 'Create', func createDB() will work.

    func createDB() {
        print("CREATE DB")
        do {

            let documentDirectory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)

            let fileUrl = documentDirectory.appendingPathExtension("test").appendingPathExtension("sqlite3")

            // if there is existing db, then remove it
            let fileMng = FileManager.default
            if fileMng.fileExists(atPath: fileUrl.path) {
                do {
                    try fileMng.removeItem(at: fileUrl)
                    print("remove db file because you already have db")
                }
                catch {
                    print("Remove DB Error", error)
                }
            }

            let database = try Connection(fileUrl.path)
            self.database = database
            print("Successfully create database")
        }
        catch {
            print("Create DB Error : ", error)
        }
    }

and this is log.

CREATE DB
remove db file because you already have db
Successfully create database
CREATE DB
remove db file because you already have db
2020-04-13 23:01:36.866156+0900 RealmTest[40604:6719249] [logging] BUG IN CLIENT OF libsqlite3.dylib: database integrity compromised by API violation: vnode unlinked while in use: {directory-address-in-my-local-computer}
2020-04-13 23:01:36.866272+0900 RealmTest[40604:6719249] [logging] invalidated open fd: 5 (0x11)
Successfully create database

i found out this is not error, but warning. and when i restart app, the removing operation work very well without warning message. but when i second click the button 'Create', the warning message alerts.

i didn't delete the database when I turned off the app. therefore, i think it is clear that the database will be deleted when the app is turned on again. so i don't know what the problem is with creating a db twice. I'd really appreciate it if you could tell me! Please let me know.

Isometric answered 13/4, 2020 at 14:12 Comment(1)
I've been getting this problem while creating a temporary persistent storage using SwiftData in unit tests. After each test when it tears down the container it spits out this warning.Piragua
C
6

You need to make sure that before you call your createDB() method, any pending connections to your database are closed. You have at least one such connection in your code, in self.database so you need to set that to nil.

self.database = nil
self.createDB()

(Alternatively, you can to that inside createDB())

Cordate answered 13/4, 2020 at 14:49 Comment(0)
C
0

I don't have a better solution, but for what it's worth -- I am getting the same error when I try to delete and recreate my database in a Google Drive folder on my Mac, but not when I use a local folder such as my home directory.

Cosmopolis answered 20/11, 2021 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.