Skip to content

Commit c7763b3

Browse files
committed
Fixing some boolean issues in DboPostgres
1 parent 88289f0 commit c7763b3

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

cake/libs/model/datasources/dbo/dbo_postgres.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -742,24 +742,29 @@ function fetchResult() {
742742
/**
743743
* Translates between PHP boolean values and PostgreSQL boolean values
744744
*
745-
* @param mixed $data Value to be translated
746-
* @param boolean $quote True to quote value, false otherwise
747-
* @return mixed Converted boolean value
745+
* @param mixed $data Value to be translated
746+
* @param boolean $quote true to quote a boolean to be used in a query, flase to return the boolean value
747+
* @return boolean Converted boolean value
748748
*/
749749
function boolean($data, $quote = true) {
750750
switch (true) {
751751
case ($data === true || $data === false):
752-
return $data;
752+
$result = $data;
753753
case ($data === 't' || $data === 'f'):
754-
return ($data === 't');
754+
$result = ($data === 't');
755755
case ($data === 'true' || $data === 'false'):
756-
return ($data === 'true');
756+
$result = ($data === 'true');
757757
case ($data === 'TRUE' || $data === 'FALSE'):
758-
return ($data === 'TRUE');
758+
$result = ($data === 'TRUE');
759759
default:
760-
return (bool)$data;
760+
$result = (bool)$data;
761761
break;
762762
}
763+
764+
if ($quote) {
765+
$result = ($result) ? 'TRUE' : 'FALSE';
766+
}
767+
return $result;
763768
}
764769

765770
/**

cake/libs/model/datasources/dbo_source.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function value($data, $column = null, $safe = false) {
215215
return $this->_connection->quote($data, PDO::PARAM_LOB);
216216
break;
217217
case 'boolean':
218-
return $this->boolean($data);
218+
return $this->_connection->quote($this->boolean($data), PDO::PARAM_BOOL);
219219
break;
220220
case 'string':
221221
case 'text':

cake/tests/cases/libs/model/model_read.test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ function testFetchingNonUniqueFKJoinTableRecords() {
5757

5858
$result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2)));
5959

60-
$this->assertEqual($result[0]['JoinThing']['doomed'], '1');
61-
$this->assertEqual($result[1]['JoinThing']['doomed'], '0');
60+
$this->assertEqual((bool)$result[0]['JoinThing']['doomed'], true);
61+
$this->assertEqual((bool)$result[1]['JoinThing']['doomed'], false);
6262

6363
$result = $Something->find('first');
6464
$this->assertEqual(count($result['SomethingElse']), 2);

0 commit comments

Comments
 (0)