More refactoring to DboSource::value()

This commit is contained in:
José Lorenzo Rodríguez 2010-10-17 23:55:11 -04:30
parent 6778d4b565
commit aedf69dee1
2 changed files with 15 additions and 16 deletions

View file

@ -205,22 +205,22 @@ class DboSource extends DataSource {
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';
}
@ -233,8 +233,7 @@ class DboSource extends DataSource {
) {
return $data;
}
default:
return $this->_connection->quote($data, PDO::PARAM_STR);
return $this->_connection->quote($data);
break;
}
}

View file

@ -380,17 +380,17 @@ class DboPostgresTest extends CakeTestCase {
* @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');
}
/**