Permalink
Browse files

Allow object results to be chosen during execute(). Fixes #3227

  • Loading branch information...
1 parent e303e81 commit f8abadbcf3a3a7c3f22b6f6e13ba1a4973346f9c @cbandy cbandy committed Jul 3, 2011
Showing with 16 additions and 3 deletions.
  1. +16 −3 classes/kohana/database/query.php
@@ -199,18 +199,31 @@ public function compile(Database $db)
* Execute the current query on the given database.
*
* @param mixed Database instance or name of instance
+ * @param string result object classname, TRUE for stdClass or FALSE for array
+ * @param array result object constructor arguments
+ *
* @return object Database_Result for SELECT queries
* @return mixed the insert id for INSERT queries
* @return integer number of affected rows for all other queries
*/
- public function execute($db = NULL)
+ public function execute($db = NULL, $as_object = NULL, $object_params = NULL)
{
if ( ! is_object($db))
{
// Get the database instance
$db = Database::instance($db);
}
+ if ($as_object === NULL)
+ {
+ $as_object = $this->_as_object;
+ }
+
+ if ($object_params === NULL)
+ {
+ $object_params = $this->_object_params;
+ }
+
// Compile the SQL query
$sql = $this->compile($db);
@@ -224,12 +237,12 @@ public function execute($db = NULL)
AND ! $this->_force_execute)
{
// Return a cached result
- return new Database_Result_Cached($result, $sql, $this->_as_object, $this->_object_params);
+ return new Database_Result_Cached($result, $sql, $as_object, $object_params);
}
}
// Execute the query
- $result = $db->query($this->_type, $sql, $this->_as_object, $this->_object_params);
+ $result = $db->query($this->_type, $sql, $as_object, $object_params);
if (isset($cache_key) AND $this->_lifetime > 0)
{

0 comments on commit f8abadb

Please sign in to comment.