Merge 'trunk' into 'try-tiny'
Peter Rabbitson [Tue, 25 May 2010 15:40:17 +0000 (15:40 +0000)]
r9420@Thesaurus (orig r9406):  caelum | 2010-05-20 16:28:18 +0200
support INSERT OR UPDATE triggers for Oracle
r9421@Thesaurus (orig r9407):  matthewt | 2010-05-20 19:19:14 +0200
don't try and ensure_class_loaded an object. this doesn't work.
r9422@Thesaurus (orig r9408):  matthewt | 2010-05-20 19:36:01 +0200
fix result_class setter behaviour to not stuff attrs (line commented out to prevent this regression being mistakenly re-introduced)
r9423@Thesaurus (orig r9409):  matthewt | 2010-05-20 19:49:32 +0200
forgot to commit fixes
r9424@Thesaurus (orig r9410):  matthewt | 2010-05-20 20:09:52 +0200
fix find() since that was also broken in r8754
r9435@Thesaurus (orig r9421):  rabbit | 2010-05-25 11:14:29 +0200
Fix undef warning
r9436@Thesaurus (orig r9422):  rabbit | 2010-05-25 11:15:01 +0200
Rewrite test as to not propagate several ways to do the same thing

Changes
lib/DBIx/Class/ResultSet.pm
lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm
t/73oracle.t
t/85utf8.t
t/inflate/hri.t
t/lib/DBIC/DebugObj.pm
t/lib/DBICTest/AuthorCheck.pm

diff --git a/Changes b/Changes
index 120be79..e6c97fb 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for DBIx::Class
 
+        - Fix find() to use result_class set on object
+        - Fix result_class setter behaviour to not mistakenly stuff attrs.
+        - Don't try and ensure_class_loaded an object. This doesn't work.
         - Add a warning to load_namespaces if a class in ResultSet/
           is not a subclass of DBIx::Class::ResultSet
         - ::Storage::DBI now correctly preserves a parent $dbh from
index 1dc4068..ce86650 100644 (file)
@@ -538,8 +538,8 @@ sub find {
       : $self->_add_alias($input_query, $alias);
   }
 
