From: Cory G Watson Date: Thu, 9 Mar 2006 22:35:19 +0000 (+0000) Subject: Allow scalarefs passed to order_by to pass straight through to SQL X-Git-Tag: v0.06000~60^2~36 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e535069e2685255d87c39b39d5f91f00a2548f3a;p=dbsrgits%2FDBIx-Class.git Allow scalarefs passed to order_by to pass straight through to SQL --- diff --git a/Changes b/Changes index e44d12d..fcd74b5 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for DBIx::Class +0.05990_01 Pending + - allow scalarefs passed to order_by to go straight through to SQL - renamed insert_or_update to update_or_insert (with compat alias) 0.05999_01 2006-03-09 18:31:44 diff --git a/README b/README index 1d8dc58..7ff6476 100644 --- a/README +++ b/README @@ -124,6 +124,8 @@ CONTRIBUTORS Scott McWhirter (konobi) + Cory Watson (gphat) + LICENSE You may distribute this code under the same terms as Perl itself. diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index e733b53..03f3a6c 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -68,6 +68,8 @@ sub _order_by { if (defined $_[0]->{order_by}) { $ret .= $self->SUPER::_order_by($_[0]->{order_by}); } + } elsif(ref $_[0] eq 'SCALAR') { + $ret = $self->_sqlcase(' order by ').${ $_[0] }; } else { $ret = $self->SUPER::_order_by(@_); } diff --git a/t/19quotes.t b/t/19quotes.t index 70c8f8e..18588c8 100644 --- a/t/19quotes.t +++ b/t/19quotes.t @@ -6,7 +6,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 4 ); + : ( tests => 6 ); } use lib qw(t/lib); @@ -24,6 +24,26 @@ my $rs = DBICTest::CD->search( cmp_ok( $rs->count, '==', 1, "join with fields quoted"); +$rs = DBICTest::CD->search({}, + { 'order_by' => 'year DESC'}); +{ + my $warnings; + local $SIG{__WARN__} = sub { $warnings .= $_[0] }; + my $first = eval{ $rs->first() }; + ok( $warnings =~ /ORDER BY terms/, "Problem with ORDER BY quotes" ); +} + +my $order = 'year DESC'; +$rs = DBICTest::CD->search({}, + { 'order_by' => \$order }); +{ + my $warnings; + local $SIG{__WARN__} = sub { $warnings .= $_[0] }; + my $first = $rs->first(); + ok( $warnings !~ /ORDER BY terms/, + "No problem handling ORDER by scalaref" ); +} + DBICTest->schema->storage->sql_maker->quote_char([qw/[ ]/]); DBICTest->schema->storage->sql_maker->name_sep('.');