mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
More fixes for Postgres boolean handling, fixes #5327
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7525 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
32e5f7c886
commit
e64af40530
2 changed files with 29 additions and 2 deletions
|
@ -280,9 +280,9 @@ class DboPostgres extends DboSource {
|
|||
$data = pg_escape_bytea($data);
|
||||
break;
|
||||
case 'boolean':
|
||||
if ($data === true || $data === 't') {
|
||||
if ($data === true || $data === 't' || $data === 'true') {
|
||||
return 'TRUE';
|
||||
} elseif ($data === false || $data === 'f') {
|
||||
} elseif ($data === false || $data === 'f' || $data === 'false') {
|
||||
return 'FALSE';
|
||||
}
|
||||
return (!empty($data) ? 'TRUE' : 'FALSE');
|
||||
|
@ -598,6 +598,10 @@ class DboPostgres extends DboSource {
|
|||
return $data;
|
||||
case ($data === 't' || $data === 'f'):
|
||||
return ($data === 't');
|
||||
case ($data === 'true' || $data === 'false'):
|
||||
return ($data === 'true');
|
||||
case ($data === 'TRUE' || $data === 'FALSE'):
|
||||
return ($data === 'TRUE');
|
||||
default:
|
||||
return (bool)$data;
|
||||
break;
|
||||
|
|
|
@ -290,12 +290,35 @@ class DboPostgresTest extends CakeTestCase {
|
|||
$this->assertEqual($this->db2->value(false), "FALSE");
|
||||
$this->assertEqual($this->db2->value('t'), "'t'");
|
||||
$this->assertEqual($this->db2->value('f'), "'f'");
|
||||
$this->assertEqual($this->db2->value('true', 'boolean'), 'TRUE');
|
||||
$this->assertEqual($this->db2->value('false', 'boolean'), 'FALSE');
|
||||
$this->assertEqual($this->db2->value('', 'boolean'), 'FALSE');
|
||||
$this->assertEqual($this->db2->value(0, 'boolean'), 'FALSE');
|
||||
$this->assertEqual($this->db2->value(1, 'boolean'), 'TRUE');
|
||||
$this->assertEqual($this->db2->value('1', 'boolean'), 'TRUE');
|
||||
$this->assertEqual($this->db2->value(null, 'boolean'), "NULL");
|
||||
}
|
||||
/**
|
||||
* Tests that different Postgres boolean 'flavors' are properly returned as native PHP booleans
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testBooleanNormalization() {
|
||||
$this->assertTrue($this->db2->boolean('t'));
|
||||
$this->assertTrue($this->db2->boolean('true'));
|
||||
$this->assertTrue($this->db2->boolean('TRUE'));
|
||||
$this->assertTrue($this->db2->boolean(true));
|
||||
$this->assertTrue($this->db2->boolean(1));
|
||||
$this->assertTrue($this->db2->boolean(" "));
|
||||
|
||||
$this->assertFalse($this->db2->boolean('f'));
|
||||
$this->assertFalse($this->db2->boolean('false'));
|
||||
$this->assertFalse($this->db2->boolean('FALSE'));
|
||||
$this->assertFalse($this->db2->boolean(false));
|
||||
$this->assertFalse($this->db2->boolean(0));
|
||||
$this->assertFalse($this->db2->boolean(''));
|
||||
}
|
||||
/**
|
||||
* testLastInsertIdMultipleInsert method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue