ZF-197: Zend_Db_Select: new method reset()
Description
It can be useful to be able to reset just a part of a select object instead of creating a new one.
For example I construct a select, run the query and get no results. I then want to run the same query again with just a slight modification of the WHERE clause. Currently I have to construct a new select object because there are no ways of resetting a part of the select.
It could be done this way:
/**
* Resets a part of the SELECT statement to null, so you can set it again without creating a new Select object
*
* @param string $part The part to reset (e.g. 'where', 'limit', etc.)
* @return true on success, otherwise false
*/
public function resetPart($part)
{
// find part in private $_parts array
if(in_array($part, $this->_parts)) {
// reset it
$this->_parts[$part] = null;
return true;
} else {
// part not found, so return false
return false;
}
}
Comments
Posted by Christian Münch (cmuench) on 2006-07-10T12:03:05.000+0000
I also think that the parts must be accessible. Zend_Db_Select should offer some setter or getter methods to change i.e. the columns. We want to create a DB pager class with Zend_Db_Select. In the pager class the limitPage Method is very usefull, but we need to reset some parts.
Posted by Gavin (gavin) on 2006-10-24T16:22:30.000+0000
The solution for ZF-1 will provide a large portion of the solution to this problem. In order to properly submit ZF "where" clauses and other data collected programmatically through an OO interface to a DB driver in a format suitable for prepared queries (if supported by that driver), all parts of the SQL query need to be kept separated, instead of combined into a string. If the parts collected via the programmatic interface are stored individually, the parts can then be quoted correctly (e.g. quoting for column names is not always the same for other identifiers, depending on the DB). Additional API methods could then be added to get and set the parts of the query.
Creating a programmatic interface that offers the above features without becoming more difficult than using raw SQL with PHP's PDO object will not be a simple task. Contact the ZF DB Project Team, if you would like to help!
http://framework.zend.com/wiki/display/…
Posted by Bill Karwin (bkarwin) on 2006-11-13T15:22:38.000+0000
Changing fix version to 0.8.0.
Posted by Bill Karwin (bkarwin) on 2007-01-05T17:02:21.000+0000
Recategorize in Zend_Db_Select component.
Posted by Shekar Reddy (zendfw) on 2007-01-29T04:28:20.000+0000
I guess the following would be more ideal as it resets a specific part or the entire parts array optionally:
[code] /** * Resets a part of the SELECT statement to null, so you can set it again without creating a new Select object * * @param string $part The part to reset (e.g. 'where', 'limit', etc.) * @return true on success, otherwise false */
Posted by Shekar Reddy (zendfw) on 2007-01-29T04:46:35.000+0000
Applied the right code tags:
I guess the following would be more ideal as it resets a specific part or the entire parts array optionally:
``` /** * Resets a part of the SELECT statement to null, so you can set it again without creating a new Select object * * @param string $part The part to reset (e.g. 'where', 'limit', etc.) * @return true on success, otherwise false */
Posted by Bill Karwin (bkarwin) on 2007-02-08T20:43:17.000+0000
Fixed in revision 3320.
New method {{reset()}} clears all parts internal to the Select object. With a parameter, it clears one individual part. For example:
There are also constants defined to make it easier to name the parts. For example:
Posted by Bill Karwin (bkarwin) on 2007-02-08T20:44:39.000+0000
Change summary wording.