X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F41orrible.t;h=b0117a77d29c4276ed1ed30c389040cb51b322a7;hb=81d1c592ce6632d0f21a2077337ce5f08ed05bc9;hp=bd391da5e1706528b29d5d97756f86b6ce471668;hpb=f66596f958ad37be9be25133fc8d28fbcea272f8;p=dbsrgits%2FDBIx-Class.git diff --git a/t/41orrible.t b/t/41orrible.t index bd391da..b0117a7 100644 --- a/t/41orrible.t +++ b/t/41orrible.t @@ -2,24 +2,88 @@ use strict; use warnings; use Test::More; -use DBIx::Class::Storage::DBI; +use DBIx::Class::SQLAHacks::OracleJoins; -plan tests => 1; +use lib qw(t/lib); +use DBICTest; # do not remove even though it is not used +use DBIC::SqlMakerTest; -my $sa = new DBIC::SQL::Abstract; +plan tests => 4; + +my $sa = new DBIx::Class::SQLAHacks::OracleJoins; $sa->limit_dialect('RowNum'); is($sa->select('rubbish', - [ 'foo.id', 'bar.id' ], + [ 'foo.id', 'bar.id', \'TO_CHAR(foo.womble, "blah")' ], undef, undef, 1, 3), 'SELECT * FROM ( SELECT A.*, ROWNUM r FROM ( - SELECT foo.id AS col1, bar.id AS col2 FROM rubbish + SELECT foo.id AS col1, bar.id AS col2, TO_CHAR(foo.womble, "blah") AS col3 FROM rubbish ) A WHERE ROWNUM < 5 ) B WHERE r >= 4 ', 'Munged stuff to make Oracle not explode'); + +# test WhereJoins +# search with undefined or empty $cond + +# my ($self, $table, $fields, $where, $order, @rest) = @_; +my ($sql, @bind) = $sa->select( + [ + { me => "cd" }, + [ + { "-join_type" => "LEFT", artist => "artist" }, + { "artist.artistid" => "me.artist" }, + ], + ], + [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ], + undef, + undef +); +is_same_sql_bind( + $sql, \@bind, + 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( artist.artistid(+) = me.artist )', [], + 'WhereJoins search with empty where clause' +); + +($sql, @bind) = $sa->select( + [ + { me => "cd" }, + [ + { "-join_type" => "", artist => "artist" }, + { "artist.artistid" => "me.artist" }, + ], + ], + [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ], + { 'artist.artistid' => 3 }, + undef +); +is_same_sql_bind( + $sql, \@bind, + 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( ( ( artist.artistid = me.artist ) AND ( artist.artistid = ? ) ) )', [3], + 'WhereJoins search with where clause' +); + +($sql, @bind) = $sa->select( + [ + { me => "cd" }, + [ + { "-join_type" => "LEFT", artist => "artist" }, + { "artist.artistid" => "me.artist" }, + ], + ], + [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ], + [{ 'artist.artistid' => 3 }, { 'me.cdid' => 5 }], + undef +); +is_same_sql_bind( + $sql, \@bind, + 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( ( ( artist.artistid(+) = me.artist ) AND ( ( ( artist.artistid = ? ) OR ( me.cdid = ? ) ) ) ) )', [3, 5], + 'WhereJoins search with or in where clause' +); + +