From: Peter Rabbitson Date: Thu, 7 May 2009 09:58:14 +0000 (+0000) Subject: Back out skip_parens support in as_query X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=428a645e8c8a91d4182ff70482d10c354b44df45;p=dbsrgits%2FDBIx-Class-Historic.git Back out skip_parens support in as_query --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 4f8f35f..e231107 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1333,7 +1333,7 @@ sub _cond_for_update_delete { return $cond unless ref $full_cond; foreach my $pk ($self->result_source->primary_columns) { - $cond->{$pk} = { IN => $self->get_column($pk)->as_query({ skip_parens => 1 }) }; + $cond->{$pk} = { -in => $self->get_column($pk)->as_query }; } return $cond; @@ -1810,7 +1810,7 @@ sub _remove_alias { =over 4 -=item Arguments: \%opts +=item Arguments: none =item Return Value: \[ $sql, @bind ] @@ -1822,14 +1822,6 @@ This is generally used as the RHS for a subquery. B: This feature is still experimental. -The query returned will be surrounded by parentheses, e.g: - - ( SELECT cdid FROM cd WHERE title LIKE '%Hits%' ) - -This behaviour can be changed by passing special options: - - $rs->get_column('cdid')->as_query({ skip_parens => 1 }); - =cut sub as_query { return shift->cursor->as_query(@_) } diff --git a/lib/DBIx/Class/ResultSetColumn.pm b/lib/DBIx/Class/ResultSetColumn.pm index 646e084..2679803 100644 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@ -58,7 +58,7 @@ sub new { =over 4 -=item Arguments: See L +=item Arguments: none =item Return Value: \[ $sql, @bind ] diff --git a/lib/DBIx/Class/Storage/DBI/Cursor.pm b/lib/DBIx/Class/Storage/DBI/Cursor.pm index 454738c..60df379 100644 --- a/lib/DBIx/Class/Storage/DBI/Cursor.pm +++ b/lib/DBIx/Class/Storage/DBI/Cursor.pm @@ -53,7 +53,7 @@ sub new { =over 4 -=item Arguments: See L +=item Arguments: none =item Return Value: \[ $sql, @bind ] @@ -64,12 +64,7 @@ Returns the SQL statement and bind vars associated with the invocant. =cut sub as_query { - my ( $self, $opts ) = @_; - - $self->throw_exception( "as_query needs a hashref" ) - if defined $opts and ref $opts ne 'HASH'; - - $opts->{skip_parens} ||= 0; + my $self = shift; my $storage = $self->{storage}; my $sql_maker = $storage->sql_maker; @@ -77,8 +72,7 @@ sub as_query { my @args = $storage->_select_args(@{$self->{args}}); my ($sql, $bind) = $storage->_prep_for_execute(@args[0 .. 2], [@args[4 .. $#args]]); - $sql = "($sql)" unless $opts->{skip_parens}; - return \[ $sql, @$bind ]; + return \[ "($sql)", @$bind ]; } =head2 next diff --git a/t/resultset/as_query.t b/t/resultset/as_query.t index 4d593de..c496085 100644 --- a/t/resultset/as_query.t +++ b/t/resultset/as_query.t @@ -7,7 +7,7 @@ use Data::Dumper; use Test::More; -plan ( tests => 6 ); +plan ( tests => 4 ); use lib qw(t/lib); use DBICTest; @@ -65,21 +65,3 @@ my $rscol = $art_rs->get_column( 'charfield' ); [ [ rank => 2 ], [ name => 'Billy Joel' ] ], ); } - -{ - my $rs = $schema->resultset("CD")->search( - { 'artist.name' => 'Caterwauler McCrae' }, - { join => [qw/artist/]} - ); - my $query = $rs->get_column('cdid')->as_query({ skip_parens => 1 }); - my ($sql, @bind) = @{$$query}; - is_same_sql_bind( - $sql, \@bind, - 'SELECT me.cdid FROM cd me JOIN artist artist ON artist.artistid = me.artist WHERE ( artist.name = ? )', - [['artist.name' => 'Caterwauler McCrae']] - ); - my $subsel_rs = $schema->resultset("CD")->search( { cdid => { IN => $query } } ); - is($subsel_rs->count, $rs->count, 'Subselect on PK got the same row count'); -} - -__END__