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

Your regex is flawed because it used a list.

[as] equivalent the a|s

Test in

Try use

CAST(column) AS alias.

what do you mean with List? I have tested this regex with some querys and all works fine

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

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.