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

such as "order by me.year desc" => 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
===================================================================
--- 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` = `me`.`artist` ) WHERE ( `artist`.`name` = ?
AND `me`.`year` = ? )\E/, 'got correct SQL for count query with
quoting');

-my $order = 'year DESC';
+my $order = 'me.year DESC';
 $rs = DBICTest::CD->search({},
             { 'order_by' => $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 = DBICTest::CD->search({},
             { 'order_by' => \$order });

This one fixes it.

Index: lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- 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
Index: t/19quotes_newstyle.t
===================================================================
--- t/19quotes_newstyle.t	(revision 2968)
+++ t/19quotes_newstyle.t	(working copy)
@@ -40,7 +40,7 @@
 $rs = DBICTest::CD->search({},
             { 'order_by' => $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 `year` DESC/, 'quoted ORDER BY with DESC (should use a scalarref anyway)');
 
 $rs = DBICTest::CD->search({},
             { 'order_by' => \$order });
Index: t/19quotes.t
===================================================================
--- 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` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )\E/, 'got correct SQL for count query with quoting');
 
-my $order = 'year DESC';
+my $order = 'me.year DESC';
 $rs = DBICTest::CD->search({},
             { 'order_by' => $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 = DBICTest::CD->search({},
             { 'order_by' => \$order });
Index: lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- 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));
 }
 
 sub limit_dialect {
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to