Merge 'trunk' into 'chaining_fixes'
Peter Rabbitson [Fri, 5 Feb 2010 18:10:06 +0000 (18:10 +0000)]
r8431@Thesaurus (orig r8418):  frew | 2010-01-22 17:05:12 +0100
fix name of _is_numeric to _is_column_numeric

r8437@Thesaurus (orig r8424):  ribasushi | 2010-01-26 09:33:42 +0100
Switch to Test::Exception
r8438@Thesaurus (orig r8425):  ribasushi | 2010-01-26 09:48:30 +0100
Test txn_scope_guard regression
r8439@Thesaurus (orig r8426):  ribasushi | 2010-01-26 10:10:11 +0100
Fix txn_begin on external non-AC coderef regression
r8443@Thesaurus (orig r8430):  ribasushi | 2010-01-26 14:19:50 +0100
 r8304@Thesaurus (orig r8292):  nigel | 2010-01-13 16:05:48 +0100
 Branch to extend ::Schema::Versioned to handle series of upgrades
 r8320@Thesaurus (orig r8308):  nigel | 2010-01-14 16:52:50 +0100
 Changes to support multiple step schema version updates
 r8321@Thesaurus (orig r8309):  nigel | 2010-01-14 17:05:21 +0100
 Changelog for Changes to support multiple step schema version updates
 r8393@Thesaurus (orig r8380):  ribasushi | 2010-01-19 13:59:51 +0100
 Botched merge (tests still fail)
 r8395@Thesaurus (orig r8382):  ribasushi | 2010-01-19 17:37:07 +0100
 More cleanup
 r8396@Thesaurus (orig r8383):  ribasushi | 2010-01-19 17:48:09 +0100
 Fix last pieces of retardation and UNtodo the quick cycle
 r8442@Thesaurus (orig r8429):  ribasushi | 2010-01-26 14:18:53 +0100
 No need for 2 statements to get the version

r8445@Thesaurus (orig r8432):  ribasushi | 2010-01-26 14:22:16 +0100
 r8161@Thesaurus (orig r8149):  ovid | 2009-12-18 15:59:56 +0100
 Prefetch queries make inefficient SQL when combined with a pager.  This branch
 is to try to isolate some of the join conditions and figure out if we can fix
 this.

 r8166@Thesaurus (orig r8154):  ovid | 2009-12-18 18:17:55 +0100
 Refactor internals to expose some join logic. Awful method and args :(

 r8319@Thesaurus (orig r8307):  ovid | 2010-01-14 15:37:35 +0100
 Attempt to factor our alias handling has mostly failed.

 r8330@Thesaurus (orig r8318):  ribasushi | 2010-01-15 03:02:21 +0100
 Better refactor
 r8332@Thesaurus (orig r8320):  ribasushi | 2010-01-15 03:14:39 +0100
 Better varnames
 r8347@Thesaurus (orig r8335):  ribasushi | 2010-01-17 11:33:55 +0100
 More mangling
 r8348@Thesaurus (orig r8336):  ribasushi | 2010-01-17 13:44:00 +0100
 Getting warmer
 r8349@Thesaurus (orig r8337):  ribasushi | 2010-01-17 14:00:20 +0100
 That was tricky :)
 r8352@Thesaurus (orig r8340):  ribasushi | 2010-01-17 15:57:06 +0100
 Turned out to be much trickier
 r8354@Thesaurus (orig r8342):  ribasushi | 2010-01-17 16:29:20 +0100
 This is made out of awesome
 r8355@Thesaurus (orig r8343):  ribasushi | 2010-01-17 16:46:02 +0100
 Changes
 r8400@Thesaurus (orig r8387):  ribasushi | 2010-01-20 08:17:44 +0100
 Whoops - need to dsable quoting

