Support empty sets in (x IN @foo) exprs (#109)
commita67d57004255835edf3689c46ddb38e0c2a9bfc2
authormfp <mauricio.fernandez@ahrefs.com>
Tue, 22 Feb 2022 19:30:54 +0000 (22 20:30 +0100)
committerGitHub <noreply@github.com>
Tue, 22 Feb 2022 19:30:54 +0000 (22 14:30 -0500)
tree6dfa34f7a1fc0a371b4b4a22c0603a5d5a31a94f
parent5f8cf85893730ce6b0137d1ac9afa171e9ddb95c
Support empty sets in (x IN @foo) exprs (#109)

* sql: revamp IN @x support, require surrounding params + allow empty set

* sql: recover (x NOT IN @x) syntax

* xml: fix SQL for IN @x

* xml: fix collecting of set invars

* test: update tests for new (... IN @x) syntax

* gen: fix discovery of var names inside (x IN @xs) expressions

* test: + check discovery of params in LHS of (x IN @xs) expr

* sql, gen: support IN expressions in variants

SELECT * FROM foo WHERE
@ids { None { TRUE } | Some { (foo = @x AND (id IN @ids1) OR (id IN @ids2)) } };

* gen: fix left-to-right order for IN expr LHS and RHS in variants

emit correct code for

@ids2 { None { TRUE } | Some { (foo = @x AND (CONCAT(foo, @y, 'xxx') IN @set1) } }

the pattern must be
   `Some (x,y,set1)
was
   `Some (x,set1,y)

* sql: drop requirement to use parentheses around  x IN @xs

* lib: refactor Sql.var type

* sql: fix parsing of expressions like  `x` in @xs

* gen: simplify pattern in generated code when possible

* lib: drop parenthesis position tracking in parser

* gen: fix codegen for IN exprs without parentheses
lib/sql.ml
lib/sql_lexer.mll
lib/sql_parser.mly
lib/syntax.ml
src/gen.ml
src/gen_caml.ml
src/gen_xml.ml
src/test.ml
test/inargument.sql
test/out/inargument.xml