ZF-8504: DB_Select "AS" Problem
Description
File: Zend/Db/Select.php
935 // Check for a column matching " AS " and extract the alias name 936 if (preg_match('/^(.+)\s+' . self::SQL_AS . '\s+(.+)$/i', $col, $m)) {
the preg_match makes problems if you have a function with an "AS" in the column part
example:
$select = $DB->select( )->from( 'table', array( 'Id', 'ColumnAlias' => 'CAST( Column AS SIGNED )' ) );
sql result: SELECT table.Id, table.CAST( Column AS SIGNED ) FROM table
you can fix it with 936 if (preg_match('/^(.+)\s+' . self::SQL_AS . '\s+(.[^\s' . self::SQL_AS . '\s])$/i', $col, $m)) {
Comments
Posted by Ramon Henrique Ornelas (ramon) on 2009-12-09T10:10:06.000+0000
Your regex is flawed because it used a list.
[as] equivalent the a|s
Test in
Posted by Ramon Henrique Ornelas (ramon) on 2009-12-09T10:11:28.000+0000
Try use
CAST(column) AS alias.
Posted by Ingo (ingo) on 2009-12-09T10:27:32.000+0000
what do you mean with List? I have tested this regex with some querys and all works fine
Posted by Ramon Henrique Ornelas (ramon) on 2009-12-09T10:45:59.000+0000
Any alias preceded by an element of the list.
problem in ^(.+)\s+AS\s+(.+[^\sAS\s])$
Test 1: column AS xxs
Test 2: column AS dda
Posted by Rob Allen (rob) on 2012-11-20T20:53:17.000+0000
Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".
Feel free to re-open and provide a patch if you want to fix this issue.