             // Special case: Write additional info to the database log in the case of a database corruption.
             if error.code == Int(SQLITE_CORRUPT) {
                 writeCorruptionInfoForDBNamed(filename, toLogger: Logger.corruptLogger)
-            }
-
-            log.error("SQL error: \(error.localizedDescription).")
+                
+                SentryIntegration.shared.sendWithStacktrace(message: "SQLITE_CORRUPT for DB \(filename), \(error)", tag: "SwiftData", severity: .error)
+            }
+
+            log.error("SQL error. Error code: \(error.code), \(error) for SQL \(sqlStr).")
+            SentryIntegration.shared.sendWithStacktrace(message: "SQL error. Error code: \(error.code), \(error)", tag: "SwiftData", severity: .error)
+
             return Cursor<T>(err: error)
         }
 

        } catch let error1 as NSError {
            error = error1
            statement = nil
            log.error("SQL error: \(error1.localizedDescription) for SQL \(sqlStr).")
        }

        // Close, not reset -- this isn't going to be reused.

                throw err
            }
            if let err = openWithFlags(flags) {
                log.error("Error opening database with flags. Error code: \(err.code), \(err)")
                SentryIntegration.shared.sendWithStacktrace(message: "Error opening database with flags. Error code: \(err.code), \(err)", tag: "SwiftData", severity: .error)
                throw err
            }
            if let err = reKey(prevKey, newKey: key) {
                // Note: Don't log the error here as it may contain sensitive data.
                log.error("Unable to encrypt database.")
                SentryIntegration.shared.sendWithStacktrace(message: "Unable to encrypt database.", tag: "SwiftData", severity: .error)
                throw err
            }
        }
