Merge 'trunk' into 'DBIx-Class-current'
Brandon L. Black [Tue, 22 Aug 2006 18:10:42 +0000 (18:10 +0000)]
r13301@evoc8 (orig r2696):  dyfrgi | 2006-08-21 10:33:04 -0500
Change _cond_for_update_delete to handle more complicated queries through recursing on internal hashes.
Add a test which should succeed and fails without this change.
r13302@evoc8 (orig r2697):  blblack | 2006-08-21 12:33:02 -0500
bugfix to Oracle columns_info_for
r13321@evoc8 (orig r2716):  dwc | 2006-08-22 00:05:58 -0500
use ref instead of eval to check limit syntax (to avoid issues with Devel::StackTrace)

Changes
lib/DBIx/Class/ResultSet.pm
lib/DBIx/Class/Storage/DBI.pm
lib/DBIx/Class/Storage/DBI/Oracle.pm
t/46where_attribute.t

diff --git a/Changes b/Changes
index beee9bd..d0389c1 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 Revision history for DBIx::Class
 
+        - use ref instead of eval to check limit syntax (to avoid issues with
+          Devel::StackTrace)
         - remove_columns now deletes columns from _columns
 
 0.07001 2006-08-18 19:55:00
index 7a8f44d..ec54136 100644 (file)
@@ -997,13 +997,14 @@ sub first {
 # appropriately, returning the new condition.
 
 sub _cond_for_update_delete {
-  my ($self) = @_;
+  my ($self, $full_cond) = @_;
   my $cond = {};
 
+  $full_cond ||= $self->{cond};
   # No-op. No condition, we're updating/deleting everything
-  return $cond unless ref $self->{cond};
+  return $cond unless ref $full_cond;
 
-  if (ref $self->{cond} eq 'ARRAY') {
+  if (ref $full_cond eq 'ARRAY') {
     $cond = [
       map {
         my %hash;
@@ -1012,36 +1013,33 @@ sub _cond_for_update_delete {
           $hash{$1} = $_->{$key};
         }
         \%hash;
-      } @{$self->{cond}}
+      } @{$full_cond}
     ];
   }
-  elsif (ref $self->{cond} eq 'HASH') {
-    if ((keys %{$self->{cond}})[0] eq '-and') {
+  elsif (ref $full_cond eq 'HASH') {
+    if ((keys %{$full_cond})[0] eq '-and') {
       $cond->{-and} = [];
 
-      my @cond = @{$self->{cond}{-and}};
+      my @cond = @{$full_cond->{-and}};
       for (my $i = 0; $i < @cond; $i++) {
         my $entry = $cond[$i];
 
-        my %hash;
+        my $hash;
         if (ref $entry eq 'HASH') {
-          foreach my $key (keys %{$entry}) {
-            $key =~ /([^.]+)$/;
-            $hash{$1} = $entry->{$key};
-          }
+          $hash = $self->_cond_for_update_delete($entry);
         }
         else {
           $entry =~ /([^.]+)$/;
-          $hash{$1} = $cond[++$i];
+          $hash->{$1} = $cond[++$i];
         }
 
-        push @{$cond->{-and}}, \%hash;
+        push @{$cond->{-and}}, $hash;
       }
     }
     else {
-      foreach my $key (keys %{$self->{cond}}) {
+      foreach my $key (keys %{$full_cond}) {
         $key =~ /([^.]+)$/;
-        $cond->{$1} = $self->{cond}{$key};
+        $cond->{$1} = $full_cond->{$key};
       }
     }
   }
index 8d2956b..37a083d 100644 (file)
@@ -60,7 +60,7 @@ WHERE ROW_NUM BETWEEN $offset AND $last
 #  without digging into things too deeply
 sub _find_syntax {
   my ($self, $syntax) = @_;
-  my $dbhname = eval { $syntax->{Driver}->{Name}} || '';
+  my $dbhname = ref $syntax eq 'HASH' ? $syntax->{Driver}{Name} : '';
   if(ref($self) && $dbhname && $dbhname eq 'DB2') {
     return 'RowNumberOver';
   }
index 8549b41..fa5d67f 100644 (file)
@@ -52,7 +52,7 @@ sub get_autoinc_seq {
 sub columns_info_for {
   my ($self, $table) = @_;
 
-  $self->next::method($self, uc($table));
+  $self->next::method(uc($table));
 }
 
 
index 764d7cc..e17b518 100644 (file)
@@ -7,7 +7,7 @@ use lib qw(t/lib);
 use DBICTest;\r
 my $schema = DBICTest->init_schema();\r
 \r
-plan tests => 14;\r
+plan tests => 16;\r
 \r
 # select from a class with resultset_attributes\r
 my $resultset = $schema->resultset('BooksInLibrary');\r
@@ -25,6 +25,12 @@ if ($@) { print $@ }
 ok(!$@, 'find_or_create on resultset with attribute for non-existent entry did not throw');\r
 ok(defined $see_spot, 'successfully did insert on resultset with attribute for non-existent entry');\r
 \r
+my $see_spot_rs = $owner->books->search({ title => "See Spot Run" });\r
+eval { $see_spot_rs->delete(); };\r
+if ($@) { print $@ }\r
+ok(!$@, 'delete on resultset with attribute did not throw');\r
+is($see_spot_rs->count(), 0, 'delete on resultset with attributes succeeded');\r
+\r
 # many_to_many tests\r
 my $collection = $schema->resultset('Collection')->search({collectionid => 1});\r
 my $pointy_objects = $collection->search_related('collection_object')->search_related('object', { type => "pointy"});\r