mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fixing some boolean issues in DboPostgres
This commit is contained in:
parent
88289f071e
commit
c7763b316e
3 changed files with 16 additions and 11 deletions
|
@ -742,24 +742,29 @@ class DboPostgres extends DboSource {
|
|||
/**
|
||||
* 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 @@ class DboSource extends DataSource {
|
|||
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 @@ class ModelReadTest extends BaseModelTest {
|
|||
|
||||
$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);
|
||||
|
|
Loading…
Add table
Reference in a new issue