branch: elpa/emacsql commit 5f30787890441bb8cce25ad9953fa503bf14fd93 Author: Ákos Kiss <a...@coram.pub> Commit: Ákos Kiss <a...@coram.pub>
Add precedence handling for "between" syntax --- emacsql-compiler.el | 5 ++++- tests/emacsql-compiler-tests.el | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/emacsql-compiler.el b/emacsql-compiler.el index b1aae9ce63..8c9bdbc2d8 100644 --- a/emacsql-compiler.el +++ b/emacsql-compiler.el @@ -360,7 +360,10 @@ Only use within `emacsql-with-params'!" ((<= >=) (cl-case (length args) (2 (format format-string (recur 0) (recur 1))) - (3 (format "%s BETWEEN %s AND %s" + (3 (format (if (>= (or parent-precedence-value 0) + precedence-value) + "(%s BETWEEN %s AND %s)" + "%s BETWEEN %s AND %s") (recur 1) (recur (if (eq op '>=) 2 0)) (recur (if (eq op '>=) 0 2)))) diff --git a/tests/emacsql-compiler-tests.el b/tests/emacsql-compiler-tests.el index 79ec6b41e6..aad9b53fcd 100644 --- a/tests/emacsql-compiler-tests.el +++ b/tests/emacsql-compiler-tests.el @@ -242,7 +242,9 @@ ([:select (funcall length (|| (* x x) (* y y) (* z z)))] '() "SELECT length((x * x) || (y * y) || (z * z));") ([:select (and (+ (<= x y) 1) (>= y x))] '() - "SELECT (x <= y) + 1 AND y >= x;"))) + "SELECT (x <= y) + 1 AND y >= x;") + ([:select (or (& (<= x (+ y 1) (- z)) 1) (>= x z y))] '() + "SELECT (y + 1 BETWEEN x AND -z) & 1 OR z BETWEEN y AND x;"))) (provide 'emacsql-compiler-tests)