From 3ce765358d542cb6c17ecb6d4da23a32416e1539 Mon Sep 17 00:00:00 2001 From: nate Date: Tue, 24 Jun 2008 04:55:59 +0000 Subject: [PATCH] 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 --- .../model/datasources/dbo/dbo_postgres.php | 6 ++--- .../datasources/dbo/dbo_postgres.test.php | 25 +++++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 815c08eb6..634752f2e 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -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); diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php index 2d5f51eb2..7cf11d2ff 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php @@ -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); } } -?> +?> \ No newline at end of file