1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
8 use DBIx::Class::_Util 'dump_value';
9 use DBICTest ':DiffSQL';
10 use SQL::Abstract qw(is_plain_value is_literal_value);
11 use List::Util 'shuffle';
12 $Data::Dumper::Indent = 0;
14 my $schema = DBICTest->init_schema();
17 { cond => undef, sql => 'IS NULL' },
18 { cond => { -value => undef }, sql => 'IS NULL' },
19 { cond => \'foo', sql => '= foo' },
20 { cond => 'foo', sql => '= ?', bind => [
21 [ { dbic_colname => "title", sqlt_datatype => "varchar", sqlt_size => 100 } => 'foo' ],
22 [ { dbic_colname => "year", sqlt_datatype => "varchar", sqlt_size => 100 } => 'foo' ],
24 { cond => { -value => 'foo' }, sql => '= ?', bind => [
25 [ { dbic_colname => "title", sqlt_datatype => "varchar", sqlt_size => 100 } => 'foo' ],
26 [ { dbic_colname => "year", sqlt_datatype => "varchar", sqlt_size => 100 } => 'foo' ],
28 { cond => \[ '?', "foo" ], sql => '= ?', bind => [
33 my $rs = $schema->resultset('CD')->search({}, { columns => 'title' });
35 my $bare_cond = is_literal_value($c->{cond}) ? { '=', $c->{cond} } : $c->{cond};
38 # these are monkey-wrenches, always there
39 { title => { '!=', [ -and => \'bar' ] }, year => { '!=', [ -and => 'bar' ] } },
40 { -or => [ genreid => undef, genreid => { '!=' => \42 } ] },
41 { -or => [ genreid => undef, genreid => { '!=' => \42 } ] },
43 { title => $bare_cond, year => { '=', $c->{cond} } },
44 { -and => [ year => $bare_cond, { title => { '=', $c->{cond} } } ] },
45 [ year => $bare_cond ],
46 [ title => $bare_cond ],
47 { -and => [ { year => { '=', $c->{cond} } }, { title => { '=', $c->{cond} } } ] },
48 { -and => { -or => { year => { '=', $c->{cond} } } }, -or => { title => $bare_cond } },
51 if (my $v = is_plain_value($c->{cond})) {
55 { -and => [ year => $$v, title => $$v ] },
59 @query_steps = shuffle @query_steps;
61 $rs = $rs->search($_) for @query_steps;
63 my @bind = @{$c->{bind} || []};
66 splice @bind, 1, 0, [ { dbic_colname => "year", sqlt_datatype => "varchar", sqlt_size => 100 } => 'bar' ];
75 ( genreid != 42 OR genreid IS NULL )
77 ( genreid != 42 OR genreid IS NULL )
88 'Double condition correctly collapsed for steps' . dump_value \@query_steps,