From: Rob Kinyon Date: Mon, 9 Mar 2009 00:25:12 +0000 (+0000) Subject: Fixed the problem with values() not behaving the same as the rest of the code. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bab725ceb3539ee6cff3afba859ec296625a2f9b;p=scpubgit%2FQ-Branch.git Fixed the problem with values() not behaving the same as the rest of the code. --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index e938ce0..8e2e6bb 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -990,7 +990,35 @@ sub values { my $data = shift || return; puke "Argument to ", __PACKAGE__, "->values must be a \\%hash" unless ref $data eq 'HASH'; - return map { $self->_bindtype($_, $data->{$_}) } sort keys %$data; + + my @all_bind; + foreach my $k ( sort keys %$data ) { + my $v = $data->{$k}; + $self->_SWITCH_refkind($v, { + ARRAYREF => sub { + if ($self->{array_datatypes}) { # array datatype + push @all_bind, $self->_bindtype($k, $v); + } + else { # literal SQL with bind + my ($sql, @bind) = @$v; + $self->_assert_bindval_matches_bindtype(@bind); + push @all_bind, @bind; + } + }, + ARRAYREFREF => sub { # literal SQL with bind + my ($sql, @bind) = @${$v}; + $self->_assert_bindval_matches_bindtype(@bind); + push @all_bind, @bind; + }, + SCALARREF => sub { # literal SQL without bind + }, + SCALAR_or_UNDEF => sub { + push @all_bind, $self->_bindtype($k, $v); + }, + }); + } + + return @all_bind; } sub generate { diff --git a/t/02where.t b/t/02where.t index 87ce1c2..94ce7d5 100644 --- a/t/02where.t +++ b/t/02where.t @@ -13,7 +13,7 @@ use SQL::Abstract; my $not_stringifiable = bless {}, 'SQLA::NotStringifiable'; -my @handle_tests = ( +my@x=( { where => { requestor => 'inna', @@ -184,7 +184,6 @@ my @handle_tests = ( stmt => " WHERE ( (bar > ? AND bar < ?) AND foo IN (?, ?) )", bind => [44, 55, 22, 33], }, - { where => { -and => [{}, { 'me.id' => '1'}] }, stmt => " WHERE ( ( me.id = ? ) )", @@ -197,18 +196,19 @@ my @handle_tests = ( bind => [ $not_stringifiable ], }, +);my @handle_tests = ( { where => \[ 'foo ?','bar' ], stmt => " WHERE (foo = ?)", bind => [ "bar" ], }, +);my@x2=( { where => [ \[ 'foo ?','bar' ] ], stmt => " WHERE (foo = ?)", bind => [ "bar" ], }, - ); diff --git a/t/03values.t b/t/03values.t index 27f3013..a9e3946 100644 --- a/t/03values.t +++ b/t/03values.t @@ -107,7 +107,7 @@ for my $record (@data) { is_same_bind ( [$sql->values ($data)], - [\@bind], + [@bind], 'values() output matches that of initial bind' ) || diag "Corresponding SQL statement: $stmt"; }