Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 0.9.0
-
Fix Version/s: 1.5.0
-
Component/s: Zend_Db_Select
-
Labels:None
-
Fix Version Priority:Nice to Have
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"; } } }
Assigning to Mark Gibson. Thanks Mark!