Browse Source

Making Connection accepts Query objects

Juan Basso 12 years ago
parent
commit
d0cb098c39
2 changed files with 5 additions and 2 deletions
  1. 4 1
      src/Database/Connection.php
  2. 1 1
      src/Database/Query.php

+ 4 - 1
src/Database/Connection.php

@@ -196,10 +196,13 @@ class Connection {
 /**
  * Prepares a sql statement to be executed
  *
- * @param string $sql
+ * @param string|Cake\Database\Query $sql
  * @return \Cake\Database\Statement
  */
 	public function prepare($sql) {
+		if ($sql instanceof Query) {
+			$sql = $sql->sql();
+		}
 		$statement = $this->_driver->prepare($sql);
 
 		if ($this->_logQueries) {

+ 1 - 1
src/Database/Query.php

@@ -201,7 +201,7 @@ class Query implements ExpressionInterface, IteratorAggregate {
  */
 	public function execute() {
 		$query = $this->_transformQuery();
-		$statement = $this->_connection->prepare($query->sql());
+		$statement = $this->_connection->prepare($query);
 		$query->_bindStatement($statement);
 		$statement->execute();