Added checks for empty string in integer columns. value() Now returns NULL. Closes #5141

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7366 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-07-27 02:49:02 +00:00
parent e26b7e7a63
commit 8d2e4721e3
5 changed files with 26 additions and 5 deletions

View file

@ -224,7 +224,7 @@ class DboMysql extends DboSource {
return $parent;
} elseif ($data === null || (is_array($data) && empty($data))) {
return 'NULL';
} elseif ($data === '') {
} elseif ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
return "''";
}
if (empty($column)) {
@ -237,6 +237,9 @@ class DboMysql extends DboSource {
break;
case 'integer':
case 'float':
if ($data === '') {
return 'NULL';
}
if ((is_int($data) || is_float($data) || $data === '0') || (
is_numeric($data) && strpos($data, ',') === false &&
$data[0] != '0' && strpos($data, 'e') === false)) {

View file

@ -241,7 +241,7 @@ class DboMysqli extends DboSource {
return 'NULL';
}
if ($data === '') {
if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
return "''";
}
@ -252,6 +252,9 @@ class DboMysqli extends DboSource {
case 'integer' :
case 'float' :
case null :
if ($data === '') {
return 'NULL';
}
if ((is_int($data) || is_float($data) || $data === '0') || (
is_numeric($data) && strpos($data, ',') === false &&
$data[0] != '0' && strpos($data, 'e') === false)) {

View file

@ -234,13 +234,18 @@ class DboSqlite extends DboSource {
if ($data === null) {
return 'NULL';
}
if ($data === '') {
if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
return "''";
}
switch ($column) {
case 'boolean':
$data = $this->boolean((bool)$data);
break;
case 'integer':
case 'float':
if ($data === '') {
return 'NULL';
}
default:
$data = sqlite_escape_string($data);
break;

View file

@ -234,6 +234,15 @@ class DboMysqlTest extends CakeTestCase {
$expected = "'4713e29446'";
$result = $this->db->value('4713e29446');
$this->assertEqual($expected, $result);
$expected = 'NULL';
$result = $this->db->value('', 'integer');
$this->assertEqual($expected, $result);
$expected = 'NULL';
$result = $this->db->value('', 'boolean');
$this->assertEqual($expected, $result);
$expected = 10010001;

View file

@ -3340,7 +3340,8 @@ class DboSourceTest extends CakeTestCase {
// EMPTY STRING
$result = $this->testDb->value('', 'boolean');
$this->assertEqual($result, "''");
$this->assertEqual($result, "NULL");
// BOOLEAN
$result = $this->testDb->value('true', 'boolean');
@ -3441,7 +3442,7 @@ class DboSourceTest extends CakeTestCase {
$result = $this->testDb->value(array('first', 2, 'third'));
$expected = array('\'first\'', 2, '\'third\'');
$this->assertEqual($result, $expected);
$this->assertEqual($result, $expected);
}
/**
* testReconnect method