ZF-2316: Allow NULL columns in Select object
Description
A simple modification to the Select object __toString() method can allow the setting of NULL columns when constructing the SQL string. Specifically changing: (line 137)
...
list($correlationName, $column, $alias) = $columnEntry;
if ($column instanceof Zend_Db_Expr) {
$columns[] = $this->_adapter->quoteColumnAs($column, $alias, true);
} else {
....
into:
...
list($correlationName, $column, $alias) = $columnEntry;
if(is_null($column)){
$columns[] = 'NULL';
} else if ($column instanceof Zend_Db_Expr) {
$columns[] = $this->_adapter->quoteColumnAs($column, $alias, true);
} else {
...
would allow setting NULL columns by passing a 'null' value as an array value in the column correlation array.
I needed this modification since I sometimes use the Select object to construct SQL strings to be used as parts in a larger UNION query. In a UNION, the number of columns for each composing SELECT query has to match, sometimes requiring setting columns as NULL. Others might find this useful for various reasons.
Comments
Posted by Eran Galperin (erangalp) on 2008-01-20T21:34:12.000+0000
Is a patch commit of this planned? Or do I need to continue patching Zend_Db_Select with new releases...
Posted by Thomas Weidner (thomas) on 2008-02-08T14:35:56.000+0000
Integrated with SVN-7869