Skip to content
Permalink
Browse files

Fixing some boolean issues in DboPostgres

  • Loading branch information...
lorenzo committed Oct 22, 2010
1 parent 88289f0 commit c7763b316eb2371e16cdce5d3e835955dd10f820
@@ -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;
}
/**
@@ -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':
@@ -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);

0 comments on commit c7763b3

Please sign in to comment.
You can’t perform that action at this time.