Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More refactoring to DboSource::value()
  • Loading branch information
lorenzo committed Oct 18, 2010
1 parent 6778d4b commit aedf69d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
15 changes: 7 additions & 8 deletions cake/libs/model/datasources/dbo_source.php
Expand Up @@ -205,22 +205,22 @@ function value($data, $column = null, $safe = false) {
if ($data === null || (is_array($data) && empty($data))) {
return 'NULL';
}
if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
return $this->_connection->quote($data, PDO::PARAM_STR);
}

if (empty($column)) {
$column = $this->introspectType($data);
}

switch ($column) {
case 'binary':
$data = $this->_connection->quote($data, PDO::PARAM_LOB);
return $this->_connection->quote($data, PDO::PARAM_LOB);
break;
case 'boolean':
return $this->boolean($data);
break;
case 'integer':
case 'float':
case 'string':
case 'text':
return $this->_connection->quote($data, PDO::PARAM_STR);
default:
if ($data === '') {
return 'NULL';
}
Expand All @@ -233,8 +233,7 @@ function value($data, $column = null, $safe = false) {
) {
return $data;
}
default:
return $this->_connection->quote($data, PDO::PARAM_STR);
return $this->_connection->quote($data);
break;
}
}
Expand Down
Expand Up @@ -380,17 +380,17 @@ function testLocalizedFloats() {
* @return void
*/
function testDateAndTimeAsNull() {
$this->assertEqual($this->Dbo2->value(null, 'date'), 'NULL');
$this->assertEqual($this->Dbo2->value('', 'date'), 'NULL');
$this->assertEqual($this->Dbo->value(null, 'date'), 'NULL');
$this->assertEqual($this->Dbo->value('', 'date'), 'NULL');

$this->assertEqual($this->Dbo2->value('', 'datetime'), 'NULL');
$this->assertEqual($this->Dbo2->value(null, 'datetime'), 'NULL');
$this->assertEqual($this->Dbo->value('', 'datetime'), 'NULL');
$this->assertEqual($this->Dbo->value(null, 'datetime'), 'NULL');

$this->assertEqual($this->Dbo2->value('', 'timestamp'), 'NULL');
$this->assertEqual($this->Dbo2->value(null, 'timestamp'), 'NULL');
$this->assertEqual($this->Dbo->value('', 'timestamp'), 'NULL');
$this->assertEqual($this->Dbo->value(null, 'timestamp'), 'NULL');

$this->assertEqual($this->Dbo2->value('', 'time'), 'NULL');
$this->assertEqual($this->Dbo2->value(null, 'time'), 'NULL');
$this->assertEqual($this->Dbo->value('', 'time'), 'NULL');
$this->assertEqual($this->Dbo->value(null, 'time'), 'NULL');
}

/**
Expand Down

0 comments on commit aedf69d

Please sign in to comment.