groue / GRDB.swift

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

Unable to successfully initialize GRDB #1568

Closed glve1027 closed 2 months ago

glve1027 commented 2 months ago

What did you do?

  1. init GRDB on the main queue like this:

    final public class XXXXDBAppDatabase {
    
    fileprivate static let dbPathV2 = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last! + "/test.db"
    
    static let shared = makeShared()
    
    private static func makeShared() -> XXXDBAppDatabase? {
        do {
            var config = Configuration()
            config.prepareDatabase { database in
                try database.execute(sql: "PRAGMA auto_vacuum = FULL")
            }
            let currentQueue = try DatabaseQueue(path: XXXDBAppDatabase.dbPathV2, configuration: config)
    
            // Create the AppDatabase
            let appDatabase = try XXXDBAppDatabase(currentQueue)
    
            return appDatabase
        } catch {
            Log(error.localizedDescription)
            print(error)
            return nil
        }
    }
    }

1. I got a error message from above method:

SQLite error 11: database disk image is malformed - while executing PRAGMA auto_vacuum = FULL

2. I notice that try database.execute(sql: "PRAGMA auto_vacuum = FULL") excute on Thread: GRDB.DatabaseQueue, I'm not sure this has anything to do with it.

3. I used two different serial queue to handle two different model, Although they are different objects. I'm not sure this has anything to do with it.


public struct AEvent {    // DispatchQueue(label: "handle.AEvent")
var ID: Int64?
var xxxx
}

public struct BEvent { // DispatchQueue(label: "handle.BEvent") var ID: Int64? var yyyy }



### I noticed another thing is: https://github.com/groue/GRDB.swift/issues/415. I don't update to readonly like this: `config.readonly = true`,  I'm not sure this has anything to do with it.

<!-- Please replace this with what you did. -->

### What did you expect to happen?

1. find the root cause why Unable to successfully initialize, and how to fix it?
<!-- Please replace this with what you expected to happen. -->

### What happened instead?
1. Unable to successfully initialize
<!-- Please replace this with of what happened instead. -->

### Environment

**GRDB flavor(s):** (GRDB, SQLCipher, Custom SQLite build?)  GRDB
**GRDB version:**  `"GRDB.swift", "6.8.0"`"[GRDB.swift](https://cocoapods.org/pods/GRDB.swift)", "6.8.0"
**Installation method:** (CocoaPods, SPM, manual?)  CocoaPods
**Xcode version:**  Version 15.2
**Swift version:**  5.0
**Platform(s) running GRDB:** (iOS, macOS, watchOS?)iOS
**macOS version running Xcode:**

### Demo Project

<!-- Please link to or upload a project we can download that reproduces the issue. -->
groue commented 2 months ago

Hello @glve1027

I'm not sure this issue contains any more information than your previous issue #877. You did not seemed to care about the answers there. I'm unsure you'll care about the answers here. There's not point keeping issues open when people don't care about the answers.