From: Peter Rabbitson Date: Wed, 4 Jun 2014 00:17:20 +0000 (+0200) Subject: Fix incorrect handling of stringifiable objects in cond collapser X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7638636bdb0c040452faa52d290ea65979f321d2;p=dbsrgits%2FDBIx-Class-Historic.git Fix incorrect handling of stringifiable objects in cond collapser Thinko introduced in the recent 8d005ad9 --- diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index 7a3587d..3164e5a 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -1207,9 +1207,17 @@ sub _extract_fixed_condition_columns { if ( ! length ref $v or - (ref $v eq 'HASH' and keys %$v == 1 and defined $v->{'='} and ( - is_literal_value($v->{'='}) or is_plain_value( $v->{'='}) - )) + is_plain_value ($v) + or + ( + ref $v eq 'HASH' + and + keys %$v == 1 + and + ref $v->{'='} + and + is_literal_value($v->{'='}) + ) ) { $res->{$c} = 1; } diff --git a/t/sqlmaker/dbihacks_internals.t b/t/sqlmaker/dbihacks_internals.t index de5e49e..81deb89 100644 --- a/t/sqlmaker/dbihacks_internals.t +++ b/t/sqlmaker/dbihacks_internals.t @@ -11,6 +11,20 @@ use Data::Dumper; my $schema = DBICTest->init_schema( no_deploy => 1); my $sm = $schema->storage->sql_maker; +{ + package # hideee + DBICTest::SillyInt; + + use overload + fallback => 1, + '0+' => sub { ${$_[0]} }, + ; +} +my $num = bless( \do { my $foo = 69 }, 'DBICTest::SillyInt' ); + +is($num, 69, 'test overloaded object is "sane"'); +is("$num", 69, 'test overloaded object is "sane"'); + for my $t ( { where => { artistid => 1, charfield => undef }, @@ -49,14 +63,14 @@ for my $t ( efcc_result => [], }, { - where => { -and => [ \'foo=bar', [ { artistid => { '=', 3 } } ], { name => 'Caterwauler McCrae'} ] }, - cc_result => { '' => \'foo=bar', name => 'Caterwauler McCrae', artistid => 3 }, + where => { -and => [ \'foo=bar', [ { artistid => { '=', $num } } ], { name => 'Caterwauler McCrae'} ] }, + cc_result => { '' => \'foo=bar', name => 'Caterwauler McCrae', artistid => $num }, sql => 'WHERE foo=bar AND artistid = ? AND name = ?', efcc_result => [qw( artistid name )], }, { - where => { artistid => [ 1 ], rank => [ 13, 2, 3 ], charfield => [ undef ] }, - cc_result => { artistid => 1, charfield => undef, rank => [13, 2, 3] }, + where => { artistid => [ $num ], rank => [ 13, 2, 3 ], charfield => [ undef ] }, + cc_result => { artistid => $num, charfield => undef, rank => [13, 2, 3] }, sql => 'WHERE artistid = ? AND charfield IS NULL AND ( rank = ? OR rank = ? OR rank = ? )', efcc_result => [qw( artistid )], }, @@ -67,8 +81,8 @@ for my $t ( efcc_result => [qw( artistid )], }, { - where => { artistid => { '=' => [ 1 ], }, charfield => { '=' => [-and => \'1', \['?',2] ] }, rank => { '=' => [ 1, 2 ] } }, - cc_result => { artistid => 1, charfield => [-and => { '=' => \'1' }, { '=' => \['?',2] } ], rank => { '=' => [1, 2] } }, + where => { artistid => { '=' => [ 1 ], }, charfield => { '=' => [-and => \'1', \['?',2] ] }, rank => { '=' => [ $num, $num ] } }, + cc_result => { artistid => 1, charfield => [-and => { '=' => \'1' }, { '=' => \['?',2] } ], rank => { '=' => [$num, $num] } }, sql => 'WHERE artistid = ? AND charfield = 1 AND charfield = ? AND ( rank = ? OR rank = ? )', efcc_result => [qw( artistid charfield )], },