ShouldRecoverSQLite reports whether the open error indicates recoverable corruption.
(err error)
| 220 | |
| 221 | // ShouldRecoverSQLite reports whether the open error indicates recoverable corruption. |
| 222 | func ShouldRecoverSQLite(err error) bool { |
| 223 | if err == nil { |
| 224 | return false |
| 225 | } |
| 226 | |
| 227 | var sqliteErr *sqlite.Error |
| 228 | if !errors.As(err, &sqliteErr) { |
| 229 | return false |
| 230 | } |
| 231 | switch sqliteErr.Code() & sqlitePrimaryResultCodeMask { |
| 232 | case sqlite3.SQLITE_CORRUPT, sqlite3.SQLITE_NOTADB: |
| 233 | return true |
| 234 | default: |
| 235 | return false |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | func closeQuietly(db *sql.DB) { |
| 240 | if db != nil { |
no test coverage detected