« Return to Thread: Adding SELECT options to Zend_Db_Select

Re: Adding SELECT options to Zend_Db_Select

by Bill Karwin :: Rate this Message:

Reply to Author | View in Thread


Hector Virgen wrote:
I want to be able to produce the following SELECT statement:

SELECT *SQL_CALC_FOUND_ROWS* * FROM table LIMIT 10;

I've considered subclassing Zend_Db_Select to handle this, but I would
have to redefine __toString() to support this.
SQL_CALC_FOUND_ROWS is a MySQL proprietary thing, and adding it to Zend_Db_Select would break on other RDBMS brands.  In general, Zend_Db_Select supports only ANSI SQL syntax (except for the limit() functionality).

Take a closer look at Zend_Db_Select.  It has been refactored in recent months to make it easier to do what you're describing in a subclass.  You shouldn't have to change __toString(), just do this:
- add a key to the $_partsInit array for the option you want; it probably belongs before DISTINCT
- add functions  sqlCalcFoundRows() and _renderSqlCalcFoundRows()

See functions distinct() and _renderDistinct() as examples.

Regards,
Bill Karwin

 « Return to Thread: Adding SELECT options to Zend_Db_Select