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:
nate 2008-08-27 12:42:13 +00:00
parent 32e5f7c886
commit e64af40530
2 changed files with 29 additions and 2 deletions

View file

@ -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;

View file

@ -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
*