make between work as a binop
[scpubgit/Q-Branch.git] / lib / SQL / Abstract.pm
index 6df60d8..131126b 100644 (file)
@@ -40,6 +40,8 @@ my @BUILTIN_SPECIAL_OPS = (
   {regex => qr/^ (?: not \s )? between $/ix, handler => sub { die "NOPE" }},
   {regex => qr/^ is (?: \s+ not )?     $/ix, handler => sub { die "NOPE" }},
   {regex => qr/^ (?: not \s )? in      $/ix, handler => sub { die "NOPE" }},
+  {regex => qr/^ ident                 $/ix, handler => sub { die "NOPE" }},
+  {regex => qr/^ value                 $/ix, handler => sub { die "NOPE" }},
 );
 
 #======================================================================
@@ -170,10 +172,8 @@ sub new {
   push @{$opt{special_ops}}, @BUILTIN_SPECIAL_OPS;
 
   if ($class->isa('DBIx::Class::SQLMaker')) {
-    push @{$opt{special_ops}}, our $DBIC_Compat_Op ||= {
-      regex => qr/^(?:ident|value|(?:not\s)?in)$/i, handler => sub { die "NOPE" }
-    };
     $opt{is_dbic_sqlmaker} = 1;
+    $opt{disable_old_special_ops} = 1;
   }
 
   # unary operators
@@ -204,10 +204,12 @@ sub new {
     -bind => sub { shift; +{ @_ } },
     -in => '_expand_in',
     -not_in => '_expand_in',
-    -list => sub {
+    -tuple => sub {
       my ($self, $node, $args) = @_;
       +{ $node => [ map $self->expand_expr($_), @$args ] };
     },
+    -between => '_expand_between',
+    -not_between => '_expand_between',
   };
 
   $opt{expand_op} = {
@@ -236,7 +238,7 @@ sub new {
   }
 
   $opt{render} = {
-    (map +("-$_", "_render_$_"), qw(op func bind ident literal list)),
+    (map +("-$_", "_render_$_"), qw(op func bind ident literal tuple)),
     %{$opt{render}||{}}
   };
 
@@ -248,7 +250,7 @@ sub new {
     ),
     (not => '_render_op_not'),
     (map +($_ => '_render_op_andor'), qw(and or)),
-    ',' => sub { shift->_render_op_multop(@_, 1) },
+    ',' => '_render_op_multop',
   };
 
   return bless \%opt, $class;
@@ -737,6 +739,7 @@ sub _expand_expr_hashpair_op {
 
     if (
       (our $Expand_Depth) == 1
+      and $self->{disable_old_special_ops}
       and List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}}
     ) {
       puke "Illegal use of top-level '-$op'"
@@ -981,6 +984,8 @@ sub _expand_op_is {
 
 sub _expand_between {
   my ($self, $op, $vv, $k) = @_;
+  $op =~ s/^-//;
+  $k = shift @{$vv = [ @$vv ]} unless defined $k;
   local our $Cur_Col_Meta = $k;
   my @rhs = map $self->_expand_expr($_),
               ref($vv) eq 'ARRAY' ? @$vv : $vv;
@@ -1001,7 +1006,6 @@ sub _expand_between {
 sub _expand_in {
   my ($self, $raw, $vv, $k) = @_;
   $k = shift @{$vv = [ @$vv ]} unless defined $k;
-  local our $Cur_Col_Meta = $k;
   my $op = $self->_normalize_op($raw);
   if (my $literal = is_literal_value($vv)) {
     my ($sql, @bind) = @$literal;
@@ -1076,9 +1080,9 @@ sub _render_ident {
   return $self->_convert($self->_quote($ident));
 }
 
-sub _render_list {
-  my ($self, $list) = @_;
-  my ($sql, @bind) = $self->_render_op([ ',', @$list ]);
+sub _render_tuple {
+  my ($self, $values) = @_;
+  my ($sql, @bind) = $self->_render_op([ ',', @$values ]);
   return "($sql)", @bind;  
 }
 
@@ -1191,12 +1195,12 @@ sub _render_op_andor {
 }
 
 sub _render_op_multop {
-  my ($self, $op, $args, $strip_left) = @_;
+  my ($self, $op, $args) = @_;
   my @parts = grep length($_->[0]), map [ $self->render_aqt($_) ], @$args;
   return '' unless @parts;
   return @{$parts[0]} if @parts == 1;
   my ($final_sql) = join(
-    ($strip_left ? '' : ' ').$self->_sqlcase(join ' ', split '_', $op).' ',
+    ($op eq ',' ? '' : ' ').$self->_sqlcase(join ' ', split '_', $op).' ',
     map $_->[0], @parts
   );
   return (