From: Peter Rabbitson Date: Sun, 28 Nov 2010 02:15:24 +0000 (+0100) Subject: Rename method, normalize rv to [$sql, @bind] X-Git-Tag: v0.08125~36 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bac358c9d99a75db2d2bab8f11102ed557f523b7;p=dbsrgits%2FDBIx-Class.git Rename method, normalize rv to [$sql, @bind] --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 580ab20..db6c27e 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2745,7 +2745,7 @@ sub is_paged { sub is_ordered { my ($self) = @_; - return scalar $self->result_source->storage->_extract_order_columns($self->{attrs}{order_by}); + return scalar $self->result_source->storage->_extract_order_criteria($self->{attrs}{order_by}); } =head2 related_resultset diff --git a/lib/DBIx/Class/ResultSetColumn.pm b/lib/DBIx/Class/ResultSetColumn.pm index a459bc3..0879585 100644 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@ -68,8 +68,8 @@ sub new { ; if ( scalar grep - { ! $collist{$_} } - ( $rs->result_source->schema->storage->_extract_order_columns ($orig_attrs->{order_by} ) ) + { ! $collist{$_->[0]} } + ( $rs->result_source->schema->storage->_extract_order_criteria ($orig_attrs->{order_by} ) ) ) { # nuke the prefetch before collapsing to sql my $subq_rs = $rs->search; diff --git a/lib/DBIx/Class/Storage/DBI/MSSQL.pm b/lib/DBIx/Class/Storage/DBI/MSSQL.pm index 77b0996..1a1f355 100644 --- a/lib/DBIx/Class/Storage/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Storage/DBI/MSSQL.pm @@ -164,7 +164,7 @@ sub _select_args_to_query { if ( $sql !~ /^ \s* SELECT \s+ TOP \s+ \d+ \s+ /xi && - scalar $self->_extract_order_columns ($attrs->{order_by}) + scalar $self->_extract_order_criteria ($attrs->{order_by}) ) { $self->throw_exception( 'An ordered subselect encountered - this is not safe! Please see "Ordered Subselects" in DBIx::Class::Storage::DBI::MSSQL diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 9fa00f2..54ca793 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -355,7 +355,6 @@ has 'write_handler' => ( _resolve_column_info _prune_unused_joins _strip_cond_qualifiers - _extract_order_columns _resolve_aliastypes_from_select_args _execute _do_query @@ -379,6 +378,7 @@ my @unimplemented = qw( _inner_join_to_node _group_over_selection _prefetch_autovalues + _extract_order_criteria ); # the capability framework diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index 61f8aac..db9bc27 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -276,8 +276,8 @@ sub _resolve_aliastypes_from_select_args { }), ], selecting => [ - $self->_extract_order_columns ($attrs->{order_by}, $sql_maker), $sql_maker->_recurse_fields ($select), + ( map { $_->[0] } $self->_extract_order_criteria ($attrs->{order_by}, $sql_maker) ), ], }; @@ -336,6 +336,7 @@ sub _resolve_aliastypes_from_select_args { return $aliases_by_type; } +# This is the engine behind { distinct => 1 } sub _group_over_selection { my ($self, $from, $select, $order_by) = @_; @@ -356,11 +357,12 @@ sub _group_over_selection { # add any order_by parts that are not already present in the group_by # we need to be careful not to add any named functions/aggregates - # i.e. select => [ ... { count => 'foo', -as 'foocount' } ... ] - for my $chunk ($self->_extract_order_columns($order_by)) { + # i.e. order_by => [ ... { count => 'foo' } ... ] + for ($self->_extract_order_criteria($order_by)) { # only consider real columns (for functions the user got to do an explicit group_by) - my $colinfo = $rs_column_list->{$chunk} - or next; + next if @$_ != 1; + my $chunk = $_->[0]; + my $colinfo = $rs_column_list->{$chunk} or next; $chunk = "$colinfo->{-source_alias}.$chunk" if $chunk !~ /\./; push @group_by, $chunk unless $group_index{$chunk}++; @@ -588,7 +590,7 @@ sub _strip_cond_qualifiers { return $cond; } -sub _extract_order_columns { +sub _extract_order_criteria { my ($self, $order_by, $sql_maker) = @_; my $parser = sub { @@ -598,8 +600,9 @@ sub _extract_order_columns { unless wantarray; my @chunks; - for my $chunk (map { ref $_ ? @$_ : $_ } ($sql_maker->_order_by_chunks ($order_by) ) ) { - $chunk =~ s/\s+ (?: ASC|DESC ) \s* $//ix; + for ($sql_maker->_order_by_chunks ($order_by) ) { + my $chunk = ref $_ ? $_ : [ $_ ]; + $chunk->[0] =~ s/\s+ (?: ASC|DESC ) \s* $//ix; push @chunks, $chunk; }