[Bast-commits] r3341 - in branches/DBIx-Class-current:
lib/DBIx/Class/Storage/DBI/Oracle t
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Mon May 21 15:22:53 GMT 2007
Author: matthewt
Date: 2007-05-21 15:22:52 +0100 (Mon, 21 May 2007)
New Revision: 3341
Modified:
branches/DBIx-Class-current/lib/DBIx/Class/Storage/DBI/Oracle/WhereJoins.pm
branches/DBIx-Class-current/t/41orrible.t
Log:
fixed WhereJoins to handle conditions edge cases
Modified: branches/DBIx-Class-current/lib/DBIx/Class/Storage/DBI/Oracle/WhereJoins.pm
===================================================================
--- branches/DBIx-Class-current/lib/DBIx/Class/Storage/DBI/Oracle/WhereJoins.pm 2007-05-20 00:10:20 UTC (rev 3340)
+++ branches/DBIx-Class-current/lib/DBIx/Class/Storage/DBI/Oracle/WhereJoins.pm 2007-05-21 14:22:52 UTC (rev 3341)
@@ -13,7 +13,9 @@
sub select {
my ($self, $table, $fields, $where, $order, @rest) = @_;
- $self->_oracle_joins($where, @{ $table });
+ if (ref($table) eq 'ARRAY') {
+ $where = $self->_oracle_joins($where, @{ $table });
+ }
return $self->SUPER::select($table, $fields, $where, $order, @rest);
}
@@ -39,12 +41,29 @@
sub _oracle_joins {
my ($self, $where, $from, @join) = @_;
+ my $join_where = {};
+ $self->_recurse_oracle_joins($join_where, $from, @join);
+ if (keys %$join_where) {
+ if (!defined($where)) {
+ $where = $join_where;
+ } else {
+ if (ref($where) eq 'ARRAY') {
+ $where = { -or => $where };
+ }
+ $where = { -and => [ $join_where, $where ] };
+ }
+ }
+ return $where;
+ }
+ sub _recurse_oracle_joins {
+ my ($self, $where, $from, @join) = @_;
+
foreach my $j (@join) {
my ($to, $on) = @{ $j };
if (ref $to eq 'ARRAY') {
- $self->_oracle_joins($where, @{ $to });
+ $self->_recurse_oracle_joins($where, @{ $to });
}
my $to_jt = ref $to eq 'ARRAY' ? $to->[0] : $to;
@@ -66,7 +85,7 @@
}
foreach my $lhs (keys %{ $on }) {
- $where->{$lhs . $left_join} = \" = $on->{ $lhs }$right_join";
+ $where->{$lhs . $left_join} = \"= $on->{ $lhs }$right_join";
}
}
}
Modified: branches/DBIx-Class-current/t/41orrible.t
===================================================================
--- branches/DBIx-Class-current/t/41orrible.t 2007-05-20 00:10:20 UTC (rev 3340)
+++ branches/DBIx-Class-current/t/41orrible.t 2007-05-21 14:22:52 UTC (rev 3341)
@@ -2,11 +2,12 @@
use warnings;
use Test::More;
-use DBIx::Class::Storage::DBI;
+#use DBIx::Class::Storage::DBI;
+use DBIx::Class::Storage::DBI::Oracle::WhereJoins;
-plan tests => 1;
+plan tests => 4;
-my $sa = new DBIC::SQL::Abstract;
+my $sa = new DBIC::SQL::Abstract::Oracle;
$sa->limit_dialect('RowNum');
@@ -23,3 +24,45 @@
) 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) = @_;
+is($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),
+ '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');
+
+is($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),
+ '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 = ? ) ) )', 'WhereJoins search with where clause');
+
+is($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),
+ '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 = ? ) ) ) ) )', 'WhereJoins search with or in where clause');
+
+
More information about the Bast-commits
mailing list