mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fix issue with postgres and virtualFields
If a virtualField was set to a literal value it would be quoted. Test added. Fixes #2085
This commit is contained in:
parent
7e89442a13
commit
fe9e595913
2 changed files with 24 additions and 2 deletions
|
@ -394,6 +394,7 @@ class Postgres extends DboSource {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auxiliary function to quote matched `(Model.fields)` from a preg_replace_callback call
|
* Auxiliary function to quote matched `(Model.fields)` from a preg_replace_callback call
|
||||||
|
* Quotes the fields in a function call.
|
||||||
*
|
*
|
||||||
* @param string $match matched string
|
* @param string $match matched string
|
||||||
* @return string quoted strig
|
* @return string quoted strig
|
||||||
|
@ -404,9 +405,11 @@ class Postgres extends DboSource {
|
||||||
$prepend = 'DISTINCT ';
|
$prepend = 'DISTINCT ';
|
||||||
$match[1] = trim(str_replace('DISTINCT', '', $match[1]));
|
$match[1] = trim(str_replace('DISTINCT', '', $match[1]));
|
||||||
}
|
}
|
||||||
if (strpos($match[1], '.') === false) {
|
$constant = preg_match('/^\d+|NULL|FALSE|TRUE$/i', $match[1]);
|
||||||
|
|
||||||
|
if (!$constant && strpos($match[1], '.') === false) {
|
||||||
$match[1] = $this->name($match[1]);
|
$match[1] = $this->name($match[1]);
|
||||||
} else {
|
} elseif (!$constant){
|
||||||
$parts = explode('.', $match[1]);
|
$parts = explode('.', $match[1]);
|
||||||
if (!Set::numeric($parts)) {
|
if (!Set::numeric($parts)) {
|
||||||
$match[1] = $this->name($match[1]);
|
$match[1] = $this->name($match[1]);
|
||||||
|
|
|
@ -751,6 +751,25 @@ class PostgresTest extends CakeTestCase {
|
||||||
$this->assertEqual($result['Article']['subquery'], 6);
|
$this->assertEqual($result['Article']['subquery'], 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that virtual fields work with SQL constants
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testVirtualFieldAsAConstant() {
|
||||||
|
$this->loadFixtures('Article', 'Comment');
|
||||||
|
$Article =& ClassRegistry::init('Article');
|
||||||
|
$Article->virtualFields = array(
|
||||||
|
'empty' => "NULL",
|
||||||
|
'number' => 43,
|
||||||
|
'truth' => 'TRUE'
|
||||||
|
);
|
||||||
|
$result = $Article->find('first');
|
||||||
|
$this->assertNull($result['Article']['empty']);
|
||||||
|
$this->assertTrue($result['Article']['truth']);
|
||||||
|
$this->assertEquals(43, $result['Article']['number']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests additional order options for postgres
|
* Tests additional order options for postgres
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue