[Bast-commits] r9385 - in DBIx-Class/0.08/branches/order_by_func:
lib/DBIx/Class t/bind t/sqlahacks
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Sat May 15 16:07:19 GMT 2010
Author: ribasushi
Date: 2010-05-15 17:07:19 +0100 (Sat, 15 May 2010)
New Revision: 9385
Modified:
DBIx-Class/0.08/branches/order_by_func/lib/DBIx/Class/SQLAHacks.pm
DBIx-Class/0.08/branches/order_by_func/t/bind/order_by.t
DBIx-Class/0.08/branches/order_by_func/t/sqlahacks/order_by_func.t
Log:
Put back code from trunk
Modified: DBIx-Class/0.08/branches/order_by_func/lib/DBIx/Class/SQLAHacks.pm
===================================================================
--- DBIx-Class/0.08/branches/order_by_func/lib/DBIx/Class/SQLAHacks.pm 2010-05-15 16:06:22 UTC (rev 9384)
+++ DBIx-Class/0.08/branches/order_by_func/lib/DBIx/Class/SQLAHacks.pm 2010-05-15 16:07:19 UTC (rev 9385)
@@ -485,6 +485,8 @@
croak "Malformed select argument - too many keys in hash: " . join (',', keys %$fields );
}
+ $func =~ s/^\-+//; # strip leading dash, at some point the dash itself should become mandatory
+
if (lc ($func) eq 'distinct' && ref $args eq 'ARRAY' && @$args > 1) {
croak (
'The select => { distinct => ... } syntax is not supported for multiple columns.'
@@ -575,6 +577,23 @@
]);
}
+sub _order_by_chunks {
+ my ($self, $arg) = @_;
+ if ( # non-empty hash with neither an -asc or a -desc
+ ref $arg eq 'HASH'
+ &&
+ keys %$arg
+ &&
+ ! exists $arg->{-desc}
+ &&
+ ! exists $arg->{-asc}
+ ) {
+ return $self->_recurse_fields ($arg);
+ }
+
+ return $self->SUPER::_order_by_chunks ($arg);
+}
+
sub _table {
my ($self, $from) = @_;
if (ref $from eq 'ARRAY') {
Modified: DBIx-Class/0.08/branches/order_by_func/t/bind/order_by.t
===================================================================
--- DBIx-Class/0.08/branches/order_by_func/t/bind/order_by.t 2010-05-15 16:06:22 UTC (rev 9384)
+++ DBIx-Class/0.08/branches/order_by_func/t/bind/order_by.t 2010-05-15 16:07:19 UTC (rev 9385)
@@ -103,4 +103,3 @@
plan( tests => scalar @tests * 2 );
test_order($_) for @tests;
-
Modified: DBIx-Class/0.08/branches/order_by_func/t/sqlahacks/order_by_func.t
===================================================================
--- DBIx-Class/0.08/branches/order_by_func/t/sqlahacks/order_by_func.t 2010-05-15 16:06:22 UTC (rev 9384)
+++ DBIx-Class/0.08/branches/order_by_func/t/sqlahacks/order_by_func.t 2010-05-15 16:07:19 UTC (rev 9385)
@@ -7,29 +7,45 @@
use DBIC::SqlMakerTest;
my $schema = DBICTest->init_schema();
+$schema->storage->sql_maker->quote_char ('"');
+$schema->storage->sql_maker->name_sep ('.');
my $rs = $schema->resultset('CD')->search({}, {
'join' => 'tracks',
- order_by => {
+ order_by => [
+ { -length => 'me.title' },
+ {
-desc => {
- count => 'tracks.track_id',
+ count => 'tracks.trackid',
},
- },
+ },
+ ],
distinct => 1,
rows => 2,
- page => 1,
+ page => 2,
});
-my $match = q{
- SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me
- GROUP BY me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
- ORDER BY COUNT(tracks.trackid) DESC
-};
-TODO: {
- todo_skip 'order_by using function', 2;
- is_same_sql($rs->as_query, $match, 'order by with func query');
+is_same_sql_bind(
+ $rs->as_query,
+ '(
+ SELECT "me"."cdid", "me"."artist", "me"."title", "me"."year", "me"."genreid", "me"."single_track"
+ FROM cd "me"
+ LEFT JOIN "track" "tracks" ON "tracks"."cd" = "me"."cdid"
+ GROUP BY "me"."cdid", "me"."artist", "me"."title", "me"."year", "me"."genreid", "me"."single_track"
+ ORDER BY
+ LENGTH( "me"."title" ),
+ COUNT( "tracks"."trackid" ) DESC
+ LIMIT 2 OFFSET 2
+ )',
+ [],
+ 'order by with func query',
+);
- ok($rs->count == 2, 'amount of rows return in order by func query');
-}
+ok($rs->count_rs->next == 2, 'amount of rows return in order by func query');
+is_deeply (
+ [ $rs->get_column ('me.title')->all ],
+ [ "Caterwaulin' Blues", "Come Be Depressed With Us" ],
+ 'Correctly ordered stuff by title-length',
+);
done_testing;
More information about the Bast-commits
mailing list