Skip to content

Commit

Permalink
Revert "fix db_sqlite.tryInsertID does raise exceptions in 1.6.0 #197…
Browse files Browse the repository at this point in the history
…43 (#19744)"

This reverts commit b10f0e7.
  • Loading branch information
Araq authored Apr 25, 2022
1 parent b10f0e7 commit bbed8e5
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lib/impure/db_sqlite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ proc getValue*(db: DbConn, stmtName: SqlPrepared): string

proc tryInsertID*(db: DbConn, query: SqlQuery,
args: varargs[string, `$`]): int64
{.tags: [WriteDbEffect], raises: [].} =
{.tags: [WriteDbEffect], raises: [DbError].} =
## Executes the query (typically "INSERT") and returns the
## generated ID for the row or -1 in case of an error.
##
Expand All @@ -650,19 +650,16 @@ proc tryInsertID*(db: DbConn, query: SqlQuery,
## 1, "item#1") == -1
## db.close()
assert(not db.isNil, "Database not connected.")
var q = dbFormat(query, args)
var stmt: sqlite3.PStmt
result = -1
try:
var q = dbFormat(query, args)
var stmt: sqlite3.PStmt
if prepare_v2(db, q, q.len.cint, stmt, nil) == SQLITE_OK:
if step(stmt) == SQLITE_DONE:
result = last_insert_rowid(db)
if finalize(stmt) != SQLITE_OK:
result = -1
else:
discard finalize(stmt)
except DbError:
discard
if prepare_v2(db, q, q.len.cint, stmt, nil) == SQLITE_OK:
if step(stmt) == SQLITE_DONE:
result = last_insert_rowid(db)
if finalize(stmt) != SQLITE_OK:
result = -1
else:
discard finalize(stmt)

proc insertID*(db: DbConn, query: SqlQuery,
args: varargs[string, `$`]): int64 {.tags: [WriteDbEffect].} =
Expand Down Expand Up @@ -695,7 +692,7 @@ proc insertID*(db: DbConn, query: SqlQuery,

proc tryInsert*(db: DbConn, query: SqlQuery, pkName: string,
args: varargs[string, `$`]): int64
{.tags: [WriteDbEffect], raises: [], since: (1, 3).} =
{.tags: [WriteDbEffect], raises: [DbError], since: (1, 3).} =
## same as tryInsertID
tryInsertID(db, query, args)

Expand Down

0 comments on commit bbed8e5

Please sign in to comment.