mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing escaping of fields in hasAny() also adding in correct model aliases.
Tests added. Fixes #6089 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8032 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
43ad3d76e5
commit
ce4fa20f3f
2 changed files with 18 additions and 3 deletions
|
@ -2102,10 +2102,11 @@ class DboSource extends DataSource {
|
|||
function hasAny(&$Model, $sql) {
|
||||
$sql = $this->conditions($sql);
|
||||
$table = $this->fullTableName($Model);
|
||||
$where = $sql ? "WHERE {$sql}" : 'WHERE 1 = 1';
|
||||
$id = $Model->primaryKey;
|
||||
$alias = $this->alias . $this->name($Model->alias);
|
||||
$where = $sql ? "{$sql}" : ' WHERE 1 = 1';
|
||||
$id = $Model->escapeField();
|
||||
|
||||
$out = $this->fetchRow("SELECT COUNT({$id}) {$this->alias}count FROM {$table} {$where}");
|
||||
$out = $this->fetchRow("SELECT COUNT({$id}) {$this->alias}count FROM {$table} {$alias}{$where}");
|
||||
|
||||
if (is_array($out)) {
|
||||
return $out[0]['count'];
|
||||
|
|
|
@ -3394,6 +3394,20 @@ class DboSourceTest extends CakeTestCase {
|
|||
$expected = '`int_field` int(11) NOT NULL';
|
||||
$this->assertTrue($result, $expected);
|
||||
}
|
||||
/**
|
||||
* test hasAny()
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testHasAny() {
|
||||
$this->testDb->hasAny($this->Model, array());
|
||||
$expected = 'SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE 1 = 1';
|
||||
$this->assertEqual($this->testDb->simulated[0], $expected);
|
||||
|
||||
$this->testDb->hasAny($this->Model, array('TestModel.name' => 'harry'));
|
||||
$expected = "SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE `TestModel`.`name` = 'harry'";
|
||||
$this->assertEqual($this->testDb->simulated[1], $expected);
|
||||
}
|
||||
/**
|
||||
* testIntrospectType method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue