X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fsqlmaker%2Fdbihacks_internals.t;h=cd229fd5dacd795e7d34267c111af084181694c9;hb=07add744fd8b328dbc83f2a0906aaf6bd0b25674;hp=b635d6fb5f3f25117362315037750a458aaec5c1;hpb=c1f3f2e8a79c6a4081c9949fa30da09d18d64d3b;p=dbsrgits%2FDBIx-Class.git diff --git a/t/sqlmaker/dbihacks_internals.t b/t/sqlmaker/dbihacks_internals.t index b635d6f..cd229fd 100644 --- a/t/sqlmaker/dbihacks_internals.t +++ b/t/sqlmaker/dbihacks_internals.t @@ -81,11 +81,18 @@ for my $t ( }, { where => { -and => [ \'foo=bar', [ { artistid => { '=', $num } } ], { name => 'Caterwauler McCrae'} ] }, - cc_result => { '' => \'foo=bar', name => 'Caterwauler McCrae', artistid => $num }, + cc_result => { -and => [ \'foo=bar' ], name => 'Caterwauler McCrae', artistid => $num }, sql => 'WHERE foo=bar AND artistid = ? AND name = ?', efcc_result => { name => 'Caterwauler McCrae', artistid => $num }, }, { + where => { -and => [ \'foo=bar', [ { artistid => { '=', $num } } ], { name => 'Caterwauler McCrae'}, \'buzz=bozz' ] }, + cc_result => { -and => [ \'foo=bar', \'buzz=bozz' ], name => 'Caterwauler McCrae', artistid => $num }, + sql => 'WHERE foo=bar AND artistid = ? AND name = ? AND buzz=bozz', + collapsed_sql => 'WHERE foo=bar AND buzz=bozz AND artistid = ? AND name = ?', + efcc_result => { name => 'Caterwauler McCrae', artistid => $num }, + }, + { 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 = ? )', @@ -357,15 +364,82 @@ for my $t ( [ { 'me.title' => 'Spoonful of bees' } ], ]}, cc_result => { - '' => \[ + -and => [ \[ "LOWER(me.title) LIKE ?", '%spoon%', - ], + ]], 'me.title' => 'Spoonful of bees', }, sql => 'WHERE LOWER(me.title) LIKE ? AND me.title = ?', efcc_result => { 'me.title' => 'Spoonful of bees' }, - } + }, + + # crazy literals + { + where => { + -or => [ + \'foo = bar', + ], + }, + sql => 'WHERE foo = bar', + cc_result => { + -and => [ + \'foo = bar', + ], + }, + efcc_result => {}, + }, + { + where => { + -or => [ + \'foo = bar', + \'baz = ber', + ], + }, + sql => 'WHERE foo = bar OR baz = ber', + collapsed_sql => 'WHERE baz = ber OR foo = bar', + cc_result => { + -or => [ + \'baz = ber', + \'foo = bar', + ], + }, + efcc_result => {}, + }, + { + where => { + -and => [ + \'foo = bar', + \'baz = ber', + ], + }, + sql => 'WHERE foo = bar AND baz = ber', + cc_result => { + -and => [ + \'foo = bar', + \'baz = ber', + ], + }, + efcc_result => {}, + }, + { + where => { + -and => [ + \'foo = bar', + \'baz = ber', + x => { -ident => 'y' }, + ], + }, + sql => 'WHERE foo = bar AND baz = ber AND x = y', + cc_result => { + -and => [ + \'foo = bar', + \'baz = ber', + ], + x => { '=' => { -ident => 'y' } } + }, + efcc_result => { x => { -ident => 'y' } }, + }, ) { for my $w ( @@ -390,14 +464,14 @@ for my $t ( is_same_sql ( $generated_sql, $t->{sql}, "Expected SQL from $name" ) if exists $t->{sql}; - my $collapsed_cond = $schema->storage->_collapse_cond($w); - is_same_sql( - ($sm->where($collapsed_cond))[0], + ($sm->where($t->{cc_result}))[0], ( $t->{collapsed_sql} || $t->{sql} || $generated_sql ), "Collapse did not alter *the semantics* of the final SQL based on $name", ); + my $collapsed_cond = $schema->storage->_collapse_cond($w); + is_deeply( $collapsed_cond, $t->{cc_result},