[Solar-talk] Solar_Sql_Select bug
Jeff Moore
jeff at mashery.com
Sat May 17 18:19:59 CDT 2008
On May 17, 2008, at 3:20 PM, Paul M Jones wrote:
> Hi Jeff,
>
> On May 14, 2008, at 14:34 , Jeff Moore wrote:
>
>> I found a small bug. This code fails to detect an parenthesis in
>> position 0.
>>
>> Solar/Sql/Select.php:1043
>> $parens = strpos($col, '(');
>>
>> // choose our column-name deconfliction strategy
>> if ($prefix == '' || $parens || $count_sources == 1) {
>>
>> You could use
>>
>> $parens = (strpos($col, '(') === FALSE);
>>
>> To fix the bug
>
> This check is in place to see if an SQL function is being used
> (noted in a comment on line 1042). Yes, just looking for a
> parenthesis is naive. ;-) However, if the paren is the first char
> in the string, it's not likely related to an SQL function.
>
> Did you run into a situation where this caused you some trouble?
Yes and no. I was using table aliases to do a self join, but using the
syntax "tbl_name alias_name'. This resulted in a syntax error prefix
to the columns I was joining. So, my first instinct was to put the
column name in parenthesis to prevent the automatic prefixing of
column names. This was basically a guess knowing that count() didn't
get prefixed, not informed by looking at the code or any
documentation. What I didn't realize at first was that the 'tbl_name
AS alias_name" syntax was supported, which I found after I had to dig
in the code to figure out why the parenthesis weren't working, shortly
after my prior post.
Jeff
More information about the Solar-talk
mailing list