Merge 'trunk' into 'mssql_top_fixes'
Peter Rabbitson [Fri, 19 Jun 2009 16:41:45 +0000 (16:41 +0000)]
r6690@Thesaurus (orig r6689):  timbunce | 2009-06-16 15:06:07 +0200
Removed wording from txn_do that implies the coderef could be executed more than once.

r6691@Thesaurus (orig r6690):  timbunce | 2009-06-16 15:14:23 +0200
Added doc note that txn_commit does not perform an actual storage commit unless
there's a DBIx::Class transaction currently in effect

r6692@Thesaurus (orig r6691):  timbunce | 2009-06-16 15:40:11 +0200
Reverted doc patch r6689 for now, sadly. I'll open a ticket to explain.

r6694@Thesaurus (orig r6693):  ribasushi | 2009-06-16 17:22:59 +0200
Fix possible regression with prefetch select resolution
r6699@Thesaurus (orig r6698):  wintrmute | 2009-06-17 10:32:30 +0200
Replace vague language around whether load_classes/namespaces is preferred,
with an explanation that load_namespaces() is generally preferred, and explain
when load_classes is appropriate.
r6702@Thesaurus (orig r6701):  caelum | 2009-06-17 19:50:47 +0200
fix page with offset bug
r6704@Thesaurus (orig r6703):  ribasushi | 2009-06-18 08:40:18 +0200
Cleanup attribute handling - I deal with resolved attributes throughout, no point in complicating things further
r6705@Thesaurus (orig r6704):  abraxxa | 2009-06-18 12:30:01 +0200
added test for nested has_many prefetch without entries

r6707@Thesaurus (orig r6706):  ribasushi | 2009-06-18 12:43:36 +0200
HRI fix
r6708@Thesaurus (orig r6707):  ribasushi | 2009-06-18 14:05:42 +0200
wtf
r6714@Thesaurus (orig r6713):  caelum | 2009-06-19 01:03:01 +0200
fix broken link in manual
r6726@Thesaurus (orig r6725):  ribasushi | 2009-06-19 17:25:19 +0200
 r6706@Thesaurus (orig r6705):  ribasushi | 2009-06-18 12:30:08 +0200
 Branch to attempt prefetch with limit fix
 r6709@Thesaurus (orig r6708):  ribasushi | 2009-06-18 15:54:38 +0200
 This seems to be the prefetch+limit fix - ugly as hell but appears to work
 r6710@Thesaurus (orig r6709):  ribasushi | 2009-06-18 16:13:31 +0200
 More comments
 r6717@Thesaurus (orig r6716):  ribasushi | 2009-06-19 15:39:43 +0200
 single() throws with has_many prefetch
 r6718@Thesaurus (orig r6717):  ribasushi | 2009-06-19 15:40:38 +0200
 Rename test
 r6719@Thesaurus (orig r6718):  ribasushi | 2009-06-19 15:44:26 +0200
 cleanup svn attrs
 r6720@Thesaurus (orig r6719):  ash | 2009-06-19 16:31:11 +0200
 Add extra test for prefetch+has_many

 r6721@Thesaurus (orig r6720):  ribasushi | 2009-06-19 16:33:49 +0200
 no need to slice as use_prefetch already has a limit
 r6722@Thesaurus (orig r6721):  ribasushi | 2009-06-19 16:36:08 +0200
 throw in an extra limit, sophisticate test a bit
 r6723@Thesaurus (orig r6722):  ribasushi | 2009-06-19 16:36:54 +0200
 Fix the fix
 r6725@Thesaurus (orig r6724):  ribasushi | 2009-06-19 17:24:23 +0200
 Fix dubious optimization

1  2 
lib/DBIx/Class/ResultSet.pm
lib/DBIx/Class/Storage/DBI.pm

@@@ -698,10 -698,14 +698,14 @@@ a warning
  
    Query returned more than one row
  
- In this case, you should be using L</first> or L</find> instead, or if you really
+ In this case, you should be using L</next> or L</find> instead, or if you really
  know what you are doing, use the L</rows> attribute to explicitly limit the size
  of the resultset.
  
+ This method will also throw an exception if it is called on a resultset prefetching
+ has_many, as such a prefetch implies fetching multiple rows from the database in
+ order to assemble the resulting object.
  =back
  
  =cut
@@@ -714,6 -718,12 +718,12 @@@ sub single 
  
    my $attrs = $self->_resolved_attrs_copy;
  
