diff options
author | Chris Heller <chrisheller@users.noreply.github.com> | 2019-12-29 08:41:18 -0800 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-12-29 17:41:18 +0100 |
commit | 8d1a7db6ea7cd4e8d9e2b38874477c12b99ffcd7 (patch) | |
tree | 3b8f912685e46f5abdcfa520b7252f0f3f90f666 | |
parent | 441cacf70f6de5369f3fba5d8bda966277881a71 (diff) | |
download | Nim-8d1a7db6ea7cd4e8d9e2b38874477c12b99ffcd7.tar.gz |
Check pqntuples > 0 in getValue. Fixes #12973 (#12974)
-rw-r--r-- | lib/impure/db_postgres.nim | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index fde4db119..57c61fa23 100644 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -441,8 +441,12 @@ 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 {. @@ -450,8 +454,12 @@ proc getValue*(db: DbConn, stmtName: SqlPrepared, ## 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 {. |