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))) { if ($data === null || (is_array($data) && empty($data))) {
return 'NULL'; return 'NULL';
} }
if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
return $this->_connection->quote($data, PDO::PARAM_STR);
}
if (empty($column)) { if (empty($column)) {
$column = $this->introspectType($data); $column = $this->introspectType($data);
} }
switch ($column) { switch ($column) {
case 'binary': case 'binary':
$data = $this->_connection->quote($data, PDO::PARAM_LOB); return $this->_connection->quote($data, PDO::PARAM_LOB);
break; break;
case 'boolean': case 'boolean':
return $this->boolean($data); return $this->boolean($data);
break; break;
case 'integer': case 'string':
case 'float': case 'text':
return $this->_connection->quote($data, PDO::PARAM_STR);
default:
if ($data === '') { if ($data === '') {
return 'NULL'; return 'NULL';
} }
@ -233,8 +233,7 @@ class DboSource extends DataSource {
) { ) {
return $data; return $data;
} }
default: return $this->_connection->quote($data);
return $this->_connection->quote($data, PDO::PARAM_STR);
break; break;
} }
} }

View file

@ -380,17 +380,17 @@ class DboPostgresTest extends CakeTestCase {
* @return void * @return void
*/ */
function testDateAndTimeAsNull() { function testDateAndTimeAsNull() {
$this->assertEqual($this->Dbo2->value(null, 'date'), 'NULL'); $this->assertEqual($this->Dbo->value(null, 'date'), 'NULL');
$this->assertEqual($this->Dbo2->value('', 'date'), 'NULL'); $this->assertEqual($this->Dbo->value('', 'date'), 'NULL');
$this->assertEqual($this->Dbo2->value('', 'datetime'), 'NULL'); $this->assertEqual($this->Dbo->value('', 'datetime'), 'NULL');
$this->assertEqual($this->Dbo2->value(null, 'datetime'), 'NULL'); $this->assertEqual($this->Dbo->value(null, 'datetime'), 'NULL');
$this->assertEqual($this->Dbo2->value('', 'timestamp'), 'NULL'); $this->assertEqual($this->Dbo->value('', 'timestamp'), 'NULL');
$this->assertEqual($this->Dbo2->value(null, 'timestamp'), 'NULL'); $this->assertEqual($this->Dbo->value(null, 'timestamp'), 'NULL');
$this->assertEqual($this->Dbo2->value('', 'time'), 'NULL'); $this->assertEqual($this->Dbo->value('', 'time'), 'NULL');
$this->assertEqual($this->Dbo2->value(null, 'time'), 'NULL'); $this->assertEqual($this->Dbo->value(null, 'time'), 'NULL');
} }
/** /**