diff options
author | Varriount <Varriount@users.noreply.github.com> | 2014-10-24 21:07:54 -0400 |
---|---|---|
committer | Varriount <Varriount@users.noreply.github.com> | 2014-10-24 21:07:54 -0400 |
commit | d4820517108cd56939c0df8378b9b34ef0867e08 (patch) | |
tree | 9b2e3830262cf858630653512108e1603befe243 /lib/impure/db_postgres.nim | |
parent | 134311c7e0c3da1ef59be11fcbdf3c27fbdc9faf (diff) | |
parent | 2a203e5340654936e3bbe1c0ac392221d15c9aeb (diff) | |
download | Nim-d4820517108cd56939c0df8378b9b34ef0867e08.tar.gz |
Merge pull request #1497 from milosn/devel
Preserve nil <-> NULL between Nimrod and database.
Diffstat (limited to 'lib/impure/db_postgres.nim')
-rw-r--r-- | lib/impure/db_postgres.nim | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index c375d9191..510cb8e45 100644 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -48,7 +48,8 @@ proc dbError*(msg: string) {.noreturn.} = e.msg = msg raise e -proc dbQuote(s: string): string = +proc dbQuote*(s: string): string = + ## DB quotes the string. result = "'" for c in items(s): if c == '\'': add(result, "''") @@ -60,7 +61,10 @@ proc dbFormat(formatstr: TSqlQuery, args: varargs[string]): string = var a = 0 for c in items(string(formatstr)): if c == '?': - add(result, dbQuote(args[a])) + if args[a] == nil: + add(result, "NULL") + else: + add(result, dbQuote(args[a])) inc(a) else: add(result, c) @@ -124,7 +128,10 @@ proc setRow(res: PPGresult, r: var TRow, line, cols: int32) = for col in 0..cols-1: setLen(r[col], 0) var x = PQgetvalue(res, line, col) - add(r[col], x) + if x == nil: + r[col] = nil + else: + add(r[col], x) iterator fastRows*(db: TDbConn, query: TSqlQuery, args: varargs[string, `$`]): TRow {.tags: [FReadDB].} = |