From 61a50d9c8c46d80fe947a5f86fb30ee8ca922976 Mon Sep 17 00:00:00 2001 From: Thomas Johnson Date: Tue, 24 Oct 2017 01:48:45 -0700 Subject: Fixes #6571 (#6578) --- lib/impure/db_postgres.nim | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'lib/impure/db_postgres.nim') diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index a42950557..b0d3170f8 100644 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -98,15 +98,18 @@ proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string = var a = 0 if args.len > 0 and not string(formatstr).contains("?"): dbError("""parameter substitution expects "?" """) - for c in items(string(formatstr)): - if c == '?': - if args[a] == nil: - add(result, "NULL") + if args.len == 0: + return string(formatstr) + else: + for c in items(string(formatstr)): + if c == '?': + if args[a] == nil: + add(result, "NULL") + else: + add(result, dbQuote(args[a])) + inc(a) else: - add(result, dbQuote(args[a])) - inc(a) - else: - add(result, c) + add(result, c) proc tryExec*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]): bool {.tags: [ReadDbEffect, WriteDbEffect].} = -- cgit 1.4.1-2-gfad0