You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Kee Hinckley <na...@somewhere.com> on 2002/06/21 08:56:31 UTC
DBIx::Recordset patch for select xxxx AS foo
Currently if you do something like:
select year(pubdate) as year;
you can't refer to $set->{year}, instead it's $set->{'year(pubdate)
as year'}. I didn't make this an option, perhaps it should be, but
in any case, if you add the following line to SQLSelect just before
the check for LongNames, that will fix this case.
$fields = join(',', map { (/\bAS\s+(.*)\s*$/i)?$1:$_} split
(/\s*,\s*/, $fields));
Note however that there is a bug that has existed before this.
Namely if the expression to the left of the AS has a comma in it, the
whole field parsing code is going to fall apart. I'm pretty sure
that there will only ever be a comma inside of parenthesis, so it
should be possible to fix that, but I'm not going to try at three in
the morning.
--
Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/
I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: DBIx::Recordset patch for select xxxx AS foo
Posted by Kee Hinckley <na...@somewhere.com>.
At 9:57 PM +0200 6/25/02, Gerald Richter wrote:
> > At Fri, 21 Jun 2002 02:56:31 -0400, Kee Hinckley wrote:
>> > Currently if you do something like:
>> > select year(pubdate) as year;
>> > you can't refer to $set->{year}, instead it's $set->{'year(pubdate)
>> > as year'}.
>>
>> i have used column aliasing (or whatever its called) without even
>> thinking about it, and its worked fine (using postgres/DBD::Pg).
>>
>
>Same for me. I never had a problem with it. Kee, which database are you
>using? Do you use LongNames ?
mysql. It could be that LongNames is throwing it off, I'll take
another look at the code.
--
Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/
I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: DBIx::Recordset patch for select xxxx AS foo
Posted by Gerald Richter <ri...@ecos.de>.
> At Fri, 21 Jun 2002 02:56:31 -0400, Kee Hinckley wrote:
> > Currently if you do something like:
> > select year(pubdate) as year;
> > you can't refer to $set->{year}, instead it's $set->{'year(pubdate)
> > as year'}.
>
> i have used column aliasing (or whatever its called) without even
> thinking about it, and its worked fine (using postgres/DBD::Pg).
>
Same for me. I never had a problem with it. Kee, which database are you
using? Do you use LongNames ?
Gerald
-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting
Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925131
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: DBIx::Recordset patch for select xxxx AS foo
Posted by Angus Lees <gu...@switchonline.com.au>.
At Fri, 21 Jun 2002 02:56:31 -0400, Kee Hinckley wrote:
> Currently if you do something like:
> select year(pubdate) as year;
> you can't refer to $set->{year}, instead it's $set->{'year(pubdate)
> as year'}.
i have used column aliasing (or whatever its called) without even
thinking about it, and its worked fine (using postgres/DBD::Pg).
iirc, DBIx::Recordset uses the column names as returned by
fetchrow_hashref (or similar), so you might want to check that your
database/driver correctly supports column alia there.
> Note however that there is a bug that has existed before this.
> Namely if the expression to the left of the AS has a comma in it, the
> whole field parsing code is going to fall apart.
i posted a patch for that in january (message id:
<20...@switchonline.com.au>). it didn't actually fix
the problem, just made it a little more robust by ignoring things that
weren't column names..
one line patch repeated here:
Index: Recordset.pm
===================================================================
RCS file: /var/lib/cvs/debian/libdbix-recordset-perl/Recordset.pm,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 Recordset.pm
--- Recordset.pm 23 Dec 2001 07:01:03 -0000 1.1.1.2
+++ Recordset.pm 2 Jan 2002 01:39:40 -0000
@@ -1801,7 +1801,7 @@
if (defined ($fields) && !($fields =~ /^\s*\*\s*$/))
{
#@allfields = map { (/\./)?$_:"$tab4f->{$_}.$_" } split (/\s*,\s*/, $fields) ;
- @allfields = map { (/\./)?$_:"$tab4f->{$_}.$_" } quotewords ('\s*,\s*', 0, $fields) ;
+ @allfields = map { (/\./ || !$tab4f->{$_})?$_:"$tab4f->{$_}.$_" } quotewords ('\s*,\s*', 0, $fields) ;
#print LOG "###allfields = @allfields\n" ;
}
else
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org