@@ -156,27 +156,42 @@ proc sqlSelectConstWhere(where: varargs[string], usePrepared: NimNode): string =
156
156
wes.add(" ? " & v)
157
157
158
158
# => x = y
159
- elif v.len() >= 5 and v.contains(" = " ):
160
- let eSplit = v.split(" = " )
161
- # Value included already
162
- if eSplit.len() == 2 and eSplit[0 ].strip().len() > 0 and eSplit[1 ].strip().len() > 0 :
163
- if boolVal(usePrepared):
164
- wes.add(v)
165
- else :
166
- wes.add(v)
167
- # If there's multiple elements
168
- elif eSplit.len() > 2 and eSplit[eSplit.high].len() > 1 :
169
- if boolVal(usePrepared):
170
- wes.add(v)
171
- else :
172
- wes.add(v)
173
- # Insert ?
174
- else :
175
- if boolVal(usePrepared):
176
- prepareCount += 1
177
- wes.add(v & " $" & $ prepareCount)
159
+ elif v.len() >= 5 and (
160
+ v.contains(" = " ) or
161
+ v.contains(" != " ) or
162
+ v.contains(" >= " ) or
163
+ v.contains(" <= " ) or
164
+ v.contains(" <> " ) or
165
+ v.contains(" > " ) or
166
+ v.contains(" < " )
167
+ ):
168
+ const whereTypes = [" = " , " != " , " >= " , " <= " , " > " , " < " ]
169
+ for wt in whereTypes:
170
+ if wt notin v:
171
+ continue
172
+
173
+ let eSplit = v.split(wt) # " = ")
174
+ # Value included already
175
+ if eSplit.len() == 2 and eSplit[0 ].strip().len() > 0 and eSplit[1 ].strip().len() > 0 :
176
+ if boolVal(usePrepared):
177
+ wes.add(v)
178
+ else :
179
+ wes.add(v)
180
+ # If there's multiple elements
181
+ elif eSplit.len() > 2 and eSplit[eSplit.high].len() > 1 :
182
+ if boolVal(usePrepared):
183
+ wes.add(v)
184
+ else :
185
+ wes.add(v)
186
+ # Insert ?
178
187
else :
179
- wes.add(v & " ?" )
188
+ if boolVal(usePrepared):
189
+ prepareCount += 1
190
+ wes.add(v & " $" & $ prepareCount)
191
+ else :
192
+ wes.add(v & " ?" )
193
+
194
+ break
180
195
181
196
# => ... = ?
182
197
else :
@@ -641,27 +656,42 @@ proc sqlSelect*(
641
656
# !! Waring = pfl.action IN (2,3,4) <== not supported
642
657
643
658
# => x = y
644
- elif d.len() >= 5 and d.contains(" = " ):
645
- let eSplit = d.split(" = " )
646
- # Value included already
647
- if eSplit.len() == 2 and eSplit[0 ].strip().len() > 0 and eSplit[1 ].strip().len() > 0 :
648
- if usePrepared:
649
- wes.add(d)
650
- else :
651
- wes.add(d)
652
- # If there's multiple elements
653
- elif eSplit.len() > 2 and eSplit[eSplit.high].len() > 1 :
654
- if usePrepared:
655
- wes.add(d)
656
- else :
657
- wes.add(d)
658
- # Insert ?
659
- else :
660
- if usePrepared:
661
- prepareCount += 1
662
- wes.add(d & " $" & $ prepareCount)
659
+ elif d.len() >= 5 and (
660
+ d.contains(" = " ) or
661
+ d.contains(" != " ) or
662
+ d.contains(" >= " ) or
663
+ d.contains(" <= " ) or
664
+ d.contains(" <> " ) or
665
+ d.contains(" > " ) or
666
+ d.contains(" < " )
667
+ ): # d.contains(" = "):
668
+ const whereTypes = [" = " , " != " , " >= " , " <= " , " > " , " < " ]
669
+ for wt in whereTypes:
670
+ if wt notin d:
671
+ continue
672
+
673
+ let eSplit = d.split(wt)
674
+ # Value included already
675
+ if eSplit.len() == 2 and eSplit[0 ].strip().len() > 0 and eSplit[1 ].strip().len() > 0 :
676
+ if usePrepared:
677
+ wes.add(d)
678
+ else :
679
+ wes.add(d)
680
+ # If there's multiple elements
681
+ elif eSplit.len() > 2 and eSplit[eSplit.high].len() > 1 :
682
+ if usePrepared:
683
+ wes.add(d)
684
+ else :
685
+ wes.add(d)
686
+ # Insert ?
663
687
else :
664
- wes.add(d & " ?" )
688
+ if usePrepared:
689
+ prepareCount += 1
690
+ wes.add(d & " $" & $ prepareCount)
691
+ else :
692
+ wes.add(d & " ?" )
693
+
694
+ break
665
695
666
696
# => ... = ?
667
697
else :
0 commit comments