mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Making DboSource::fields() accept an expression object. Fixes issues with sql parsing over quoting special SQL syntax.
Tests added Fixes #66
This commit is contained in:
parent
47a9401d43
commit
02330b2d9c
2 changed files with 17 additions and 1 deletions
|
@ -1683,7 +1683,9 @@ class DboSource extends DataSource {
|
||||||
|
|
||||||
if ($count >= 1 && !in_array($fields[0], array('*', 'COUNT(*)'))) {
|
if ($count >= 1 && !in_array($fields[0], array('*', 'COUNT(*)'))) {
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
if (preg_match('/^\(.*\)\s' . $this->alias . '.*/i', $fields[$i])){
|
if (is_object($fields[$i]) && isset($fields[$i]->type) && $fields[$i]->type === 'expression') {
|
||||||
|
$fields[$i] = $fields[$i]->value;
|
||||||
|
} elseif (preg_match('/^\(.*\)\s' . $this->alias . '.*/i', $fields[$i])){
|
||||||
continue;
|
continue;
|
||||||
} elseif (!preg_match('/^.+\\(.*\\)/', $fields[$i])) {
|
} elseif (!preg_match('/^.+\\(.*\\)/', $fields[$i])) {
|
||||||
$prepend = '';
|
$prepend = '';
|
||||||
|
|
|
@ -2781,6 +2781,20 @@ class DboSourceTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* test that fields() will accept objects made from DboSource::expression
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testFieldsWithExpression() {
|
||||||
|
$expression =& $this->testDb->expression("CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col");
|
||||||
|
$result = $this->testDb->fields($this->Model, null, array("id", $expression));
|
||||||
|
$expected = array(
|
||||||
|
'`TestModel`.`id`',
|
||||||
|
"CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col"
|
||||||
|
);
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* testMergeAssociations method
|
* testMergeAssociations method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue