Permalink
Browse files

Adding nullish value handling for date, datetime, and timestamp colum…

…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 2c1b7fc24ed0766975d9b7b461922d6435d6f72c
@@ -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';
}
@@ -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
*

0 comments on commit 2c1b7fc

Please sign in to comment.