[Dbix-class] Updated test for quoted sort by.

Jesper Krogh jesper at krogh.cc
Thu Dec 14 10:15:41 GMT 2006


This test failes.. when adding the "aliased" prefix of the sort column.

such as "order by me.year desc" =3D> order by `me`.`year` desc

Basically a resend, if was discussed a bit earlier with some added syntax
of handling this stuff.

Index: t/19quotes.t
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- t/19quotes.t        (revision 2968)
+++ t/19quotes.t        (working copy)
@@ -37,11 +37,11 @@
 eval { $rs->count };
 like($sql, qr/\QSELECT COUNT( * ) FROM `cd` `me`  JOIN `artist` `artist`
ON ( `artist`.`artistid` =3D `me`.`artist` ) WHERE ( `artist`.`name` =3D ?
AND `me`.`year` =3D ? )\E/, 'got correct SQL for count query with
quoting');

-my $order =3D 'year DESC';
+my $order =3D 'me.year DESC';
 $rs =3D DBICTest::CD->search({},
             { 'order_by' =3D> $order });
 eval { $rs->first };
-like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC
(should use a scalarref anyway)');
+like($sql, qr/ORDER BY `me`.`year` DESC/, 'quoted ORDER BY with DESC
(should use a scalarref anyway)');

 $rs =3D DBICTest::CD->search({},
             { 'order_by' =3D> \$order });

This one fixes it.

Index: lib/DBIx/Class/Storage/DBI.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/DBIx/Class/Storage/DBI.pm       (revision 2968)
+++ lib/DBIx/Class/Storage/DBI.pm       (working copy)
@@ -264,7 +264,7 @@
         map { $self->{quote_char}->[0] . $_ . $self->{quote_char}->[1]  }
        split(/\Q$sep\E/,$label));
   }
-  return $self->SUPER::_quote($label);
+  return join(" ",map { $_ !~ /^(asc|desc)$/i ? $self->SUPER::_quote($_)
: $_ } split(" ",$label));
 }


Patch attached.




-- =

Jesper Krogh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: prefix-table-order-by.patch
Type: text/x-patch
Size: 1924 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20061214/94=
d7a3bc/prefix-table-order-by.bin


More information about the Dbix-class mailing list