sqlite3.dylib: illegal multi-threaded access to database connection

后端 未结 4 1631
[愿得一人]
[愿得一人] 2021-01-02 08:40

I have an iOS app that uses sqlite3 and I\'m facing issues with multi-threading crashing the app with the illegal multi-threaded access to database connec

4条回答
  •  遥遥无期
    2021-01-02 09:17

    In case of any one faced this problem in Swift. Solution will be:

    let dbName = "first.db"
    static let shared = DatabaseManger()
    var db: OpaquePointer?
    
    
    private init(){
        print("singletone initialized")
        sqlite3_shutdown();
        let dbPath = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
            .appendingPathComponent(dbName)
        if sqlite3_open_v2(dbPath.path, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX, nil) == SQLITE_OK {
            print("Successfully opened database connection at \(dbPath.path)")
        }
        else {
            print("unable to open database connection")
        }
    }
    

    This code tested in swift version 4.0 and 4.2

提交回复
热议问题