Skip to content

Commit

Permalink
if user forgets inner values, substitute with a 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasTJdev committed Dec 26, 2021
1 parent 499dc88 commit 6c970d2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sqlbuilder.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.3.0"
version = "0.3.1"
author = "ThomasTJdev"
description = "SQL builder"
license = "MIT"
Expand Down
5 changes: 4 additions & 1 deletion src/sqlbuilder.nim
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@
## # Credit
## Inspiration for builder: [Nim Forum](https://github.com/nim-lang/nimforum)

import strutils, db_common, macros
import
std/db_common,
std/macros,
std/strutils

type
ArgObj* = object ## Argument object
Expand Down
18 changes: 14 additions & 4 deletions src/sqlbuilderpkg/select.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ proc sqlSelect*(table: string, data: varargs[string], left: varargs[string], whe
acc.add("(")
else:
acc.add(" AND " & accessC & " in (")
var inVal: string
for a in split(access, ","):
acc.add(a & ",")
acc = acc[0 .. ^2]
if a == "": continue
if inVal != "":
inVal.add(",")
inVal.add(a)
acc.add(if inVal == "": "0" else: inVal)
acc.add(")")

when defined(testSqlquery):
Expand Down Expand Up @@ -73,9 +77,13 @@ proc sqlSelect*(table: string, data: varargs[string], left: varargs[string], whe
acc.add("(")
else:
acc.add(" AND " & accessC & " in (")
var inVal: string
for a in split(access, ","):
acc.add(a & ",")
acc = acc[0 .. ^2]
if a == "": continue
if inVal != "":
inVal.add(",")
inVal.add(a)
acc.add(if inVal == "": "0" else: inVal)
acc.add(")")

when defined(testSqlquery):
Expand Down Expand Up @@ -120,6 +128,8 @@ macro sqlSelectMacro*(table: string, data: varargs[string], left: varargs[string
for a in split($access, ","):
acc.add(a & ",")
acc = acc[0 .. ^2]
if acc.len() == 0:
acc.add("0")
acc.add(")")

when defined(testSqlquery):
Expand Down

0 comments on commit 6c970d2

Please sign in to comment.