ZF-1100: Refactor Zend_Db_Select::__toString() method
Description
Extending behavior of Zend_Db_Select for rendering a query to a string, or supporting RDBMS-specific syntax, requires rewriting the whole __toString() method.
What I think we need to do is make it easier to extend Zend_Db_Select by breaking __toString() down into separate methods for each section of the statement, and allow setting of the class returned by select() in the adapter.
Then for situations such as DISTINCT ON support, the solution would be the following:
class MyExtendedSelect extends Zend_Db_Select
{
public function distinctOn(array $columns)
{
$this->_parts[self::DISTINCT] = $columns;
return $this;
}
protected function _distinctToString() {
if (is_array($this->_parts[self::DISTINCT])) {
$sql .= " DISTINCT ON " . /* serialize columns here */;
} else if ($this->_parts[self::DISTINCT] === true) {
$sql .= " DISTINCT";
}
}
}
Comments
Posted by Bill Karwin (bkarwin) on 2007-03-21T12:34:00.000+0000
Assigning to Mark Gibson. Thanks Mark!
Posted by Bill Karwin (bkarwin) on 2007-10-17T15:30:50.000+0000
I wrote a prototype implementation of this refactoring. It's in the ZF Laboratory svn repository:
http://framework.zend.com/fisheye/browse/…
Posted by Simon Mundy (peptolab) on 2008-02-16T19:45:11.000+0000
Resolved in trunk r8084
NOTE: The method names are simply:-
_renderFrom() _renderWhere() ...etc..
(the 'toString' seemed superfluous)