+   if (keys %{$attrs->{collapse}}) {
+     $self->throw_exception(
+       'single() can not be used on resultsets prefetching has_many. Use find( \%cond ) or next() instead'
+     );
+   }
    if ($where) {
      if (defined $attrs->{where}) {
        $attrs->{where} = {
@@@ -1144,7 -1154,7 +1154,7 @@@ sub count 
    return $self->search(@_)->count if @_ and defined $_[0];
    return scalar @{ $self->get_cache } if $self->get_cache;
  
-   my $meth = $self->_has_attr (qw/prefetch collapse distinct group_by/)
+   my $meth = $self->_has_resolved_attr (qw/collapse group_by/)
      ? 'count_grouped'
      : 'count'
    ;
@@@ -1276,15 -1286,15 +1286,15 @@@ sub _rs_update_delete 
  
    my $rsrc = $self->result_source;
  
-   my $needs_group_by_subq = $self->_has_attr (qw/prefetch distinct join seen_join group_by/);
-   my $needs_subq = $self->_has_attr (qw/row offset page/);
+   my $needs_group_by_subq = $self->_has_resolved_attr (qw/collapse group_by -join/);
+   my $needs_subq = $self->_has_resolved_attr (qw/row offset/);
  
    if ($needs_group_by_subq or $needs_subq) {
  
      # make a new $rs selecting only the PKs (that's all we really need)
      my $attrs = $self->_resolved_attrs_copy;
  
-     delete $attrs->{$_} for qw/prefetch collapse select +select as +as columns +columns/;
+     delete $attrs->{$_} for qw/collapse select as/;
      $attrs->{columns} = [ map { "$attrs->{alias}.$_" } ($self->result_source->primary_columns) ];
  
      if ($needs_group_by_subq) {
@@@ -1808,14 -1818,14 +1818,14 @@@ sub _is_deterministic_value 
    return 0;
  }
  
- # _has_attr
+ # _has_resolved_attr
  #
  # determines if the resultset defines at least one
  # of the attributes supplied
  #
  # used to determine if a subquery is neccessary
  
- sub _has_attr {
+ sub _has_resolved_attr {
    my ($self, @attr_names) = @_;
  
    my $attrs = $self->_resolved_attrs;
    my $join_check_req;
  
    for my $n (@attr_names) {
-     ++$join_check_req if $n =~ /join/;
+     ++$join_check_req if $n eq '-join';
  
      my $attr =  $attrs->{$n};
  
      }
    }
  
-   # a join can be expressed as a multi-level from
+   # a resolved join is expressed as a multi-level from
    return 1 if (
      $join_check_req
        and
@@@ -2595,35 -2605,38 +2605,40 @@@ sub _resolved_attrs 
    # Although this is needed only if the order_by is not defined, it is
    # actually cheaper to just populate this rather than properly examining
    # order_by (stuf like [ {} ] and the like)
 -  $attrs->{_virtual_order_by} = [ $self->result_source->primary_columns ];
 -
 +  my $prefix = $alias . ($source->schema->storage->_sql_maker_opts->{name_sep} || '.');
 +  $attrs->{_virtual_order_by} = [
 +    map { $prefix . $_ } ($source->primary_columns)
 +  ];
  
-   my $collapse = $attrs->{collapse} || {};
+   $attrs->{collapse} ||= {};
    if ( my $prefetch = delete $attrs->{prefetch} ) {
      $prefetch = $self->_merge_attr( {}, $prefetch );
-     my @pre_order;
-     foreach my $p ( ref $prefetch eq 'ARRAY' ? @$prefetch : ($prefetch) ) {
-       # bring joins back to level of current class
-       my $join_map = $self->_joinpath_aliases ($attrs->{from}, $attrs->{seen_join});
-       my @prefetch =
-         $source->_resolve_prefetch( $p, $alias, $join_map, \@pre_order, $collapse );
-       push( @{ $attrs->{select} }, map { $_->[0] } @prefetch );
-       push( @{ $attrs->{as} },     map { $_->[1] } @prefetch );
-     }
-     push( @{ $attrs->{order_by} }, @pre_order );
+     my $prefetch_ordering = [];
+     my $join_map = $self->_joinpath_aliases ($attrs->{from}, $attrs->{seen_join});
+     my @prefetch =
+       $source->_resolve_prefetch( $prefetch, $alias, $join_map, $prefetch_ordering, $attrs->{collapse} );
+     push( @{ $attrs->{select} }, map { $_->[0] } @prefetch );
+     push( @{ $attrs->{as} },     map { $_->[1] } @prefetch );
+     push( @{ $attrs->{order_by} }, @$prefetch_ordering );
+     $attrs->{_collapse_order_by} = \@$prefetch_ordering;
    }
  
    if (delete $attrs->{distinct}) {
      $attrs->{group_by} ||= [ grep { !ref($_) || (ref($_) ne 'HASH') } @{$attrs->{select}} ];
    }
  
-   $attrs->{collapse} = $collapse;
-   if ( $attrs->{page} and not defined $attrs->{offset} ) {
-     $attrs->{offset} = ( $attrs->{rows} * ( $attrs->{page} - 1 ) );
+   # if both page and offset are specified, produce a combined offset
+   # even though it doesn't make much sense, this is what pre 081xx has
+   # been doing
+   if (my $page = delete $attrs->{page}) {
+     $attrs->{offset} = ($attrs->{rows} * ($page - 1)) +
+       ($attrs->{offset} || 0);
    }
  
    return $self->{_attrs} = $attrs;
@@@ -3,7 -3,7 +3,7 @@@ package DBIx::Class::Storage::DBI
  
  use base 'DBIx::Class::Storage';
  
 -use strict;    
 +use strict;
  use warnings;
  use Carp::Clan qw/^DBIx::Class/;
  use DBI;
@@@ -89,8 -89,8 +89,8 @@@ recognized by DBIx::Class
  
  =item *
  
 -A single code reference which returns a connected 
 -L<DBI database handle|DBI/connect> optionally followed by 
 +A single code reference which returns a connected
 +L<DBI database handle|DBI/connect> optionally followed by
  L<extra attributes|/DBIx::Class specific connection attributes> recognized
  by DBIx::Class:
  
@@@ -109,7 -109,7 +109,7 @@@ mixed together
      %extra_attributes,
    }];
  
 -This is particularly useful for L<Catalyst> based applications, allowing the 
 +This is particularly useful for L<Catalyst> based applications, allowing the
  following config (L<Config::General> style):
  
    <Model::DB>
@@@ -128,7 -128,7 +128,7 @@@ Please note that the L<DBI> docs recomm
  set C<AutoCommit> to either I<0> or I<1>.  L<DBIx::Class> further
  recommends that it be set to I<1>, and that you perform transactions
  via our L<DBIx::Class::Schema/txn_do> method.  L<DBIx::Class> will set it
 -to I<1> if you do not do explicitly set it to zero.  This is the default 
 +to I<1> if you do not do explicitly set it to zero.  This is the default
  for most DBDs. See L</DBIx::Class and AutoCommit> for details.
  
  =head3 DBIx::Class specific connection attributes
@@@ -182,7 -182,7 +182,7 @@@ storage object
  If set to a true value, this option will disable the caching of
  statement handles via L<DBI/prepare_cached>.
  
 -=item limit_dialect 
 +=item limit_dialect
  
  Sets the limit dialect. This is useful for JDBC-bridge among others
  where the remote SQL-dialect cannot be determined by the name of the
@@@ -190,7 -190,7 +190,7 @@@ driver alone. See also L<SQL::Abstract:
  
  =item quote_char
  
 -Specifies what characters to use to quote table and column names. If 
 +Specifies what characters to use to quote table and column names. If
  you use this you will want to specify L</name_sep> as well.
  
  C<quote_char> expects either a single character, in which case is it
@@@ -202,8 -202,8 +202,8 @@@ SQL Server you should use C<< quote_cha
  
  =item name_sep
  
 -This only needs to be used in conjunction with C<quote_char>, and is used to 
 -specify the charecter that seperates elements (schemas, tables, columns) from 
 +This only needs to be used in conjunction with C<quote_char>, and is used to
 +specify the charecter that seperates elements (schemas, tables, columns) from
  each other. In most cases this is simply a C<.>.
  
  The consequences of not supplying this value is that L<SQL::Abstract>
@@@ -594,7 -594,7 +594,7 @@@ sub dbh 
  
  sub _sql_maker_args {
      my ($self) = @_;
 -    
 +
      return ( bindtype=>'columns', array_datatypes => 1, limit_dialect => $self->dbh, %{$self->_sql_maker_opts} );
  }
  
@@@ -753,11 -753,11 +753,11 @@@ sub svp_begin 
  
    $self->throw_exception ("Your Storage implementation doesn't support savepoints")
      unless $self->can('_svp_begin');
 -  
 +
    push @{ $self->{savepoints} }, $name;
  
    $self->debugobj->svp_begin($name) if $self->debug;
 -  
 +
    return $self->_svp_begin($name);
  }
  
@@@ -817,7 -817,7 +817,7 @@@ sub svp_rollback 
    }
  
    $self->debugobj->svp_rollback($name) if $self->debug;
 -  
 +
    return $self->_svp_rollback($name);
  }
  
@@@ -955,7 -955,7 +955,7 @@@ sub _dbh_execute 
  
    my $sth = $self->sth($sql,$op);
  
 -  my $placeholder_index = 1; 
 +  my $placeholder_index = 1;
  
    foreach my $bound (@$bind) {
      my $attributes = {};
@@@ -1014,7 -1014,7 +1014,7 @@@ sub insert 
  }
  
  ## Still not quite perfect, and EXPERIMENTAL
 -## Currently it is assumed that all values passed will be "normal", i.e. not 
 +## Currently it is assumed that all values passed will be "normal", i.e. not
  ## scalar refs, or at least, all the same type as the first set, the statement is
  ## only prepped once.
  sub insert_bulk {
    my $table = $source->from;
    @colvalues{@$cols} = (0..$#$cols);
    my ($sql, @bind) = $self->sql_maker->insert($table, \%colvalues);
 -  
 +
    $self->_query_start( $sql, @bind );
    my $sth = $self->sth($sql);
  
    my $bind_attributes = $self->source_bind_attributes($source);
  
    ## Bind the values and execute
 -  my $placeholder_index = 1; 
 +  my $placeholder_index = 1;
  
    foreach my $bound (@bind) {
  
@@@ -1084,7 -1084,7 +1084,7 @@@ sub update 
    my $self = shift @_;
    my $source = shift @_;
    my $bind_attributes = $self->source_bind_attributes($source);
 -  
 +
    return $self->_execute('update' => [], $source, $bind_attributes, @_);
  }
  
  sub delete {
    my $self = shift @_;
    my $source = shift @_;
 -  
 +
    my $bind_attrs = $self->source_bind_attributes($source);
 -  
 +
    return $self->_execute('delete' => [], $source, $bind_attrs, @_);
  }
  
@@@ -1193,10 -1193,10 +1193,10 @@@ sub _select 
    my $self = shift;
  
    # localization is neccessary as
 -  # 1) there is no infrastructure to pass this around (easy to do, but will wait)
 +  # 1) there is no infrastructure to pass this around before SQLA2
    # 2) _select_args sets it and _prep_for_execute consumes it
    my $sql_maker = $self->sql_maker;
 -  local $sql_maker->{for};
 +  local $sql_maker->{_dbic_rs_attrs};
  
    return $self->_execute($self->_select_args(@_));
  }
@@@ -1205,10 -1205,10 +1205,10 @@@ sub _select_args_to_query 
    my $self = shift;
  
    # localization is neccessary as
 -  # 1) there is no infrastructure to pass this around (easy to do, but will wait)
 +  # 1) there is no infrastructure to pass this around before SQLA2
    # 2) _select_args sets it and _prep_for_execute consumes it
    my $sql_maker = $self->sql_maker;
 -  local $sql_maker->{for};
 +  local $sql_maker->{_dbic_rs_attrs};
  
    # my ($op, $bind, $ident, $bind_attrs, $select, $cond, $order, $rows, $offset)
    #  = $self->_select_args($ident, $select, $cond, $attrs);
  }
  
  sub _select_args {
-   my ($self, $ident, $select, $condition, $attrs) = @_;
+   my ($self, $ident, $select, $where, $attrs) = @_;
  
    my $sql_maker = $self->sql_maker;
 +  $sql_maker->{_dbic_rs_attrs} = $attrs;
 +
-   my $order = { map
-     { $attrs->{$_} ? ( $_ => $attrs->{$_} ) : ()  }
-     (qw/order_by group_by having _virtual_order_by/ )
-   };
-   my $bind_attrs = {};
    my $alias2source = $self->_resolve_ident_sources ($ident);
  
+   # calculate bind_attrs before possible $ident mangling
+   my $bind_attrs = {};
    for my $alias (keys %$alias2source) {
      my $bindtypes = $self->source_bind_attributes ($alias2source->{$alias}) || {};
      for my $col (keys %$bindtypes) {
      }
    }
  
-   # This would be the point to deflate anything found in $condition
-   # (and leave $attrs->{bind} intact). Problem is - inflators historically
-   # expect a row object. And all we have is a resultsource (it is trivial
-   # to extract deflator coderefs via $alias2source above).
-   #
-   # I don't see a way forward other than changing the way deflators are
-   # invoked, and that's just bad...
-   my @args = ('select', $attrs->{bind}, $ident, $bind_attrs, $select, $condition, $order);
+   my @limit;
    if ($attrs->{software_limit} ||
        $sql_maker->_default_limit_syntax eq "GenericSubQ") {
          $attrs->{software_limit} = 1;
  
      # MySQL actually recommends this approach.  I cringe.
      $attrs->{rows} = 2**48 if not defined $attrs->{rows} and defined $attrs->{offset};
-     push @args, $attrs->{rows}, $attrs->{offset};
+     if ($attrs->{rows} && keys %{$attrs->{collapse}}) {
+       ($ident, $select, $where, $attrs)
+         = $self->_adjust_select_args_for_limited_prefetch ($ident, $select, $where, $attrs);
+     }
+     else {
+       push @limit, $attrs->{rows}, $attrs->{offset};
+     }
    }
-   return @args;
+ ###
+   # This would be the point to deflate anything found in $where
+   # (and leave $attrs->{bind} intact). Problem is - inflators historically
+   # expect a row object. And all we have is a resultsource (it is trivial
+   # to extract deflator coderefs via $alias2source above).
+   #
+   # I don't see a way forward other than changing the way deflators are
+   # invoked, and that's just bad...
+ ###
+   my $order = { map
+     { $attrs->{$_} ? ( $_ => $attrs->{$_} ) : ()  }
+     (qw/order_by group_by having _virtual_order_by/ )
+   };
+   $sql_maker->{for} = delete $attrs->{for};
+   return ('select', $attrs->{bind}, $ident, $bind_attrs, $select, $where, $order, @limit);
+ }
+ sub _adjust_select_args_for_limited_prefetch {
+   my ($self, $from, $select, $where, $attrs) = @_;
+   if ($attrs->{group_by} and @{$attrs->{group_by}}) {
+     $self->throw_exception ('Prefetch with limit (rows/offset) is not supported on resultsets with a group_by attribute');
+   }
+   $self->throw_exception ('Prefetch with limit (rows/offset) is not supported on resultsets with a custom from attribute')
+     if (ref $from ne 'ARRAY');
+   # separate attributes
+   my $sub_attrs = { %$attrs };
+   delete $attrs->{$_} for qw/where bind rows offset/;
+   delete $sub_attrs->{$_} for qw/for collapse select order_by/;
+   my $alias = $attrs->{alias};
+   # create subquery select list
+   my $sub_select = [ grep { $_ =~ /^$alias\./ } @{$attrs->{select}} ];
+   # bring over all non-collapse-induced order_by into the inner query (if any)
+   # the outer one will have to keep them all
+   if (my $ord_cnt = @{$attrs->{order_by}} - @{$attrs->{_collapse_order_by}} ) {
+     $sub_attrs->{order_by} = [
+       @{$attrs->{order_by}}[ 0 .. ($#{$attrs->{order_by}} - $ord_cnt - 1) ]
+     ];
+   }
+   # mangle the head of the {from}
+   my $self_ident = shift @$from;
+   my %join_info = map { $_->[0]{-alias} => $_->[0] } (@$from);
+   my (%inner_joins);
+   # decide which parts of the join will remain on the inside
+   #
+   # this is not a very viable optimisation, but it was written
+   # before I realised this, so might as well remain. We can throw
+   # away _any_ branches of the join tree that are:
+   # 1) not mentioned in the condition/order
+   # 2) left-join leaves (or left-join leaf chains)
+   # Most of the join ocnditions will not satisfy this, but for real
+   # complex queries some might, and we might make some RDBMS happy.
+   #
+   #
+   # since we do not have introspectable SQLA, we fall back to ugly
+   # scanning of raw SQL for WHERE, and for pieces of ORDER BY
+   # in order to determine what goes into %inner_joins
+   # It may not be very efficient, but it's a reasonable stop-gap
+   {
+     # produce stuff unquoted, so it can be scanned
+     my $sql_maker = $self->sql_maker;
+     local $sql_maker->{quote_char};
+     my @order_by = (map
+       { ref $_ ? $_->[0] : $_ }
+       $sql_maker->_order_by_chunks ($sub_attrs->{order_by})
+     );
+     my $where_sql = $sql_maker->where ($where);
+     # sort needed joins
+     for my $alias (keys %join_info) {
+       # any table alias found on a column name in where or order_by
+       # gets included in %inner_joins
+       # Also any parent joins that are needed to reach this particular alias
+       for my $piece ($where_sql, @order_by ) {
+         if ($piece =~ /\b$alias\./) {
+           $inner_joins{$alias} = 1;
+         }
+       }
+     }
+   }
+   # scan for non-leaf/non-left joins and mark as needed
+   # also mark all ancestor joins that are needed to reach this particular alias
+   # (e.g.  join => { cds => 'tracks' } - tracks will bring cds too )
+   #
+   # traverse by the size of the -join_path i.e. reverse depth first
+   for my $alias (sort { @{$join_info{$b}{-join_path}} <=> @{$join_info{$a}{-join_path}} } (keys %join_info) ) {
+     my $j = $join_info{$alias};
+     $inner_joins{$alias} = 1 if (! $j->{-join_type} || ($j->{-join_type} !~ /^left$/i) );
+     if ($inner_joins{$alias}) {
+       $inner_joins{$_} = 1 for (@{$j->{-join_path}});
+     }
+   }
+   # construct the inner $from for the subquery
+   my $inner_from = [ $self_ident ];
+   if (keys %inner_joins) {
+     for my $j (@$from) {
+       push @$inner_from, $j if $inner_joins{$j->[0]{-alias}};
+     }
+     # if a multi-type join was needed in the subquery ("multi" is indicated by
+     # presence in {collapse}) - add a group_by to simulate the collapse in the subq
+     for my $alias (keys %inner_joins) {
+       # the dot comes from some weirdness in collapse
+       # remove after the rewrite
+       if ($attrs->{collapse}{".$alias"}) {
+         $sub_attrs->{group_by} = $sub_select;
+         last;
+       }
+     }
+   }
+   # generate the subquery
+   my $subq = $self->_select_args_to_query (
+     $inner_from,
+     $sub_select,
+     $where,
+     $sub_attrs
+   );
+   # put it back in $from
+   unshift @$from, { $alias => $subq };
+   # This is totally horrific - the $where ends up in both the inner and outer query
+   # Unfortunately not much can be done until SQLA2 introspection arrives
+   #
+   # OTOH it can be seen as a plus: <ash> (notes that this query would make a DBA cry ;)
+   return ($from, $select, $where, $attrs);
  }
  
  sub _resolve_ident_sources {
    return $alias2source;
  }
  
 +# Takes $ident, \@column_names
 +#
 +# returns { $column_name => \%column_info, ... }
 +# also note: this adds -result_source => $rsrc to the column info
 +#
 +# usage:
 +#   my $col_sources = $self->_resolve_column_info($ident, [map $_->[0], @{$bind}]);
 +sub _resolve_column_info {
 +  my ($self, $ident, $colnames) = @_;
 +  my $alias2src = $self->_resolve_ident_sources($ident);
 +
 +  my $sep = $self->_sql_maker_opts->{name_sep} || '.';
 +  $sep = "\Q$sep\E";
 +  
 +  my %return;
 +  foreach my $col (@{$colnames}) {
 +    $col =~ m/^ (?: ([^$sep]+) $sep)? (.+) $/x;
 +
 +    my $alias = $1 || 'me';
 +    my $colname = $2;
 +
 +    my $rsrc = $alias2src->{$alias};
 +    $return{$col} = $rsrc && { %{$rsrc->column_info($colname)}, -result_source => $rsrc };
 +  }
 +  return \%return;
 +}
 +
  sub count {
    my ($self, $source, $attrs) = @_;
  
    my $tmp_attrs = { %$attrs };
  
-   # take off any pagers, record_filter is cdbi, and no point of ordering a count
-   delete $tmp_attrs->{$_} for (qw/select as rows offset page order_by record_filter/);
+   # take off any limits, record_filter is cdbi, and no point of ordering a count
+   delete $tmp_attrs->{$_} for (qw/select as rows offset order_by record_filter/);
  
    # overwrite the selector
    $tmp_attrs->{select} = { count => '*' };
@@@ -1363,7 -1476,7 +1505,7 @@@ sub count_grouped 
    my $sub_attrs = { %$attrs };
  
    # these can not go in the subquery, and there is no point of ordering it
-   delete $sub_attrs->{$_} for qw/prefetch collapse select as order_by/;
+   delete $sub_attrs->{$_} for qw/collapse select as order_by/;
  
    # if we prefetch, we group_by primary keys only as this is what we would get out of the rs via ->next/->all
    # simply deleting group_by suffices, as the code below will re-fill it
    }];
  
    # the subquery replaces this
-   delete $attrs->{$_} for qw/where bind prefetch collapse group_by having having_bind rows offset page pager/;
+   delete $attrs->{$_} for qw/where bind collapse group_by having having_bind rows offset/;
  
    return $self->count ($source, $attrs);
  }
@@@ -1398,10 -1511,10 +1540,10 @@@ sub _grouped_count_select 
  
  sub source_bind_attributes {
    my ($self, $source) = @_;
 -  
 +
    my $bind_attributes;
    foreach my $column ($source->columns) {
 -  
 +
      my $data_type = $source->column_info($column)->{data_type} || '';
      $bind_attributes->{$column} = $self->bind_attribute_by_data_type($data_type)
       if $data_type;
@@@ -1650,13 -1763,13 +1792,13 @@@ By default, C<\%sqlt_args> will hav
  
   { add_drop_table => 1, ignore_constraint_names => 1, ignore_index_names => 1 }
  
 -merged with the hash passed in. To disable any of those features, pass in a 
 +merged with the hash passed in. To disable any of those features, pass in a
  hashref like the following
  
   { ignore_constraint_names => 0, # ... other options }
  
  
 -Note that this feature is currently EXPERIMENTAL and may not work correctly 
 +Note that this feature is currently EXPERIMENTAL and may not work correctly
  across all databases, or fully handle complex relationships.
  
  WARNING: Please check all SQL files created, before applying them.
@@@ -1677,7 -1790,7 +1819,7 @@@ sub create_ddl_dir 
    $version ||= $schema_version;
  
    $sqltargs = {
 -    add_drop_table => 1, 
 +    add_drop_table => 1,
      ignore_constraint_names => 1,
      ignore_index_names => 1,
      %{$sqltargs || {}}
      }
      print $file $output;
      close($file);
 -  
 +
      next unless ($preversion);
  
      require SQL::Translator::Diff;
        carp("Overwriting existing diff file - $difffile");
        unlink($difffile);
      }
 -    
 +
      my $source_schema;
      {
        my $t = SQL::Translator->new($sqltargs);
          unless ( $source_schema->name );
      }
  
 -    # The "new" style of producers have sane normalization and can support 
 +    # The "new" style of producers have sane normalization and can support
      # diffing a SQL file against a DBIC->SQLT schema. Old style ones don't
      # And we have to diff parsed SQL against parsed SQL.
      my $dest_schema = $sqlt_schema;
        $dest_schema->name( $filename )
          unless $dest_schema->name;
      }
 -    
 +
      my $diff = SQL::Translator::Diff::schema_diff($source_schema, $db,
                                                    $dest_schema,   $db,
                                                    $sqltargs
                                                   );
 -    if(!open $file, ">$difffile") { 
 +    if(!open $file, ">$difffile") {
        $self->throw_exception("Can't write to $difffile ($!)");
        next;
      }
@@@ -1822,7 -1935,7 +1964,7 @@@ sub deployment_statements 
    if(-f $filename)
    {
        my $file;
 -      open($file, "<$filename") 
 +      open($file, "<$filename")
          or $self->throw_exception("Can't open $filename ($!)");
        my @rows = <$file>;
        close($file);
    eval qq{use SQL::Translator::Producer::${type}};
    $self->throw_exception($@) if $@;
  
 -  # sources needs to be a parser arg, but for simplicty allow at top level 
 +  # sources needs to be a parser arg, but for simplicty allow at top level
    # coming in
    $sqltargs->{parser_args}{sources} = delete $sqltargs->{sources}
        if exists $sqltargs->{sources};
@@@ -1942,7 -2055,7 +2084,7 @@@ returned by databases that don't suppor
  
  sub is_replicating {
      return;
 -    
 +
  }
  
  =head2 lag_behind_master