mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding SQL function quoting fix in DboSource (Ticket #2987)
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5472 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
d6c4229d81
commit
ad53804b60
2 changed files with 12 additions and 3 deletions
|
@ -370,10 +370,14 @@ class DboSource extends DataSource {
|
|||
* @return string SQL field
|
||||
*/
|
||||
function name($data) {
|
||||
if (preg_match_all('/(.*)\((.*)\)(.*)/', $data, $fields)) {
|
||||
if (preg_match_all('/([^(]*)\((.*)\)(.*)/', $data, $fields)) {
|
||||
$fields = Set::extract($fields, '{n}.0');
|
||||
if (isset($fields[1]) && isset($fields[2])) {
|
||||
return $fields[1] . '(' . $this->name($fields[2]) . ')' . $fields[3];
|
||||
if (!empty($fields[1])) {
|
||||
if (!empty($fields[2])) {
|
||||
return $fields[1] . '(' . $this->name($fields[2]) . ')' . $fields[3];
|
||||
} else {
|
||||
return $fields[1] . '()' . $fields[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($data == '*') {
|
||||
|
|
|
@ -1631,6 +1631,7 @@ class DboSourceTest extends UnitTestCase {
|
|||
$result = $this->db->conditions($conditions);
|
||||
$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 testFieldParsing() {
|
||||
$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`');
|
||||
|
@ -1707,6 +1708,10 @@ class DboSourceTest extends UnitTestCase {
|
|||
$result = $this->db->fields($this->model, null, 'field1, field2, field3, count(*), name');
|
||||
$expected = array('`TestModel`.`field1`', '`TestModel`.`field2`', '`TestModel`.`field3`', 'count(*)', '`TestModel`.`name`');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->db->fields($this->model, null, array('dayofyear(now())'));
|
||||
$expected = array('dayofyear(now())');
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testMergeAssociations() {
|
||||
|
|
Loading…
Add table
Reference in a new issue