From: Peter Rabbitson Date: Wed, 18 Dec 2013 10:15:20 +0000 (+0100) Subject: Test BETWEEN after the IN debacle (luckily it throws in all expected cases) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FQ-Branch.git;a=commitdiff_plain;h=7f54040f15148db4a74999fd634ec452ad3298a3 Test BETWEEN after the IN debacle (luckily it throws in all expected cases) Generalize the emitted exception text --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 2bc89eb..f325978 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -961,6 +961,8 @@ sub _where_field_BETWEEN { $placeholder = $self->_convert('?'); $op = $self->_sqlcase($op); + my $invalid_args = "Operator '$op' requires either an arrayref with two defined values or expressions, or a single literal scalarref/arrayref-ref"; + my ($clause, @bind) = $self->_SWITCH_refkind($vals, { ARRAYREFREF => sub { my ($s, @b) = @$$vals; @@ -971,8 +973,7 @@ sub _where_field_BETWEEN { return $$vals; }, ARRAYREF => sub { - puke "special op 'between' accepts an arrayref with exactly two values" - if @$vals != 2; + puke $invalid_args if @$vals != 2; my (@all_sql, @all_bind); foreach my $val (@$vals) { @@ -994,7 +995,10 @@ sub _where_field_BETWEEN { if (@rest or $func !~ /^ \- (.+)/x); local $self->{_nested_func_lhs} = $k; $self->_where_unary_op ($1 => $arg); - } + }, + FALLBACK => sub { + puke $invalid_args, + }, }); push @all_sql, $sql; push @all_bind, @bind; @@ -1006,7 +1010,7 @@ sub _where_field_BETWEEN { ); }, FALLBACK => sub { - puke "special op 'between' accepts an arrayref with two values, or a single literal scalarref/arrayref-ref"; + puke $invalid_args, }, }); diff --git a/t/05in_between.t b/t/05in_between.t index 3ca3c67..27ac22f 100644 --- a/t/05in_between.t +++ b/t/05in_between.t @@ -64,6 +64,26 @@ my @in_between_tests = ( bind => [], test => '-between with literal sql with a literal (\"\'this\' AND \'that\'")', }, + + # generate a set of invalid -between tests + ( map { { + where => { x => { -between => $_ } }, + test => 'invalid -between args', + exception => qr|Operator 'BETWEEN' requires either an arrayref with two defined values or expressions, or a single literal scalarref/arrayref-ref|, + } } ( + [ 1, 2, 3 ], + [ 1, undef, 3 ], + [ undef, 2, 3 ], + [ 1, 2, undef ], + [ 1, undef ], + [ undef, 2 ], + [ undef, undef ], + [ 1 ], + [ undef ], + [], + 1, + undef, + )), { where => { start0 => { -between => [ 1, { -upper => 2 } ] },