mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
"Fixes #3645, DboSource::conditions() bug ($conditions = null, $where = false)"
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6107 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
13530f42dc
commit
4dbd53e3d9
2 changed files with 14 additions and 3 deletions
|
@ -1499,8 +1499,11 @@ class DboSource extends DataSource {
|
||||||
$clause = $out = '';
|
$clause = $out = '';
|
||||||
if (is_string($conditions) || empty($conditions) || $conditions === true) {
|
if (is_string($conditions) || empty($conditions) || $conditions === true) {
|
||||||
if (empty($conditions) || trim($conditions) == '' || $conditions === true) {
|
if (empty($conditions) || trim($conditions) == '' || $conditions === true) {
|
||||||
|
if ($where) {
|
||||||
return ' WHERE 1 = 1';
|
return ' WHERE 1 = 1';
|
||||||
}
|
}
|
||||||
|
return '1 = 1';
|
||||||
|
}
|
||||||
if (!preg_match('/^WHERE\\x20|^GROUP\\x20BY\\x20|^HAVING\\x20|^ORDER\\x20BY\\x20/i', $conditions, $match)) {
|
if (!preg_match('/^WHERE\\x20|^GROUP\\x20BY\\x20|^HAVING\\x20|^ORDER\\x20BY\\x20/i', $conditions, $match)) {
|
||||||
if ($where) {
|
if ($where) {
|
||||||
$clause = ' WHERE ';
|
$clause = ' WHERE ';
|
||||||
|
|
|
@ -1656,6 +1656,14 @@ class DboSourceTest extends CakeTestCase {
|
||||||
$this->assertPattern('/^\s*WHERE\s+`Thread`.`project_id`\s*=\s*5\s+AND\s+`Thread`.`buyer_id`\s*=\s*14\s+AND\s+1\s*=\s*1\s+GROUP BY `Thread`.`project_id`$/', $result);
|
$this->assertPattern('/^\s*WHERE\s+`Thread`.`project_id`\s*=\s*5\s+AND\s+`Thread`.`buyer_id`\s*=\s*14\s+AND\s+1\s*=\s*1\s+GROUP BY `Thread`.`project_id`$/', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testConditionsOptionalArguments() {
|
||||||
|
$result = $this->db->conditions( array('Member.name' => 'Mariano'), true, false);
|
||||||
|
$this->assertPattern('/^\s*`Member`.`name`\s*=\s*\'Mariano\'\s*$/', $result);
|
||||||
|
|
||||||
|
$result = $this->db->conditions( array(), true, false);
|
||||||
|
$this->assertPattern('/^\s*1\s*=\s*1\s*$/', $result);
|
||||||
|
}
|
||||||
|
|
||||||
function testFieldParsing() {
|
function testFieldParsing() {
|
||||||
$result = $this->db->fields($this->Model, 'Vendor', "Vendor.id, COUNT(Model.vendor_id) AS `Vendor`.`count`");
|
$result = $this->db->fields($this->Model, 'Vendor', "Vendor.id, COUNT(Model.vendor_id) AS `Vendor`.`count`");
|
||||||
$expected = array('`Vendor`.`id`', 'COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`');
|
$expected = array('`Vendor`.`id`', 'COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`');
|
||||||
|
|
Loading…
Add table
Reference in a new issue