Skip to content
Permalink
Browse files

Fix boolean casting in SQLite.

Boolean values come out as '1', '0'. These should be cast into proper
boolean values by the type system.
  • Loading branch information...
markstory committed Nov 10, 2013
1 parent 4c86eb4 commit a6e39df9f63174de55b7415202fd198cd98fb146
Showing with 9 additions and 1 deletion.
  1. +1 −1 Cake/Database/Type.php
  2. +8 −0 Cake/Test/TestCase/Database/TypeTest.php
@@ -221,7 +221,7 @@ public function toStatement($value, Driver $driver) {
* @return boolean
*/
public static function boolval($value) {
if (is_string($value)) {
if (is_string($value) && !is_numeric($value)) {
return strtolower($value) === 'true' ? true : false;
}
return !empty($value);
@@ -295,6 +295,12 @@ public function testBooleanToDatabase() {
$driver = $this->getMock('\Cake\Database\Driver');
$this->assertFalse($type->toDatabase(0, $driver));
$driver = $this->getMock('\Cake\Database\Driver');
$this->assertTrue($type->toDatabase('1', $driver));
$driver = $this->getMock('\Cake\Database\Driver');
$this->assertFalse($type->toDatabase('0', $driver));
}
/**
@@ -322,11 +328,13 @@ public function testBooleanToPHP() {
$this->assertTrue($type->toPHP(true, $driver));
$this->assertTrue($type->toPHP(1, $driver));
$this->assertTrue($type->toPHP('1', $driver));
$this->assertTrue($type->toPHP('TRUE', $driver));
$this->assertTrue($type->toPHP('true', $driver));
$this->assertFalse($type->toPHP(false, $driver));
$this->assertFalse($type->toPHP(0, $driver));
$this->assertFalse($type->toPHP('0', $driver));
$this->assertFalse($type->toPHP('FALSE', $driver));
$this->assertFalse($type->toPHP('false', $driver));
}

0 comments on commit a6e39df

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