Skip to content
Permalink
Browse files

Improving fetchAll method to accept an array of aprameters to be boun…

…d to the query, so now it is possible to use proper prepared statements
  • Loading branch information...
lorenzo committed Oct 17, 2010
1 parent 183e9c9 commit 65a641af23f35120e92a9d56de050e31aac591f7
Showing with 20 additions and 6 deletions.
  1. +20 −6 cake/libs/model/datasources/dbo_source.php
@@ -373,8 +373,7 @@ public function query() {
} else {
$cache = true;
}
$args[1] = array_map(array(&$this, 'value'), $args[1]);
return $this->fetchAll(String::insert($args[0], $args[1]), $cache);
return $this->fetchAll($args[0], $args[1], array('cache' => $cache));
}
}
}
@@ -407,16 +406,31 @@ public function fetchRow($sql = null) {
* Returns an array of all result rows for a given SQL query.
* Returns false if no rows matched.
*
*
* ### Options
*
* - cache - Returns the cached version of the query, if exists and stores the result in cache
*
* @param string $sql SQL statement
* @param boolean $cache Enables returning/storing cached query results
* @param array $params parameters to be bound as values for the SQL statement
* @param array $options additional options for the query.
* @return array Array of resultset rows, or false if no rows matched
*/
public function fetchAll($sql, $cache = true, $modelName = null) {
public function fetchAll($sql, $params = array(), $options = array()) {
if (is_string($options)) {
$options = array('modelName' => $options);
}
if (is_bool($params)) {
$options['cache'] = $params;
$params = array();
}
$defaults = array('cache' => true);
$options = $options + $defaults;
$cache = $options['cache'];
if ($cache && ($cached = $this->getQueryCache($sql)) !== false) {
return $cached;
}
if ($this->execute($sql)) {
if ($this->execute($sql, array(), $params)) {
$out = array();
$first = $this->fetchRow();

0 comments on commit 65a641a

Please sign in to comment.
You can’t perform that action at this time.