From: Peter Rabbitson Date: Fri, 5 Feb 2010 07:59:04 +0000 (+0000) Subject: Refactor some evil code X-Git-Tag: v0.08116~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c07482800ba8221bedd89f854dc56da865f7692f;p=dbsrgits%2FDBIx-Class.git Refactor some evil code --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 68b7d9b..c0c758f 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2851,14 +2851,10 @@ sub _resolved_attrs { my %already_grouped = map { $_ => 1 } (@{$attrs->{group_by}}); my $storage = $self->result_source->schema->storage; - my $sql_maker = $storage->sql_maker; - local $sql_maker->{quote_char}; #disable quoting my $rs_column_list = $storage->_resolve_column_info ($attrs->{from}); - my @chunks = $sql_maker->_order_by_chunks ($attrs->{order_by}); - for my $chunk (map { ref $_ ? @$_ : $_ } (@chunks) ) { - $chunk =~ s/\s+ (?: ASC|DESC ) \s* $//ix; + for my $chunk ($storage->_parse_order_by($attrs->{order_by})) { if ($rs_column_list->{$chunk} && not $already_grouped{$chunk}++) { push @{$attrs->{group_by}}, $chunk; } diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index ccd1cf2..a597576 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1833,7 +1833,7 @@ sub _select_args { && (ref $ident eq 'ARRAY' && @$ident > 1) # indicates a join && - scalar $sql_maker->_order_by_chunks ($attrs->{order_by}) + scalar $self->_parser_order_by ($attrs->{order_by}) ) { # the RNO limit dialect above mangles the SQL such that the join gets lost # wrap a subquery here diff --git a/lib/DBIx/Class/Storage/DBI/MSSQL.pm b/lib/DBIx/Class/Storage/DBI/MSSQL.pm index 3ce11e6..8bd0d45 100644 --- a/lib/DBIx/Class/Storage/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Storage/DBI/MSSQL.pm @@ -190,7 +190,7 @@ sub _select_args_to_query { # see if this is an ordered subquery my $attrs = $_[3]; - if ( scalar $self->sql_maker->_order_by_chunks ($attrs->{order_by}) ) { + if ( scalar $self->_parse_order_by ($attrs->{order_by}) ) { $self->throw_exception( 'An ordered subselect encountered - this is not safe! Please see "Ordered Subselects" in DBIx::Class::Storage::DBI::MSSQL ') unless $attrs->{unsafe_subselect_ok}; diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index 331474f..44ad59b 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -228,10 +228,7 @@ sub _resolve_aliastypes_from_select_args { my $group_by_sql = $sql_maker->_order_by({ map { $_ => $attrs->{$_} } qw/group_by having/ }); - my @order_by_chunks = (map - { ref $_ ? $_->[0] : $_ } - $sql_maker->_order_by_chunks ($attrs->{order_by}) - ); + my @order_by_chunks = ($self->_parse_order_by ($attrs->{order_by}) ); # match every alias to the sql chunks above for my $alias (keys %$alias_list) { @@ -487,5 +484,21 @@ sub _strip_cond_qualifiers { return $cond; } +sub _parse_order_by { + my ($self, $order_by) = @_; + + return scalar $self->sql_maker->_order_by_chunks ($order_by) + unless wantarray; + + my $sql_maker = $self->sql_maker; + local $sql_maker->{quote_char}; #disable quoting + my @chunks; + for my $chunk (map { ref $_ ? @$_ : $_ } ($sql_maker->_order_by_chunks ($order_by) ) ) { + $chunk =~ s/\s+ (?: ASC|DESC ) \s* $//ix; + push @chunks, $chunk; + } + + return @chunks; +} 1;