r8459@Thesaurus (orig r8446):  ribasushi | 2010-01-27 11:56:15 +0100
Clean up some stuff
r8463@Thesaurus (orig r8450):  ribasushi | 2010-01-27 12:08:04 +0100
Merge some cleanups from the prefetch branch
r8466@Thesaurus (orig r8453):  ribasushi | 2010-01-27 12:33:33 +0100
DSNs can not be empty
r8471@Thesaurus (orig r8458):  frew | 2010-01-27 21:38:42 +0100
fix silly multipk bug
r8472@Thesaurus (orig r8459):  ribasushi | 2010-01-28 11:13:16 +0100
Consolidate insert_bulk guards (and make them show up correctly in the trace)
r8473@Thesaurus (orig r8460):  ribasushi | 2010-01-28 11:28:30 +0100
Fix bogus test DDL
r8480@Thesaurus (orig r8467):  ribasushi | 2010-01-28 22:11:59 +0100
 r8381@Thesaurus (orig r8368):  moses | 2010-01-18 16:41:38 +0100
 Test commit
 r8425@Thesaurus (orig r8412):  ribasushi | 2010-01-22 11:25:01 +0100
 Informix test + cleanups
 r8428@Thesaurus (orig r8415):  ribasushi | 2010-01-22 11:59:25 +0100
 Initial informix support

r8482@Thesaurus (orig r8469):  ribasushi | 2010-01-28 22:19:23 +0100
Informix changes
r8483@Thesaurus (orig r8470):  ribasushi | 2010-01-29 12:01:41 +0100
Require non-warning-spewing MooseX::Types
r8484@Thesaurus (orig r8471):  ribasushi | 2010-01-29 12:15:15 +0100
Enhance warning test a bit (seems to fail on 5.8)
r8485@Thesaurus (orig r8472):  ribasushi | 2010-01-29 13:00:54 +0100
Fugly 5.8 workaround
r8494@Thesaurus (orig r8481):  frew | 2010-01-31 06:47:42 +0100
cleanup (3 arg open, 1 grep instead of 3)
r8496@Thesaurus (orig r8483):  ribasushi | 2010-01-31 10:04:43 +0100
better skip message
r8510@Thesaurus (orig r8497):  caelum | 2010-02-01 12:07:13 +0100
throw exception on attempt to insert a blob with DBD::Oracle == 1.23
r8511@Thesaurus (orig r8498):  caelum | 2010-02-01 12:12:48 +0100
add RT link for Oracle blob bug in DBD::Oracle == 1.23
r8527@Thesaurus (orig r8514):  caelum | 2010-02-02 23:20:17 +0100
 r22968@hlagh (orig r8502):  caelum | 2010-02-02 05:30:47 -0500
 branch to support Sybase SQL Anywhere
 r22971@hlagh (orig r8505):  caelum | 2010-02-02 07:21:13 -0500
 ASA last_insert_id and limit support, still needs BLOB support
 r22972@hlagh (orig r8506):  caelum | 2010-02-02 08:33:57 -0500
 deref table name if needed, check all columns for identity column not just PK
 r22973@hlagh (orig r8507):  caelum | 2010-02-02 08:48:11 -0500
 test blobs, they work, didn't have to do anything
 r22974@hlagh (orig r8508):  caelum | 2010-02-02 09:15:44 -0500
 fix stupid identity bug, test empty insert (works), test DTs (not working yet)
 r22976@hlagh (orig r8510):  caelum | 2010-02-02 14:31:00 -0500
 rename ::Sybase::ASA to ::SQLAnywhere, per mst
 r22978@hlagh (orig r8512):  caelum | 2010-02-02 17:02:29 -0500
 DT inflation now works
 r22979@hlagh (orig r8513):  caelum | 2010-02-02 17:18:06 -0500
 minor POD update

r8528@Thesaurus (orig r8515):  caelum | 2010-02-02 23:23:26 +0100
 r22895@hlagh (orig r8473):  caelum | 2010-01-30 03:57:26 -0500
 branch to fix computed columns in Sybase ASE
 r22911@hlagh (orig r8489):  caelum | 2010-01-31 07:18:33 -0500
 empty insert into a Sybase table with computed columns and either data_type => undef or default_value => SCALARREF works now
 r22912@hlagh (orig r8490):  caelum | 2010-01-31 07:39:32 -0500
 add POD about computed columns and timestamps for Sybase
 r22918@hlagh (orig r8496):  caelum | 2010-02-01 05:09:07 -0500
 update POD about Schema::Loader for Sybase

