'Database Methods Cannot Be Reentrant' error even though there is no reentry Swift

36 Views Asked by At

I am pretty new to swift and GRDB and am experiencing issues with this code. The exact error I get is 'Fatal error: Database methods are not reentrant.'. Due to the error, "Error occurred" is always printing. ConvertListToJSON doesn't interact with the DB. Any help would be appreciated

do {
    try dbQueue.write { db in
    try db.execute(
    sql: "INSERT INTO \(accountTableName) (\(accountUUID), \(accountEmailAddress), \(accountMainPhotoReference), \(accountPhotoTwoReference), \(accountPhotoThreeReference), \(accountPhotoFourReference), \(accountPhotoFiveReference), \(accountPhotoSixReference), \(accountBio), \(accountName), \(accountDOB), \(accountProfileComplete), \(accountInterests), \(accountLifestyle), \(accountGender), \(accountAgePrivacy), \(accountDistancePrivacy), \(accountPhoneNumber), \(accountShowReviewPopup)) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
    arguments: [accountData[0], accountData[1], mainPhotoReference, photoTwoReference, photoThreeReference, photoFourReference, photoFiveReference, photoSixReference, accountData[8], accountData[9], accountData[10], accountData[11], convertListToJSON(list: Array(accountData[12..<16])), convertListToJSON(list: Array(accountData[17..<21])), accountData[22], accountData[23], accountData[24], accountData[25], "True"]
    )
   }
  }
catch {
  print("Error occurred")
}

I fixed previous errors with this code and tried debugging the code but I didn't gain enough information to solve the problem

1

There are 1 best solutions below

1
user19953380 On

Solved it, for people experiencing the same issue check how many places you use dbQueue.write and dbQueue.read. You can find the function and line that caused the error by looking through the numbered headings under Thread 1 on the left hand side of Xcode