-  # Run the query
-  my $rs = $self->search ($query, $attrs);
+  # Run the query, passing the result_class since it should propagate for find
+  my $rs = $self->search ($query, {result_class => $self->result_class, %$attrs});
   if (keys %{$rs->_resolved_attrs->{collapse}}) {
     my $row = $rs->next;
     carp "Query returned more than one row" if $rs->next;
@@ -1138,9 +1138,14 @@ in the original source class will not run.
 sub result_class {
   my ($self, $result_class) = @_;
   if ($result_class) {
-    $self->ensure_class_loaded($result_class);
+    unless (ref $result_class) { # don't fire this for an object
+      $self->ensure_class_loaded($result_class);
+    }
     $self->_result_class($result_class);
-    $self->{attrs}{result_class} = $result_class if ref $self;
+    # THIS LINE WOULD BE A BUG - this accessor specifically exists to
+    # permit the user to set result class on one result set only; it only
+    # chains if provided to search()
+    #$self->{attrs}{result_class} = $result_class if ref $self;
   }
   $self->_result_class;
 }
index 770a3fe..74c151d 100644 (file)
@@ -86,7 +86,7 @@ sub _dbh_get_autoinc_seq {
     {
       $schema ? (owner => $schema) : (),
       table_name => $table || $source_name,
-      triggering_event => 'INSERT',
+      triggering_event => { -like => '%INSERT%' },
       status => 'ENABLED',
      },
   );
index 0aa3ee7..a9ee688 100644 (file)
@@ -87,7 +87,7 @@ $dbh->do(qq{
 });
 $dbh->do(qq{
   CREATE OR REPLACE TRIGGER cd_insert_trg
-  BEFORE INSERT ON cd
+  BEFORE INSERT OR UPDATE ON cd
   FOR EACH ROW
   BEGIN
     IF :new.cdid IS NULL THEN
index a5ffbcb..13b0398 100644 (file)
@@ -5,6 +5,7 @@ use Test::More;
 use Test::Warn;
 use lib qw(t/lib);
 use DBICTest;
+use DBIC::DebugObj;
 
 {
   package A::Comp;
@@ -74,24 +75,6 @@ DBICTest::Schema::CD->load_components('UTF8Columns');
 DBICTest::Schema::CD->utf8_columns('title');
 Class::C3->reinitialize();
 
-{
-  package DBICTest::UTF8::Debugger;
-
-  use base 'DBIx::Class::Storage::Statistics';
-
-  __PACKAGE__->mk_group_accessors(simple => 'call_stack');
-
-  sub query_start {
-    my $self = shift;
-    my $sql = shift;
-
-    my @bind = map { substr $_, 1, -1 } (@_); # undo the effect of _fix_bind_params
-
-    $self->call_stack ( [ @{$self->call_stack || [] }, [$sql, @bind] ] );
-    $self->next::method ($sql, @_);
-  }
-}
-
 # as per http://search.cpan.org/dist/Test-Simple/lib/Test/More.pm#utf8
 binmode (Test::More->builder->$_, ':utf8') for qw/output failure_output todo_output/;
 
@@ -100,16 +83,22 @@ utf8::encode($bytestream_title);
 cmp_ok ($bytestream_title, 'ne', $utf8_title, 'unicode/raw differ (sanity check)');
 
 my $storage = $schema->storage;
-$storage->debugobj (DBICTest::UTF8::Debugger->new);
-$storage->debugobj->silence (1);
+my ($sql, @bind);
+my $debugobj = DBIC::DebugObj->new (\$sql, \@bind);
+my ($orig_debug, $orig_debugobj) = ($storage->debug, $storage->debugobj);
+$storage->debugobj ($debugobj);
 $storage->debug (1);
 
 my $cd = $schema->resultset('CD')->create( { artist => 1, title => $utf8_title, year => '2048' } );
 
-# bind values are always alphabetically ordered by column, thus [2]
+$storage->debugobj ($orig_debugobj);
+$storage->debug ($orig_debug);
+
+# bind values are always alphabetically ordered by column, thus [1]
+# the single quotes are an artefact of the debug-system
 TODO: {
   local $TODO = "This has been broken since rev 1191, Mar 2006";
-  is ($storage->debugobj->call_stack->[-1][2], $bytestream_title, 'INSERT: raw bytes sent to the database');
+  is ($bind[1], "'$bytestream_title'", 'INSERT: raw bytes sent to the database');
 }
 
 # this should be using the cursor directly, no inflation/processing of any sort
@@ -145,8 +134,16 @@ ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'reloaded utf8-less title' );
 $bytestream_title = $utf8_title = "something \x{219} else";
 utf8::encode($bytestream_title);
 
+
+$storage->debugobj ($debugobj);
+$storage->debug (1);
+
 $cd->update ({ title => $utf8_title });
-is ($storage->debugobj->call_stack->[-1][1], $bytestream_title, 'UPDATE: raw bytes sent to the database');
+
+$storage->debugobj ($orig_debugobj);
+$storage->debug ($orig_debug);
+
+is ($bind[0], "'$bytestream_title'", 'UPDATE: raw bytes sent to the database');
 ($raw_db_title) = $schema->resultset('CD')
                              ->search ($cd->ident_condition)
                                ->get_column('title')
index eb74da1..c3549d8 100644 (file)
@@ -9,14 +9,15 @@ my $schema = DBICTest->init_schema();
 # Under some versions of SQLite if the $rs is left hanging around it will lock
 # So we create a scope here cos I'm lazy
 {
-    my $rs = $schema->resultset('CD')->search ({}, { order_by => 'cdid' });
+    my $rs = $schema->resultset('CD')->search ({}, {
+        order_by => 'cdid',
+        # use the hashref inflator class as result class
+        result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+    });
 
     # get the defined columns
     my @dbic_cols = sort $rs->result_source->columns;
 
-    # use the hashref inflator class as result class
-    $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
-
     # fetch first record
     my $datahashref1 = $rs->first;
 
@@ -29,6 +30,16 @@ my $schema = DBICTest->init_schema();
 
     my $cd2 = $rs->search({ cdid => 1 })->single;
     is_deeply ( $cd2, $datahashref1, 'first/search+single return the same thing');
+
+    $rs->result_class('DBIx::Class::Row');
+
+    is( $rs->result_class, 'DBIx::Class::Row', 'result_class set' );
+
+    is(
+        $rs->search->result_class, 'DBIx::Class::ResultClass::HashRefInflator',
+        'result_class set using accessor does not propagate over search'
+    );
+
 }
 
 sub check_cols_of {
index 55b74c6..c43bae9 100644 (file)
@@ -41,7 +41,7 @@ sub query_start {
 
 sub query_end { }
 
-sub txn_start { }
+sub txn_begin { }
 
 sub txn_commit { }
 
index 4d0c528..4507837 100644 (file)
@@ -43,15 +43,16 @@ sub _check_author_makefile {
     push @fail_reasons, "Missing ./inc directory";
   }
 
-  if (not $mf_mtime) {
+  if(not $mf_mtime) {
     push @fail_reasons, "Missing ./Makefile";
   }
-  elsif($mf_mtime < $mf_pl_mtime) {
-    push @fail_reasons, "./Makefile.PL is newer than ./Makefile";
-  }
-
-  if ($mf_mtime < $optdeps_mtime) {
-    push @fail_reasons, "./$optdeps is newer than ./Makefile";
+  else {
+    if($mf_mtime < $mf_pl_mtime) {
+      push @fail_reasons, "./Makefile.PL is newer than ./Makefile";
+    }
+    if($mf_mtime < $optdeps_mtime) {
+      push @fail_reasons, "./$optdeps is newer than ./Makefile";
+    }
   }
 
   if (@fail_reasons) {