Skip to content

Commit

Permalink
Adding nullish value handling for date, datetime, and timestamp colum…
Browse files Browse the repository at this point in the history
…n types to DboPostgres. Empty string values now return instead of "". Fixes #6386

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8190 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Jun 5, 2009
1 parent 4a076b3 commit 2c1b7fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cake/libs/model/datasources/dbo/dbo_postgres.php
Expand Up @@ -275,6 +275,9 @@ function value($data, $column = null, $read = true) {
case 'inet':
case 'float':
case 'integer':
case 'date':
case 'datetime':
case 'timestamp':
if ($data === '') {
return $read ? 'NULL' : 'DEFAULT';
}
Expand Down
15 changes: 15 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php
Expand Up @@ -290,6 +290,21 @@ function testValueQuoting() {
$this->assertEqual($this->db2->value('1', 'boolean'), 'TRUE');
$this->assertEqual($this->db2->value(null, 'boolean'), "NULL");
}
/**
* test that date columns do not generate errors with null and nullish values.
*
* @return void
**/
function testDateAsNull() {
$this->assertEqual($this->db2->value(null, 'date'), 'NULL');
$this->assertEqual($this->db2->value('', 'date'), 'NULL');

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

$this->assertEqual($this->db2->value('', 'timestamp'), 'NULL');
$this->assertEqual($this->db2->value(null, 'timestamp'), 'NULL');
}
/**
* Tests that different Postgres boolean 'flavors' are properly returned as native PHP booleans
*
Expand Down

0 comments on commit 2c1b7fc

Please sign in to comment.