X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet.pm;h=f71743573d39fd109343b0ddace5c796c2ff9c9d;hb=c7a9d1027d40e6b3275cb26db68141b152f3bd13;hp=edd9bd3630ca7cbb1160d552853f24fec732bc60;hpb=70eb901c022556ae982cbd55b4f738af20d2a302;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index edd9bd3..f717435 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1723,7 +1723,54 @@ Returns the SQL query and bind vars associated with the invocant. =cut -sub as_query { return shift->cursor->as_query } +sub as_query { return shift->cursor->as_query(@_) } + +=head2 as_subselect + +=over 4 + +=item Arguments: none + +=item Return Value: \[ $sql, @bind ] + +=back + +Returns the SQL query and bind vars associated with the invocant. + +The SQL will be wrapped in parentheses, ready for use as a subselect. + +=cut + +sub as_subselect { + my $self = shift; + my $arr = ${$self->as_query(@_)}; + $arr->[0] = '( ' . $arr->[0] . ' )'; + return \$arr; +} + +=head2 as_query + +=over 4 + +=item Arguments: none + +=item Return Value: $sql + +=back + +Returns the SQL query associated with the invocant. All bind vars +will have been bound using C<< DBI->quote() >>. + +=cut + +sub as_sql { + my $self = shift; + my $arr = ${$self->as_query(@_)}; + my $sql = shift @$arr; + my $dbh = $self->result_source->schema->storage->dbh; + $sql =~ s/\?/$dbh->quote((shift @$arr)->[1])/eg; + return $sql +} =head2 find_or_new