chore: sqlite make sure code is always run (#2891)

This commit is contained in:
Ivan FB 2024-07-10 18:34:28 +02:00 committed by GitHub
parent e1518cf9ff
commit 4ac4ab2a41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 14 deletions

View File

@ -234,11 +234,13 @@ proc query*(
return err($sqlite3_errstr(v))
return ok gotResults
except Exception, CatchableError:
# release implicit transaction
discard sqlite3_reset(s) # same return information as step
discard sqlite3_clear_bindings(s) # no errors possible
discard sqlite3_finalize(s)
# NB: dispose of the prepared query statement and free associated memory
error "exception in query", query = query, error = getCurrentExceptionMsg()
# release implicit transaction
discard sqlite3_reset(s) # same return information as step
discard sqlite3_clear_bindings(s) # no errors possible
discard sqlite3_finalize(s)
# NB: dispose of the prepared query statement and free associated memory
proc prepareStmt*(
db: SqliteDatabase, stmt: string, Params: type, Res: type

View File

@ -1,6 +1,7 @@
{.push raises: [].}
import std/[options, sequtils], stew/byteutils, sqlite3_abi, results
import chronicles
import
../../../common/databases/db_sqlite,
../../../common/databases/common,
@ -427,9 +428,12 @@ proc execSelectMessagesV2WithLimitStmt(
else:
return err($sqlite3_errstr(v))
except Exception, CatchableError:
# release implicit transaction
discard sqlite3_reset(s) # same return information as step
discard sqlite3_clear_bindings(s) # no errors possible
error "exception in execSelectMessagesV2WithLimitStmt",
error = getCurrentExceptionMsg()
# release implicit transaction
discard sqlite3_reset(s) # same return information as step
discard sqlite3_clear_bindings(s) # no errors possible
proc selectMessagesByHistoryQueryWithLimit*(
db: SqliteDatabase,
@ -498,9 +502,11 @@ proc execSelectMessageByHash(
else:
return err($sqlite3_errstr(v))
except Exception, CatchableError:
# release implicit transaction
discard sqlite3_reset(s) # same return information as step
discard sqlite3_clear_bindings(s) # no errors possible
error "exception in execSelectMessageByHash", error = getCurrentExceptionMsg()
# release implicit transaction
discard sqlite3_reset(s) # same return information as step
discard sqlite3_clear_bindings(s) # no errors possible
proc selectMessageByHashQuery(): SqlQueryStr =
var query: string
@ -629,9 +635,12 @@ proc execSelectMessagesWithLimitStmt(
else:
return err($sqlite3_errstr(v))
except Exception, CatchableError:
# release implicit transaction
discard sqlite3_reset(s) # same return information as step
discard sqlite3_clear_bindings(s) # no errors possible
error "exception in execSelectMessagesWithLimitStmt",
error = getCurrentExceptionMsg()
# release implicit transaction
discard sqlite3_reset(s) # same return information as step
discard sqlite3_clear_bindings(s) # no errors possible
proc selectMessagesWithLimitQuery(
table: string, where: Option[string], limit: uint, ascending = true, v3 = false