Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 807
doori Avatar asked Apr 13 '20 14:04

doori


1 Answers

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())

like image 62
Gereon Avatar answered Sep 22 '22 09:09

Gereon