r8531@Thesaurus (orig r8518):  ribasushi | 2010-02-02 23:57:27 +0100
 r8512@Thesaurus (orig r8499):  boghead | 2010-02-01 23:38:13 +0100
 - Creating a branch for adding _post_inflate_datetime and _pre_deflate_datetime to
   InflateColumn::DateTime

 r8513@Thesaurus (orig r8500):  boghead | 2010-02-01 23:42:14 +0100
 - Add _post_inflate_datetime and _pre_deflate_datetime to InflateColumn::DateTime to allow
   for modifying DateTime objects after inflation or before deflation.

 r8524@Thesaurus (orig r8511):  boghead | 2010-02-02 22:59:28 +0100
 - Simplify by allowing moving column_info depreciated {extra}{timezone} data to
   {timezone} (and the same with locale)

r8533@Thesaurus (orig r8520):  caelum | 2010-02-03 05:19:59 +0100
support for Sybase SQL Anywhere through ODBC
r8536@Thesaurus (orig r8523):  ribasushi | 2010-02-03 08:27:54 +0100
Changes
r8537@Thesaurus (orig r8524):  ribasushi | 2010-02-03 08:31:20 +0100
Quote fail
r8538@Thesaurus (orig r8525):  caelum | 2010-02-03 13:21:37 +0100
test DT inflation for Sybase SQL Anywhere over ODBC too
r8539@Thesaurus (orig r8526):  caelum | 2010-02-03 17:36:39 +0100
minor code cleanup for SQL Anywhere last_insert_id
r8540@Thesaurus (orig r8527):  ribasushi | 2010-02-04 11:28:33 +0100
Fix bug reported by tommyt
r8548@Thesaurus (orig r8535):  ribasushi | 2010-02-04 14:34:45 +0100
Prepare for new SQLA release
r8560@Thesaurus (orig r8547):  ribasushi | 2010-02-05 08:59:04 +0100
Refactor some evil code
r8565@Thesaurus (orig r8552):  ribasushi | 2010-02-05 17:00:12 +0100
Looks like RSC is finally (halfway) fixed
r8566@Thesaurus (orig r8553):  ribasushi | 2010-02-05 17:07:13 +0100
RSC subquery can not include the prefetch
r8567@Thesaurus (orig r8554):  ribasushi | 2010-02-05 17:10:29 +0100
Fix typo and borked test
r8569@Thesaurus (orig r8556):  ribasushi | 2010-02-05 17:33:12 +0100
Release 0.08116
r8571@Thesaurus (orig r8558):  ribasushi | 2010-02-05 18:01:33 +0100
No idea how I missed all these fails...
r8572@Thesaurus (orig r8559):  ribasushi | 2010-02-05 18:13:34 +0100
Release 0.08117
r8574@Thesaurus (orig r8561):  ribasushi | 2010-02-05 18:51:12 +0100
Try to distinguish trunk from official versions

lib/DBIx/Class/ResultSet.pm
t/76select.t
t/search/select_chains.t [new file with mode: 0644]

index c0c758f..5d96065 100644 (file)
@@ -299,6 +299,10 @@ sub search_rs {
     $new_attrs->{$key} = $self->_merge_attr($our_attrs->{$key}, $attrs->{$key});
   }
 
