annotate semiconginev2/thirdparty/db_connector/private/dbutils.nim @ 1235:c70fee6568f6

did: improv render tests to run without user input
author sam <sam@basx.dev>
date Sat, 20 Jul 2024 15:45:02 +0700
parents 56781cc0fc7c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1191
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
1 import ../db_common
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
2
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
3
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
4 template dbFormatImpl*(formatstr: SqlQuery, dbQuote: proc (s: string): string {.nimcall.}, args: varargs[string]): string =
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
5 var res = ""
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
6 var a = 0
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
7 for c in items(string(formatstr)):
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
8 if c == '?':
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
9 if a == args.len:
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
10 dbError("""The number of "?" given exceeds the number of parameters present in the query.""")
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
11 add(res, dbQuote(args[a]))
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
12 inc(a)
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
13 else:
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
14 add(res, c)
239adab121a3 sync from bedroom to office
sam <sam@basx.dev>
parents:
diff changeset
15 res