X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract%2FReference.pm;h=343f60a93824b4db4f9f33a6e9dd0d5007fac778;hb=9b49ddc3237d4efe1948503b1a90b869a0c51d4a;hp=ff020b3276c0a02b6057b1eb3660fbd67e1909e8;hpb=dee79057e5d03dd6c0715d577eb22b7a057ef146;p=scpubgit%2FQ-Branch.git diff --git a/lib/SQL/Abstract/Reference.pm b/lib/SQL/Abstract/Reference.pm index ff020b3..343f60a 100644 --- a/lib/SQL/Abstract/Reference.pm +++ b/lib/SQL/Abstract/Reference.pm @@ -790,7 +790,7 @@ literal expr: ( size BETWEEN 3 AND 7 ) [] -C is also expanded: +not_between is also expanded: # expr { size => { -not_between => [ 3, 7 ] } } @@ -805,4 +805,82 @@ C is also expanded: ( size NOT BETWEEN ? AND ? ) [ 3, 7 ] +=head2 in op + +The RHS of in/not_in is either an expr/value or an arrayref of +exprs/values: + + # expr + { foo => { -in => [ 1, 2 ] } } + + # aqt + { -op => [ + 'in', { -ident => [ 'foo' ] }, { -bind => [ 'foo', 1 ] }, + { -bind => [ 'foo', 2 ] }, + ] } + + # query + foo IN ( ?, ? ) + [ 1, 2 ] + + # expr + { bar => { -not_in => \"(1, 2)" } } + + # aqt + { -op => + [ 'not_in', { -ident => [ 'bar' ] }, { -literal => [ '1, 2' ] } ] + } + + # query + bar NOT IN ( 1, 2 ) + [] + +A non-trivial LHS is expanded with ident as the default rather than value: + + # expr + { -in => [ + { -row => [ 'x', 'y' ] }, { -row => [ 1, 2 ] }, + { -row => [ 3, 4 ] }, + ] } + + # aqt + { -op => [ + 'in', { -row => [ { -ident => [ 'x' ] }, { -ident => [ 'y' ] } ] }, + { -row => [ { -bind => [ undef, 1 ] }, { -bind => [ undef, 2 ] } ] }, + { -row => [ { -bind => [ undef, 3 ] }, { -bind => [ undef, 4 ] } ] }, + ] } + + # query + (x, y) IN ( (?, ?), (?, ?) ) + [ 1, 2, 3, 4 ] + +=head2 and/or ops + +expands the same way as a plain arrayref/hashref expression but with the +logic type set to the op name. + +=head2 is op + +Expands is and is_not to null checks, RHS value must be undef: + + # expr + { -is => [ 'foo', undef ] } + + # aqt + { -op => [ 'is_null', { -ident => [ 'foo' ] } ] } + + # query + foo IS NULL + [] + + # expr + { bar => { -is_not => undef } } + + # aqt + { -op => [ 'is_not_null', { -ident => [ 'bar' ] } ] } + + # query + bar IS NOT NULL + [] + =cut