Skip to content

Commit

Permalink
Moving method to where it makes more sense
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Apr 13, 2014
1 parent 5b0e715 commit 3c2f88a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
23 changes: 1 addition & 22 deletions src/Database/Connection.php
Expand Up @@ -253,33 +253,12 @@ public function run(Query $query) {
list($query, $sql) = $this->driver()->compileQuery($query, $binder);

$statement = $this->prepare($sql);
$this->_bindStatement($binder, $statement);
$binder->attachTo($statement);
$statement->execute();

return $statement;
}

/**
* Traverses all QueryExpression objects stored in every relevant for the passed
* type of query and binds every value to the statement object for each placeholder.
*
* @param \Cake\Database\ValueBinder $binder the object containing the bindings
* @param \Cake\Database\StatementInterface $statement
* @return void
*/
protected function _bindStatement($binder, $statement) {
$bindings = $binder->bindings();
if (empty($bindings)) {
return;
}
$params = $types = [];
foreach ($bindings as $b) {
$params[$b['placeholder']] = $b['value'];
$types[$b['placeholder']] = $b['type'];
}
$statement->bind($params, $types);
}

/**
* Executes a SQL statement and returns the Statement object as result.
*
Expand Down
19 changes: 19 additions & 0 deletions src/Database/ValueBinder.php
Expand Up @@ -100,4 +100,23 @@ public function resetCount() {
$this->_bindingsCount = 0;
}

/**
* Binds all the stored values in this object to the passed statement.
*
* @param \Cake\Database\StatementInterface $statement
* @return void
*/
protected function attachTo($statement) {
$bindings = $this->bindings();
if (empty($bindings)) {
return;
}
$params = $types = [];
foreach ($bindings as $b) {
$params[$b['placeholder']] = $b['value'];
$types[$b['placeholder']] = $b['type'];
}
$statement->bind($params, $types);
}

}

0 comments on commit 3c2f88a

Please sign in to comment.