Issues

ZF-1100: Refactor Zend_Db_Select::__toString() method

Issue Type: Improvement Created: 2007-03-21T12:33:18.000+0000 Last Updated: 2008-03-21T16:25:40.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)

Reporter: Bill Karwin (bkarwin) Assignee: Simon Mundy (peptolab) Tags: - Zend_Db_Select

Related issues: Attachments:

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:

<pre class="highlight">
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)

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts