fix: irNeg (unary minus) evaluation in query executor
- Added missing irNeg case in evalExpr (query/executor.nim) - Unary minus previously fell through to else: return 'false' - Added 2 tests: SELECT expression and WHERE condition
This commit is contained in:
@@ -651,6 +651,15 @@ proc evalExpr*(expr: IRExpr, row: Table[string, string], ctx: ExecutionContext =
|
|||||||
of irIsNotNull:
|
of irIsNotNull:
|
||||||
let v = evalExpr(expr.unExpr, row)
|
let v = evalExpr(expr.unExpr, row)
|
||||||
return if not isNull(v): "true" else: "false"
|
return if not isNull(v): "true" else: "false"
|
||||||
|
of irNeg:
|
||||||
|
let v = evalExpr(expr.unExpr, row)
|
||||||
|
try:
|
||||||
|
let f = -parseFloat(v)
|
||||||
|
let s = $f
|
||||||
|
if s.endsWith(".0"):
|
||||||
|
return s[0..^3]
|
||||||
|
return s
|
||||||
|
except: return "0"
|
||||||
else: return "false"
|
else: return "false"
|
||||||
of irekExists:
|
of irekExists:
|
||||||
if ctx != nil:
|
if ctx != nil:
|
||||||
|
|||||||
@@ -2564,6 +2564,18 @@ suite "Parameterized queries":
|
|||||||
check r.success
|
check r.success
|
||||||
check r.rows.len >= 2
|
check r.rows.len >= 2
|
||||||
|
|
||||||
|
test "Unary minus in SELECT expression":
|
||||||
|
let r = qexec.executeQuery(ctx, parse("SELECT -age AS neg_age FROM users WHERE id = 1"))
|
||||||
|
check r.success
|
||||||
|
check r.rows.len == 1
|
||||||
|
check r.rows[0]["neg_age"] == "-30"
|
||||||
|
|
||||||
|
test "Unary minus in WHERE condition":
|
||||||
|
let r = qexec.executeQuery(ctx, parse("SELECT name FROM users WHERE id = 2 AND -age = -25"))
|
||||||
|
check r.success
|
||||||
|
check r.rows.len == 1
|
||||||
|
check r.rows[0]["name"] == "Bob"
|
||||||
|
|
||||||
# JOIN tests
|
# JOIN tests
|
||||||
include "join_tests"
|
include "join_tests"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user