groue / GRDB.swift

A toolkit for SQLite databases, with a focus on application development
MIT License
6.73k stars 696 forks source link

Do we have better way to resolve this issue? #1571

Closed glve1027 closed 2 months ago

glve1027 commented 2 months ago

What did you do?

I just remove the original database file, and re-generate a new file to replace it.

    fileprivate func handleError(error: Error) throws {
        if let error = error as? DatabaseError, error.resultCode == .SQLITE_CORRUPT {
            //try self.dbWriter.close() -> here
            var config = Configuration()
            config.prepareDatabase { database in
                try database.execute(sql: "PRAGMA auto_vacuum = FULL")
            }
            let currentQueue = try? DatabaseQueue(path: dbPathV2, configuration: config)
            self.dbWriter = currentQueue
            try self.migrator.migrate(self.dbWriter)
        } else {
            throw error
        }
    }

But there is warning message:

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

After I add this line, there is no warning message:

try self.dbWriter.close() 

What did you expect to happen?

But i noticed the comment from this function. It shouldn't be called, so Do we have a better way to resolve this issue? or Ignore warning message?

What happened instead?

Environment

GRDB flavor(s): (GRDB, SQLCipher, Custom SQLite build?) 6.8.0 GRDB version: Installation method: (CocoaPods, SPM, manual?) cocoapods Xcode version: iOS Swift version: 5.0 Platform(s) running GRDB: (iOS, macOS, watchOS?) macOS version running Xcode:

Demo Project

groue commented 2 months ago

Hello @glve1027,

The better way to resolve the SQLITE_CORRUPT error (you already mentioned it in #877, #1474, #1568) is to take care of the replies that were already given to you in your previous issues:

Opening new issues about SQLITE_CORRUPT will not help you: please stop. Instead, do what is recommended.

glve1027 commented 2 months ago

I don't ask anything about the SQLITE_CORRUPT. I just want to confirm with you about replacing the original database file, and there is a warning from SQLite.

glve1027 commented 2 months ago

And about the close method from GRDB.

groue commented 2 months ago

The documentation of [close()](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/databasereader/close()) says:

you should not call it unless the correct execution of your program depends on precise database closing.

It looks like it's the case of your app: go ahead.

glve1027 commented 2 months ago

Thanks