Subject: | wrong quoting of "order by" fields |
An example means a thousand words ;-)
$ perl -MSQL::Abstract -le 'print scalar SQL::Abstract->new( quote_char
=> q{`}, name_sep => q{.} )->where( { q{foo.id} => 1 }, [ q{foo.name
asc}, q{bar.code}] );'
WHERE ( `foo`.`id` = ? ) ORDER BY `foo`.`name asc`, `bar`.`code`
Please notice the wrong "`foo`.`name asc`" fragment. It should have been:
"`foo`.`name` asc".
Patch attached.
Subject: | sql-abstract-1.22-fix-orderby-quoting.diff |
--- Abstract.pm.1.22 2006-12-08 16:10:56.000000000 +0200
+++ Abstract.pm 2006-12-08 16:25:18.000000000 +0200
@@ -760,7 +760,10 @@
$ref eq '' ? $_[0] :
puke "Unsupported data struct $ref for ORDER BY";
- my $val = join ', ', map { $self->_quote($_) } @vals;
+ my $val = join ', ', map {
+ s/(\s(?i:ASC|DESC))\s*$//;
+ $self->_quote($_) . ($1 || q{})
+ } @vals;
return $val ? $self->_sqlcase(' order by')." $val" : '';
}