mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-05 20:47:53 +00:00
Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
@@ -14,7 +14,8 @@ import strutils, postgres
|
||||
|
||||
type
|
||||
TDbConn* = PPGconn ## encapsulates a database connection
|
||||
TRow* = seq[string] ## a row of a dataset
|
||||
TRow* = seq[string] ## a row of a dataset. NULL database values will be
|
||||
## transformed always to the empty string.
|
||||
EDb* = object of EIO ## exception that is raised if a database error occurs
|
||||
|
||||
TSqlQuery* = distinct string ## an SQL query string
|
||||
@@ -110,7 +111,8 @@ iterator FastRows*(db: TDbConn, query: TSqlQuery,
|
||||
|
||||
proc getRow*(db: TDbConn, query: TSqlQuery,
|
||||
args: varargs[string, `$`]): TRow {.tags: [FReadDB].} =
|
||||
## retrieves a single row.
|
||||
## retrieves a single row. If the query doesn't return any rows, this proc
|
||||
## will return a TRow with empty strings for each column.
|
||||
var res = setupQuery(db, query, args)
|
||||
var L = PQnfields(res)
|
||||
result = newRow(L)
|
||||
@@ -131,8 +133,9 @@ iterator Rows*(db: TDbConn, query: TSqlQuery,
|
||||
|
||||
proc GetValue*(db: TDbConn, query: TSqlQuery,
|
||||
args: varargs[string, `$`]): string {.tags: [FReadDB].} =
|
||||
## executes the query and returns the result dataset's the first column
|
||||
## of the first row. Returns "" if the dataset contains no rows.
|
||||
## 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user