Merge 'trunk' into 'sybase'
Rafael Kitover [Sat, 1 Aug 2009 16:35:34 +0000 (16:35 +0000)]
r6394@hlagh (orig r7145):  robkinyon | 2009-07-30 10:13:21 -0400
Added prefetch caveats
r6395@hlagh (orig r7146):  robkinyon | 2009-07-30 10:20:02 -0400
Fixed caveats
r6398@hlagh (orig r7149):  caelum | 2009-07-30 11:56:01 -0400
make ::Oracle::Generic load without DBD::Oracle
r6399@hlagh (orig r7150):  caelum | 2009-07-30 12:04:47 -0400
make sure DBD::Oracle is loaded when using constants from it
r6404@hlagh (orig r7154):  castaway | 2009-07-30 16:17:33 -0400
Mangled Rob's example somewhat, still needs explaining whch circs exactly cause the borken results

r6405@hlagh (orig r7158):  mo | 2009-07-31 06:51:20 -0400
POD fix
r6406@hlagh (orig r7159):  mo | 2009-07-31 06:52:42 -0400
undo that attributes merge stuff

lib/DBIx/Class/ResultSet.pm
lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm

index 73b0920..43b0d3e 100644 (file)
@@ -3384,6 +3384,42 @@ with that artist is given below (assuming many-to-many from artists to tags):
 B<NOTE:> If you specify a C<prefetch> attribute, the C<join> and C<select>
 attributes will be ignored.
 
+B<CAVEATs>: Prefetch does a lot of deep magic. As such, it may not behave
+exactly as you might expect.
+
+=over 4
+
+=item * 
+
+Prefetch uses the L</cache> to populate the prefetched relationships. This
+may or may not be what you want.
+
+=item * 
+
+If you specify a condition on a prefetched relationship, ONLY those
+rows that match the prefetched condition will be fetched into that relationship.
+This means that adding prefetch to a search() B<may alter> what is returned by
+traversing a relationship. So, if you have C<< Artist->has_many(CDs) >> and you do
+
+  my $artist_rs = $schema->resultset('Artist')->search({
+      'cds.year' => 2008,
+  }, {
+      join => 'cds',
+  });
+
+  my $count = $artist_rs->first->cds->count;
+
+  my $artist_rs_prefetch = $artist_rs->search( {}, { prefetch => 'cds' } );
+
+  my $prefetch_count = $artist_rs_prefetch->first->cds->count;
+
+  cmp_ok( $count, '==', $prefetch_count, "Counts should be the same" );
+
+that cmp_ok() may or may not pass depending on the datasets involved. This
+behavior may or may not survive the 0.09 transition.
+
+=back
+
 =head2 page
 
 =over 4
index 925d7f9..f99793e 100644 (file)
@@ -26,9 +26,6 @@ This class implements autoincrements for Oracle.
 use base qw/DBIx::Class::Storage::DBI/;
 use mro 'c3';
 
-# For ORA_BLOB => 113, ORA_CLOB => 112
-use DBD::Oracle qw( :ora_types );
-
 sub _dbh_last_insert_id {
   my ($self, $dbh, $source, @columns) = @_;
   my @ids = ();
@@ -228,6 +225,7 @@ table with more than one LOB column.
 
 sub source_bind_attributes 
 {
+       require DBD::Oracle;
        my $self = shift;
        my($source) = @_;
 
@@ -240,8 +238,9 @@ sub source_bind_attributes
                my %column_bind_attrs = $self->bind_attribute_by_data_type($data_type);
 
                if ($data_type =~ /^[BC]LOB$/i) {
-                       $column_bind_attrs{'ora_type'}
-                               = uc($data_type) eq 'CLOB' ? ORA_CLOB : ORA_BLOB;
+                       $column_bind_attrs{'ora_type'} = uc($data_type) eq 'CLOB' ?
+                               DBD::Oracle::ORA_CLOB() :
+                               DBD::Oracle::ORA_BLOB();
                        $column_bind_attrs{'ora_field'} = $column;
                }