Skip to content

Commit

Permalink
Check pqntuples > 0 in getValue. Fixes #12973 (#12974)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisheller authored and ringabout committed Dec 29, 2019
1 parent 6c6a7e3 commit 988a4ef
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/db_postgres.nim
Original file line number Diff line number Diff line change
Expand Up @@ -441,17 +441,25 @@ proc getValue*(db: DbConn, query: SqlQuery,
## executes the query and returns the first column of the first row of the
## result dataset. Returns "" if the dataset contains no rows or the database
## value is NULL.
var x = pqgetvalue(setupQuery(db, query, args), 0, 0)
result = if isNil(x): "" else: $x
var res = setupQuery(db, query, args)
if pqntuples(res) > 0:
var x = pqgetvalue(res, 0, 0)
result = if isNil(x): "" else: $x
else:
result = ""

proc getValue*(db: DbConn, stmtName: SqlPrepared,
args: varargs[string, `$`]): string {.
tags: [ReadDbEffect].} =
## executes the query and returns the first column of the first row of the
## result dataset. Returns "" if the dataset contains no rows or the database
## value is NULL.
var x = pqgetvalue(setupQuery(db, stmtName, args), 0, 0)
result = if isNil(x): "" else: $x
var res = setupQuery(db, stmtName, args)
if pqntuples(res) > 0:
var x = pqgetvalue(res, 0, 0)
result = if isNil(x): "" else: $x
else:
result = ""

proc tryInsertID*(db: DbConn, query: SqlQuery,
args: varargs[string, `$`]): int64 {.
Expand Down

0 comments on commit 988a4ef

Please sign in to comment.