Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing support for subqueries in where clause
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
lib/Cake/Model/Datasource/Database/Expression/Comparisson.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Cake\Model\Datasource\Database\Expression; | ||
|
||
class Comparisson extends QueryExpression { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
protected $_field; | ||
|
||
protected $_value; | ||
|
||
protected $_type; | ||
|
||
public function __construct(array $condition, $types = [], $conjuntion = '=') { | ||
parent::__construct($condition, $types, $conjuntion); | ||
} | ||
|
||
public function field($field) { | ||
$this->_field = $field; | ||
} | ||
|
||
public function value($value) { | ||
$this->_value = $value; | ||
} | ||
|
||
public function getField() { | ||
return $this->_field; | ||
} | ||
|
||
public function getValue() { | ||
return $this->_value; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
markstory
Member
|
||
|
||
public function sql() { | ||
$value = $this->_value; | ||
$template = '%s %s (%s)'; | ||
if (is_scalar($this->_value)) { | ||
$value = $this->_bindValue($this->_field,$value, $this->_type); | ||
$template = '%s %s %s'; | ||
} | ||
|
||
return sprintf($template, $this->_field, $this->_conjunction, $value); | ||
} | ||
|
||
public function count() { | ||
return 1; | ||
} | ||
|
||
protected function _addConditions(array $condition, array $types) { | ||
$this->_conditions[] = current($condition); | ||
$this->_field = key($condition); | ||
$this->_value = current($condition); | ||
|
||
if (isset($types[$this->_field])) { | ||
$this->_type = current($types); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Comparison only has one
s
.