On Mon, 23 Apr 2007 02:25:33 -0400
"Bugs in SQL-Abstract-Limit via RT"
<bug-SQL-Abstract-Limit@rt.cpan.org> wrote:
Show quoted text>
> Greetings,
>
> This message has been automatically generated in response to the
> creation of a trouble ticket regarding:
> "Spaces in column name fails with order_by",
> a summary of which appears below.
>
> There is no need to reply to this message right now. Your ticket has
> been assigned an ID of [rt.cpan.org #26558]. Your ticket is
> accessible on the web at:
>
>
http://rt.cpan.org/Ticket/Display.html?id=26558
>
> Please include the string:
>
> [rt.cpan.org #26558]
>
> in the subject line of all future correspondence about this issue. To
> do so, you may reply to this message.
>
> Thank you,
> bug-SQL-Abstract-Limit@rt.cpan.org
>
> -------------------------------------------------------------------------
> I think the split
>
> foreach my $spec ( @order )
> {
> my @spec = split ' ', $spec;
> croak( "bad column order spec: $spec" ) if @spec > 2;
> push( @spec, 'ASC' ) unless @spec == 2;
> my ( $col, $up ) = @spec; # or maybe down
> $up = uc( $up );
> croak( "bad direction: $up" ) unless $up =~ /^(?:ASC|DESC)$/;
> $order_by_up .= ", $col $up";
> my $down = $up eq 'ASC' ? 'DESC' : 'ASC';
> $order_by_down .= ", $col $down";
> }
>
> is causing me grief. My spec is passed with:
>
> order_by =>\'"Invoice #" DESC',
>
> because I have quoting turned on for the column names with spaces.
> Using DBIx::Class.
>
> Error is SCALAR0xXXXXXX is a bad column name, or the error above when
> I don't use the leading \.
>
> Works as it should unless I'm trying to do paged resultsource. So, I
> don't know what actually causes it.
>
> Cheers,
>
Well, I spent a chunk of the workday figuring this out. Indeed, the
problem is with that split. You (I think) need to have a further case
when the elements in @spec is exactly one scalar reference.
When the order_by directive has a quoted column name, it gets passed by
reference, according to DBIx-Class-Resultset... so,
foreach my $spec ( @order )
{
my @spec;
my ($col, $up);
if (! ref $spec){
@spec = split ' ', $spec;
Carp::croak( "bad column order spec: $spec" ) if @spec > 2;
push( @spec, 'ASC' ) unless @spec == 2;
( $col, $up ) = @spec; # or maybe down
}else {
my $lastspace = (rindex $$spec, ' ') +1;
$col = substr $$spec, 0, $lastspace;
$up = substr $$spec, $lastspace;
}
$up = uc( $up );
Carp::croak( "bad direction: $up" ) unless $up
=~ /^(?:ASC|DESC)$/; $order_by_up .= ", $col $up";
my $down = $up eq 'ASC' ? 'DESC' : 'ASC';
$order_by_down .= ", $col $down";
}
s/^,/ORDER BY/ for ( $order_by_up, $order_by_down );
return $order_by_up, $order_by_down;
}
... fixed the problem for me, so far... sloppy though it may be.
Does that illustrate the problem enough?
I don't know what other expected behavior this would break, but I'd love
to know I'll not have to worry about the next release breaking my
program either.
Cheers,
--
|\ /| | | ~ ~
| \/ | |---| `|` ?
| |ichael | |iggins \^ /
michael.higgins[at]evolone[dot]org