From f59ac26b85302808f135aab5309c7683c4b8f405 Mon Sep 17 00:00:00 2001 From: Milos Negovanovic Date: Fri, 26 Sep 2014 11:23:13 +0100 Subject: Tweaks for postgres driver (not tested yet). --- lib/impure/db_postgres.nim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/impure/db_postgres.nim') diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index c375d9191..67e769ed2 100644 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -60,7 +60,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 +127,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].} = -- cgit 1.4.1-2-gfad0 From 2a203e5340654936e3bbe1c0ac392221d15c9aeb Mon Sep 17 00:00:00 2001 From: Milos Negovanovic Date: Tue, 21 Oct 2014 15:56:00 +0100 Subject: Add comment. --- lib/impure/db_postgres.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/impure/db_postgres.nim') diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index 67e769ed2..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, "''") -- cgit 1.4.1-2-gfad0