1010# #
1111
1212import
13- std/ logging,
1413 std/ typetraits
1514
15+ when defined (waterparkPostgres):
16+ import waterpark/ postgres
17+ elif defined (waterparkSqlite):
18+ import waterpark/ sqlite
19+
1620when NimMajor >= 2 :
17- import
18- db_connector/ db_common
21+ when defined (test):
22+ import db_connector/ db_sqlite
23+ else :
24+ import db_connector/ db_postgres
1925else :
20- import
21- std/ db_postgres
26+ when defined (test):
27+ import std/ db_sqlite
28+ else :
29+ import std/ db_postgres
30+
31+
32+
2233
34+ when defined (waterparkPostgres) or defined (waterparkSqlite):
35+ discard
36+
37+
38+
39+ else :
2340
41+ proc getValueTry * (db: DbConn , query: SqlQuery , args: varargs [string , `$`]): string =
42+ try :
43+ result = getValue (db, query, args)
44+ except :
45+ echo (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
2446
25- proc getValueTry * (db: DbConn , query: SqlQuery , args: varargs [string , `$`]): string =
26- try :
27- result = getValue (db, query, args)
28- except :
29- error (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
3047
3148
3249
50+ proc getAllRowsTry * (db: DbConn , query: SqlQuery , args: varargs [string , `$`]): seq [Row ] =
51+ try :
52+ result = getAllRows (db, query, args)
53+ except :
54+ echo (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
3355
34- proc getAllRowsTry * (db: DbConn , query: SqlQuery , args: varargs [string , `$`]): seq [Row ] =
35- try :
36- result = getAllRows (db, query, args)
37- except :
38- error (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
3956
4057
4158
59+ proc getRowTry * (db: DbConn , query: SqlQuery , args: varargs [string , `$`], fillIfNull = 0 ): Row =
60+ try :
61+ result = getRow (db, query, args)
62+ except :
63+ echo (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
4264
43- proc getRowTry * (db: DbConn , query: SqlQuery , args: varargs [ string , `$`]): Row =
44- try :
45- result = getRow (db, query, args)
46- except :
47- error ( distinctBase (query). subStr ( 0 , 200 ) & " \n " & getCurrentExceptionMsg () )
65+ # If the fillIfNull is set, we will fill the result with empty strings in case
66+ # the result count does not match the fillIfNull value
67+ if fillIfNull != 0 and result . len () != fillIfNull:
68+ for i in 0 .. fillIfNull - 1 :
69+ result . add ( " " )
4870
4971
5072
5173
52- iterator fastRowsTry * (db: DbConn , query: SqlQuery , args: varargs [string , `$`]): Row =
53- try :
54- for i in fastRows (db, query, args):
55- yield i
56- except :
57- error (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
74+ iterator fastRowsTry * (db: DbConn , query: SqlQuery , args: varargs [string , `$`]): Row =
75+ try :
76+ for i in fastRows (db, query, args):
77+ yield i
78+ except :
79+ echo (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
5880
5981
6082
6183
62- proc tryExecTry * (db: DbConn , query: SqlQuery ; args: varargs [string , `$`]): bool =
63- try :
64- result = tryExec (db, query, args)
65- except :
66- error (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
84+ proc tryExecTry * (db: DbConn , query: SqlQuery ; args: varargs [string , `$`]): bool =
85+ try :
86+ result = tryExec (db, query, args)
87+ except :
88+ echo (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
6789
6890
6991
7092
71- proc execTry * (db: DbConn , query: SqlQuery ; args: varargs [string , `$`]) =
72- try :
73- exec (db, query, args)
74- except :
75- error (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
93+ proc execTry * (db: DbConn , query: SqlQuery ; args: varargs [string , `$`]) =
94+ try :
95+ exec (db, query, args)
96+ except :
97+ echo (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
7698
7799
78100
79101
80- proc execAffectedRowsTry * (db: DbConn , query: SqlQuery ; args: varargs [string , `$`]): int64 =
81- try :
82- result = execAffectedRows (db, query, args)
83- except :
84- error (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
85- return - 1
102+ proc execAffectedRowsTry * (db: DbConn , query: SqlQuery ; args: varargs [string , `$`]): int64 =
103+ try :
104+ result = execAffectedRows (db, query, args)
105+ except :
106+ echo (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
107+ return - 1
86108
87109
88110
89- proc tryInsertIDTry * (db: DbConn , query: SqlQuery ; args: varargs [string , `$`]): int64 =
90- try :
91- result = tryInsertID (db, query, args)
92- except :
93- error (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
94- return - 1
111+ proc tryInsertIDTry * (db: DbConn , query: SqlQuery ; args: varargs [string , `$`]): int64 =
112+ try :
113+ result = tryInsertID (db, query, args)
114+ except :
115+ echo (distinctBase (query).subStr (0 , 200 ) & " \n " & getCurrentExceptionMsg ())
116+ return - 1
0 commit comments