Skip to content

Commit

Permalink
Fixing some boolean issues in DboPostgres
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 22, 2010
1 parent 88289f0 commit c7763b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
21 changes: 13 additions & 8 deletions cake/libs/model/datasources/dbo/dbo_postgres.php
Expand Up @@ -742,24 +742,29 @@ function fetchResult() {
/**
* Translates between PHP boolean values and PostgreSQL boolean values
*
* @param mixed $data Value to be translated
* @param boolean $quote True to quote value, false otherwise
* @return mixed Converted boolean value
* @param mixed $data Value to be translated
* @param boolean $quote true to quote a boolean to be used in a query, flase to return the boolean value
* @return boolean Converted boolean value
*/
function boolean($data, $quote = true) {
switch (true) {
case ($data === true || $data === false):
return $data;
$result = $data;
case ($data === 't' || $data === 'f'):
return ($data === 't');
$result = ($data === 't');
case ($data === 'true' || $data === 'false'):
return ($data === 'true');
$result = ($data === 'true');
case ($data === 'TRUE' || $data === 'FALSE'):
return ($data === 'TRUE');
$result = ($data === 'TRUE');
default:
return (bool)$data;
$result = (bool)$data;
break;
}

if ($quote) {
$result = ($result) ? 'TRUE' : 'FALSE';
}
return $result;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/model/datasources/dbo_source.php
Expand Up @@ -215,7 +215,7 @@ function value($data, $column = null, $safe = false) {
return $this->_connection->quote($data, PDO::PARAM_LOB);
break;
case 'boolean':
return $this->boolean($data);
return $this->_connection->quote($this->boolean($data), PDO::PARAM_BOOL);
break;
case 'string':
case 'text':
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/libs/model/model_read.test.php
Expand Up @@ -57,8 +57,8 @@ function testFetchingNonUniqueFKJoinTableRecords() {

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

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

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

0 comments on commit c7763b3

Please sign in to comment.