Fixing boolean handling in DboPostgres, closes #4878

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7257 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-06-24 04:55:59 +00:00
parent 3552ebea58
commit 3ce765358d
2 changed files with 23 additions and 8 deletions

View file

@ -272,12 +272,12 @@ class DboPostgres extends DboSource {
$data = pg_escape_bytea($data);
break;
case 'boolean':
if ($data === true) {
if ($data === true || $data === 't') {
return 'TRUE';
} elseif ($data === false) {
} elseif ($data === false || $data === 'f') {
return 'FALSE';
}
return 'DEFAULT';
return (!empty($data) ? 'TRUE' : 'FALSE');
break;
default:
$data = pg_escape_string($data);

View file

@ -281,6 +281,18 @@ class DboPostgresTest extends CakeTestCase {
$this->assertEqual($this->db2->value('', 'integer'), "DEFAULT");
$this->assertEqual($this->db2->value('', 'float'), "DEFAULT");
$this->assertEqual($this->db2->value('0.0', 'float'), "'0.0'");
$this->assertEqual($this->db2->value('t', 'boolean'), "TRUE");
$this->assertEqual($this->db2->value('f', 'boolean'), "FALSE");
$this->assertEqual($this->db2->value(true), "TRUE");
$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('', '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");
}
/**
* testLastInsertIdMultipleInsert method
@ -293,6 +305,7 @@ class DboPostgresTest extends CakeTestCase {
$User =& new User();
$db1 = ConnectionManager::getDataSource('test_suite');
if (PHP5) {
$db2 = clone $db1;
} else {
@ -305,13 +318,15 @@ class DboPostgresTest extends CakeTestCase {
$db1->truncate($User->useTable);
$table = $db1->fullTableName($User->useTable, false);
$db1->execute("INSERT INTO {$table} (\"user\", password)"
. " VALUES ('mariano', '5f4dcc3b5aa765d61d8327deb882cf99')");
$db2->execute("INSERT INTO {$table} (\"user\", password)"
. " VALUES ('hoge', '5f4dcc3b5aa765d61d8327deb882cf99')");
$db1->execute(
"INSERT INTO {$table} (\"user\", password) VALUES ('mariano', '5f4dcc3b5aa765d61d8327deb882cf99')"
);
$db2->execute(
"INSERT INTO {$table} (\"user\", password) VALUES ('hoge', '5f4dcc3b5aa765d61d8327deb882cf99')"
);
$this->assertEqual($db1->lastInsertId($table), 1);
$this->assertEqual($db2->lastInsertId($table), 2);
}
}
?>
?>