From: Peter Rabbitson Date: Thu, 11 Jun 2009 21:39:12 +0000 (+0000) Subject: Factor out as_query properly X-Git-Tag: v0.08106~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e9554c38de5cda0ac04471d3b6e84cbb41976091;p=dbsrgits%2FDBIx-Class.git Factor out as_query properly --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 515e45f..c220dd9 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1927,7 +1927,13 @@ B: This feature is still experimental. sub as_query { my $self = shift; - return $self->result_source->storage->as_query($self->_resolved_attrs); + + my $attrs = $self->_resolved_attrs_copy; + + my ($sqlbind, $bind_attrs) = $self->result_source->storage + ->_select_args_to_query ($attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs); + + return $sqlbind; } =head2 find_or_new diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index c6f13f5..717177c 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -910,37 +910,6 @@ sub _prep_for_execute { return ($sql, \@bind); } -=head2 as_query - -=over 4 - -=item Arguments: $rs_attrs - -=item Return Value: \[ $sql, @bind ] - -=back - -Returns the SQL statement and bind vars that would result from the given -ResultSet attributes (does not actually run a query) - -=cut - -sub as_query { - my ($self, $rs_attr) = @_; - - my $sql_maker = $self->sql_maker; - local $sql_maker->{for}; - - # my ($op, $bind, $ident, $bind_attrs, $select, $cond, $order, $rows, $offset) = $self->_select_args(...); - my @args = $self->_select_args($rs_attr->{from}, $rs_attr->{select}, $rs_attr->{where}, $rs_attr); - - # my ($sql, $bind) = $self->_prep_for_execute($op, $bind, $ident, [ $select, $cond, $order, $rows, $offset ]); - my ($sql, $bind) = $self->_prep_for_execute( - @args[0 .. 2], - [ @args[4 .. $#args] ], - ); - return \[ "($sql)", @{ $bind || [] }]; -} sub _fix_bind_params { my ($self, @bind) = @_; @@ -1227,6 +1196,23 @@ sub _select { return $self->_execute($self->_select_args(@_)); } +sub _select_args_to_query { + my $self = shift; + + my $sql_maker = $self->sql_maker; + local $sql_maker->{for}; + + # my ($op, $bind, $ident, $bind_attrs, $select, $cond, $order, $rows, $offset) + # = $self->_select_args($ident, $select, $cond, $attrs); + my ($op, $bind, $ident, $bind_attrs, @args) = + $self->_select_args(@_); + + # my ($sql, $bind) = $self->_prep_for_execute($op, $bind, $ident, [ $select, $cond, $order, $rows, $offset ]); + my ($sql, $prepared_bind) = $self->_prep_for_execute($op, $bind, $ident, \@args); + + return \[ "($sql)", @{ $prepared_bind || [] }]; +} + sub _select_args { my ($self, $ident, $select, $condition, $attrs) = @_;