Revision history for SQL::Abstract
+ - make sure that sql generation does not mutate the supplied
+ where condition structure
+
revision 1.54 2009-05-07 17:23 (UTC)
----------------------------
- allow special_operators to take both code refs and method names
sub _where_field_op_ARRAYREF {
my ($self, $k, $op, $vals) = @_;
- if(@$vals) {
- $self->_debug("ARRAY($vals) means multiple elements: [ @$vals ]");
+ my @vals = @$vals; #always work on a copy
+
+ if(@vals) {
+ $self->_debug("ARRAY($vals) means multiple elements: [ @vals ]");
# see if the first element is an -and/-or op
my $logic;
- if ($vals->[0] =~ /^ - ( AND|OR ) $/ix) {
+ if ($vals[0] =~ /^ - ( AND|OR ) $/ix) {
$logic = uc $1;
- shift @$vals;
+ shift @vals;
}
- # distribute $op over each remaining member of @$vals, append logic if exists
- return $self->_recurse_where([map { {$k => {$op, $_}} } @$vals], $logic);
+ # distribute $op over each remaining member of @vals, append logic if exists
+ return $self->_recurse_where([map { {$k => {$op, $_}} } @vals], $logic);
# LDNOTE : had planned to change the distribution logic when
# $op =~ $self->{inequality_op}, because of Morgan laws :
# WHERE field != 22 AND field != 33.
# To do this, replace the above to roughly :
# my $logic = ($op =~ $self->{inequality_op}) ? 'AND' : 'OR';
- # return $self->_recurse_where([map { {$k => {$op, $_}} } @$vals], $logic);
+ # return $self->_recurse_where([map { {$k => {$op, $_}} } @vals], $logic);
}
else {
use Data::Dumper;
use SQL::Abstract;
+use Clone;
=begin
Test -and -or and -nest modifiers, assuming the following:
},
);
-plan tests => @and_or_tests*3 + @numbered_mods*4 + @nest_tests*2;
+plan tests => @and_or_tests*4 + @numbered_mods*4 + @nest_tests*2;
for my $case (@and_or_tests) {
TODO: {
my @w;
local $SIG{__WARN__} = sub { push @w, @_ };
+
my $sql = SQL::Abstract->new ($case->{args} || {});
+ my $where_copy = Clone::clone ($case->{where});
+
lives_ok (sub {
my ($stmt, @bind) = $sql->where($case->{where});
is_same_sql_bind(
});
is (@w, 0, 'No warnings within and-or tests')
|| diag join "\n", 'Emitted warnings:', @w;
+
+ is_deeply ($case->{where}, $where_copy, 'Where conditions unchanged');
}
}