Skip Menu |

This queue is for tickets about the SQL-Abstract CPAN distribution.

Report information
The Basics
Id: 23859
Status: resolved
Priority: 0/
Queue: SQL-Abstract

People
Owner: nwiger [...] cpan.org
Requestors: altblue [...] n0i.net
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.22
Fixed in: 1.51



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" : ''; }
Resolved in SQL::Abstract 1.23, destined for CPAN today.
On Fri Dec 08 09:28:31 2006, altblue@n0i.net wrote: Show quoted text
> 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".
That isn't wrong. 'name asc' is a valid column name and we correctly quote it. Your patch introduces a bug, it doesn't fix one. However, a means to provide ASC/DESC should be supported; the current plan is to support both \'foo ASC' and { -asc => 'foo' }; if you have any better suggestions for syntax please start a separate wishlist bug for this. Since this is actually correct behaviour on SQLA 1.22's part, I'm marking this ticket rejected.