From 769869c69970203c7ac715a2d8863f3fdcd04889 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 29 Sep 2022 18:16:42 +0800 Subject: [PATCH] refactor dbFormat (#19746) * refactor dbFormat * add simple tests --- src/db_odbc.nim | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/db_odbc.nim b/src/db_odbc.nim index da1b1e9b59c73..756957acb4d1e 100644 --- a/src/db_odbc.nim +++ b/src/db_odbc.nim @@ -92,7 +92,7 @@ import strutils, odbcsql import db_common export db_common -import std/private/since +import std/private/[since, dbutils] type OdbcConnTyp = tuple[hDb: SqlHDBC, env: SqlHEnv, stmt: SqlHStmt] @@ -197,14 +197,7 @@ proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string {. noSideEffect.} = ## Replace any `?` placeholders with `args`, ## and quotes the arguments - result = "" - var a = 0 - for c in items(string(formatstr)): - if c == '?': - add(result, dbQuote(args[a])) - inc(a) - else: - add(result, c) + dbFormatImpl(formatstr, dbQuote, args) proc prepareFetch(db: var DbConn, query: SqlQuery, args: varargs[string, `$`]): TSqlSmallInt {.