From: Rob Kinyon Date: Tue, 10 Feb 2009 20:23:27 +0000 (+0000) Subject: Added as_query() support to ResultSetColumn X-Git-Tag: v0.08240~63^2~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=658fa250be6ed1944d042ccf985d5c05d41111f6;p=dbsrgits%2FDBIx-Class.git Added as_query() support to ResultSetColumn --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 72af68e..febd181 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1711,6 +1711,14 @@ sub _remove_alias { =head2 as_query +=over 4 + +=item Arguments: none + +=item Return Value: [ $sql, @bind ] + +=back + Returns the SQL query and bind vars associated with the invocant. =cut diff --git a/lib/DBIx/Class/ResultSetColumn.pm b/lib/DBIx/Class/ResultSetColumn.pm index 7b0fee6..f272592 100644 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@ -54,6 +54,22 @@ sub new { return $new; } +=head2 as_query + +=over 4 + +=item Arguments: none + +=item Return Value: [ $sql, @bind ] + +=back + +Returns the SQL query and bind vars associated with the invocant. + +=cut + +sub as_query { return shift->_resultset->as_query } + =head2 next =over 4 @@ -278,7 +294,6 @@ sub _resultset { ); } - 1; =head1 AUTHORS diff --git a/lib/DBIx/Class/Storage/DBI/Cursor.pm b/lib/DBIx/Class/Storage/DBI/Cursor.pm index e067408..6a29f46 100644 --- a/lib/DBIx/Class/Storage/DBI/Cursor.pm +++ b/lib/DBIx/Class/Storage/DBI/Cursor.pm @@ -51,6 +51,14 @@ sub new { =head2 as_query +=over 4 + +=item Arguments: none + +=item Return Value: [ $sql, @bind ] + +=back + Returns the SQL statement and bind vars associated with the invocant. =cut diff --git a/t/resultset/as_query.t b/t/resultset/as_query.t index d5baabf..23f301f 100644 --- a/t/resultset/as_query.t +++ b/t/resultset/as_query.t @@ -7,7 +7,7 @@ use Test::More; use lib qw(t/lib); use DBICTest; -plan tests => 6; +plan tests => 8; my $schema = DBICTest->init_schema(); my $art_rs = $schema->resultset('Artist'); @@ -40,4 +40,14 @@ $art_rs = $art_rs->search({ rank => 2 }); is_deeply( \@bind, [ [ rank => 2 ], [ name => 'Billy Joel' ] ] ); } +my $rscol = $art_rs->get_column( 'charfield' ); + +{ + my $arr = $rscol->as_query; + my ($query, @bind) = @$arr; + + is( $query, "SELECT me.charfield FROM artist me WHERE ( ( ( rank = ? ) AND ( name = ? ) ) )" ); + is_deeply( \@bind, [ [ rank => 2 ], [ name => 'Billy Joel' ] ] ); +} + __END__