Skip to content

Commit

Permalink
Update Query.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan authored Oct 26, 2017
1 parent 4e39005 commit 912bed4
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Query {
private $_orderBy=[];
private $_groupBy=[];
private $_fetchCount;
private $_whereReplaceCount=0;
private $_whereReplaceParams=null;
private $_lastStmt=null;
private $_collateTable=null;
Expand Down Expand Up @@ -291,7 +290,6 @@ public function getCommand() :string {
public function addWhere(array $queries, array $params=[]) {
if (isset($queries[0]) && !is_array($queries[0])) $queries = [ $queries ];

$this->_whereReplaceCount=count($this->_params);
$this->_whereReplaceParams=$params;

$this->_where[] = $this->_addWhereDo($queries);
Expand Down Expand Up @@ -323,7 +321,7 @@ private function _addWhereDo(array $queries) :string {
}

// replace unnamed params with named params cause we merge them all together here
$operation = preg_replace_callback('/\?/', [$this, '_whereReplaceParams'], $operation, -1, $this->_whereReplaceCount);
$operation = preg_replace_callback('/\?/', [$this, '_whereReplaceParams'], $operation, -1);

// divide field into table and field, resolve table alias
$table = $this->_table;
Expand Down Expand Up @@ -847,12 +845,22 @@ private function _queryCanExecute() :bool {
* @return String
**/
private function _whereReplaceParams(array $matches) :string {
if (isset($this->_whereReplaceParams[$this->_whereReplaceCount])) {
$this->_whereReplaceParams[':param' . $this->_whereReplaceCount] = $this->_whereReplaceParams[$this->_whereReplaceCount];
unset($this->_whereReplaceParams[$this->_whereReplaceCount]);
// get next free number
krsort($this->_whereReplaceParams);
$next=0;
foreach ($this->_whereReplaceParams as $key => $value) {
if (strpos($key, ':param') === 0) {
$next=(int)substr($key, 6);
++$next;
break;
}
}

return ':param' . $this->_whereReplaceCount;
$this->_whereReplaceParams[':param' . $next] = $this->_whereReplaceParams[$next];
unset($this->_whereReplaceParams[$next]);

$ret = ':param' . $next;
return $ret;
}


Expand Down

0 comments on commit 912bed4

Please sign in to comment.