+  if (List::Util::first { exists $new_attrs->{$_} } qw{select as columns}) {
+     delete $new_attrs->{$_} for (qw{+select +as +columns});
+  }
+
   my $cond = (@_
     ? (
         (@_ == 1 || ref $_[0] eq "HASH")
@@ -2502,7 +2506,7 @@ sub related_resultset {
         ->relname_to_table_alias($rel, $join_count);
 
     # since this is search_related, and we already slid the select window inwards
-    # (the select/as attrs were deleted in the beginning), we need to flip all 
+    # (the select/as attrs were deleted in the beginning), we need to flip all
     # left joins to inner, so we get the expected results
     # read the comment on top of the actual function to see what this does
     $attrs->{from} = $rsrc->schema->storage->_straight_join_to_node ($attrs->{from}, $alias);
@@ -2715,41 +2719,46 @@ sub _resolved_attrs {
   # build columns (as long as select isn't set) into a set of as/select hashes
   unless ( $attrs->{select} ) {
 
-    my @cols = ( ref($attrs->{columns}) eq 'ARRAY' )
-      ? @{ delete $attrs->{columns}}
-      : (
-          ( delete $attrs->{columns} )
-            ||
-          $source->columns
-        )
-    ;
+    my @cols;
+    if ( ref $attrs->{columns} eq 'ARRAY' ) {
+      @cols = @{ delete $attrs->{columns}}
+    } elsif ( defined $attrs->{columns} ) {
+      @cols = delete $attrs->{columns}
+    } else {
+      @cols = $source->columns
+    }
 
-    @colbits = map {
-      ( ref($_) eq 'HASH' )
-      ? $_
-      : {
-          (
-            /^\Q${alias}.\E(.+)$/
-              ? "$1"
-              : "$_"
-          )
-            =>
-          (
-            /\./
-              ? "$_"
-              : "${alias}.$_"
-          )
-        }
-    } @cols;
+    for (@cols) {
+      if ( ref $_ eq 'HASH' ) {
+        push @colbits, $_
+      } else {
+        my $key = /^\Q${alias}.\E(.+)$/
+          ? "$1"
+          : "$_";
+        my $value = /\./
+          ? "$_"
+          : "${alias}.$_";
+        push @colbits, { $key => $value };
+      }
+    }
   }
 
   # add the additional columns on
-  foreach ( 'include_columns', '+columns' ) {
-      push @colbits, map {
-          ( ref($_) eq 'HASH' )
-            ? $_
-            : { ( split( /\./, $_ ) )[-1] => ( /\./ ? $_ : "${alias}.$_" ) }
-      } ( ref($attrs->{$_}) eq 'ARRAY' ) ? @{ delete $attrs->{$_} } : delete $attrs->{$_} if ( $attrs->{$_} );
+  foreach (qw{include_columns +columns}) {
+    if ( $attrs->{$_} ) {
+      my @list = ( ref($attrs->{$_}) eq 'ARRAY' )
+        ? @{ delete $attrs->{$_} }
+        : delete $attrs->{$_};
+      for (@list) {
+        if ( ref($_) eq 'HASH' ) {
+          push @colbits, $_
+        } else {
+          my $key = ( split /\./, $_ )[-1];
+          my $value = ( /\./ ? $_ : "$alias.$_" );
+          push @colbits, { $key => $value };
+        }
+      }
+    }
   }
 
   # start with initial select items
@@ -2758,15 +2767,22 @@ sub _resolved_attrs {
         ( ref $attrs->{select} eq 'ARRAY' )
       ? [ @{ $attrs->{select} } ]
       : [ $attrs->{select} ];
-    $attrs->{as} = (
-      $attrs->{as}
-      ? (
-        ref $attrs->{as} eq 'ARRAY'
-        ? [ @{ $attrs->{as} } ]
-        : [ $attrs->{as} ]
+
+    if ( $attrs->{as} ) {
+      $attrs->{as} =
+        (
+          ref $attrs->{as} eq 'ARRAY'
+            ? [ @{ $attrs->{as} } ]
+            : [ $attrs->{as} ]
         )
-      : [ map { m/^\Q${alias}.\E(.+)$/ ? $1 : $_ } @{ $attrs->{select} } ]
-    );
+    } else {
+      $attrs->{as} = [ map {
+         m/^\Q${alias}.\E(.+)$/
+           ? $1
+           : $_
+         } @{ $attrs->{select} }
+      ]
+    }
   }
   else {
 
@@ -2776,27 +2792,24 @@ sub _resolved_attrs {
   }
 
   # now add colbits to select/as
-  push( @{ $attrs->{select} }, map { values( %{$_} ) } @colbits );
-  push( @{ $attrs->{as} },     map { keys( %{$_} ) } @colbits );
+  push @{ $attrs->{select} }, map values %{$_}, @colbits;
+  push @{ $attrs->{as}     }, map keys   %{$_}, @colbits;
 
-  my $adds;
-  if ( $adds = delete $attrs->{'+select'} ) {
+  if ( my $adds = delete $attrs->{'+select'} ) {
     $adds = [$adds] unless ref $adds eq 'ARRAY';
-    push(
-      @{ $attrs->{select} },
-      map { /\./ || ref $_ ? $_ : "${alias}.$_" } @$adds
-    );
+    push @{ $attrs->{select} },
+      map { /\./ || ref $_ ? $_ : "$alias.$_" } @$adds;
   }
-  if ( $adds = delete $attrs->{'+as'} ) {
+  if ( my $adds = delete $attrs->{'+as'} ) {
     $adds = [$adds] unless ref $adds eq 'ARRAY';
-    push( @{ $attrs->{as} }, @$adds );
+    push @{ $attrs->{as} }, @$adds;
   }
 
-  $attrs->{from} ||= [ {
+  $attrs->{from} ||= [{
     -source_handle => $source->handle,
     -alias => $self->{attrs}{alias},
     $self->{attrs}{alias} => $source->from,
-  } ];
+  }];
 
   if ( $attrs->{join} || $attrs->{prefetch} ) {
 
@@ -2816,7 +2829,7 @@ sub _resolved_attrs {
           $join,
           $alias,
           { %{ $attrs->{seen_join} || {} } },
-          ($attrs->{seen_join} && keys %{$attrs->{seen_join}})
+          ( $attrs->{seen_join} && keys %{$attrs->{seen_join}})
             ? $attrs->{from}[-1][0]{-join_path}
             : []
           ,
index 2ca47e6..6065119 100644 (file)
@@ -158,9 +158,8 @@ is_deeply(
   {
     artist         => 1,
     track_position => 2,
-    tracks         => {
-      trackid => 17,
-      title   => 'Apiary',
+    tracks => {
+      title => 'Apiary',
     },
   },
   'columns/select/as fold properly on sub-searches',
diff --git a/t/search/select_chains.t b/t/search/select_chains.t
new file mode 100644 (file)
index 0000000..6771d3b
--- /dev/null
@@ -0,0 +1,60 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+
+use lib qw(t/lib);
+use DBIC::SqlMakerTest;
+use DBICTest;
+
+
+my $schema = DBICTest->init_schema();
+
+my @chain = (
+  {
+    columns     => [ 'cdid' ],
+    '+select'   => [ { lower => 'title' }, 'genreid' ],
+    '+as'       => [ qw/title_lc genreid/ ],
+  } => 'SELECT me.cdid, LOWER( title ), me.genreid FROM cd me',
+
+  {
+    '+columns'  => [ { max_year => { max => 'me.year' }}, ],
+    '+select'   => [ { count => 'me.cdid' }, ],
+    '+as'       => [ 'cnt' ],
+  } => 'SELECT me.cdid, MAX( me.year ), LOWER( title ), me.genreid, COUNT( me.cdid ) FROM cd me',
+
+  {
+    select      => [ { min => 'me.cdid' }, ],
+    as          => [ 'min_id' ],
+  } => 'SELECT MIN( me.cdid ) FROM cd me',
+
+  {
+    '+columns' => [ { cnt => { count => 'cdid' } } ],
+  } => 'SELECT COUNT ( cdid ), MIN( me.cdid ) FROM cd me',
+
+  {
+    columns => [ 'year' ],
+  } => 'SELECT me.year FROM cd me',
+);
+
+my $rs = $schema->resultset('CD');
+
+my $testno = 1;
+while (@chain) {
+  my $attrs = shift @chain;
+  my $sql = shift @chain;
+
+  $rs = $rs->search ({}, $attrs);
+
+  is_same_sql_bind (
+    $rs->as_query,
+    "x( $sql )", # the x-es are here until SQLA is fixed
+    [],
+    "Test $testno of SELECT assembly ok",
+  );
+
+  $testno++;
+}
+
+done_testing;
\ No newline at end of file