Bug #5060 [Com]: empty date fields cause data to be invalid
| From: | sam@archives.org.au | Date: | Wed, 01 Apr 2009 08:47:30 +0000 |
| Subject: | Bug #5060 [Com]: empty date fields cause data to be invalid | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-288@lists.php.net to get a copy of this message | ||
Edit report at http://pear.php.net/bugs/bug.php?id=5060&edit=1
ID: 5060
Comment by: sam@archives.org.au
Reported By: jameslee at cs dot nmt dot edu
Summary: empty date fields cause data to be invalid
Status: No Feedback
Type: Bug
Package: DB_Table
Operating System: Irrelevant
PHP Version: 4.3.11
Assigned To: wiesemann
Roadmap Versions:
New Comment:
I am still getting this problem. I get this error:
Insert data not valid for column 'date_scheduled' ('-00-00')
I have tried altering the constructor of DB_Table_Date to initialise
all date components to 00 or 0000, but it doesn't help (I also added
date_parse() in there as well, just for fun). The odd thing is that in
the above data, that string that it's complaining about ('-00-00')
doesn't actually appear! And I can't figure out how it's building it.
Can anyone help?!
Thanks,
Sam.
Previous Comments:
------------------------------------------------------------------------
[2005-09-10 10:40:10] wiesemann
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
-----
I assume this problem as fixed but got no feedback from the bug
reporter.
------------------------------------------------------------------------
[2005-08-24 16:22:55] wiesemann
The changes are in now in the CVS repository. Please try this version
(changed files: Table.php and Table/QuickForm.php) and tell me if this
fixes the problem.
What is done now?
- if the field is required:
The QuickForm rule "required" catches this. One has to fill all three
elements with a value. This was an old bug in DB_Table (using addRule()
instead of addGroupRule() for date elements).
- if the field is not required:
If only one of the three values im empty, the value will be casted to
null.
------------------------------------------------------------------------
[2005-08-16 13:37:36] wiesemann
Hi,
I can reproduce this problem. The solution will be to insert
'0000-00-00' (if null values are not allowed in the table) or null (if
null values are allowed).
You can expect a fix for this in a few days (if a have CVS karma until
then ...)
Thanks for catching this problem, anyway.
------------------------------------------------------------------------
[2005-08-10 19:45:57] jameslee at cs dot nmt dot edu
edit:
It seems that my assumptions about how dates are handled were wrong and
the suggested patch actually does nothing. Therefore, I am unable to
suggest a solution.
------------------------------------------------------------------------
[2005-08-10 19:39:20] jameslee at cs dot nmt dot edu
Description:
------------
Empty day and month dropdowns from a date field cause an error.
Suggested patch:
Table.php, line 1586 from:
$m = (strlen($val['m']) < 2)
? '0'.$val['m'] : $val['m'];
$d = (strlen($val['d']) < 2)
? '0'.$val['d'] : $val['d'];
to:
$m = (strlen($val['m']) < 2)
? str_pad($val['m'],2,'0',STR_PAD_LEFT)
: $val['m'];
$d = (strlen($val['d']) < 2)
? str_pad($val['d'],2,'0',STR_PAD_LEFT)
: $val['d'];
Test script:
---------------
...
$col = array(
'Birthdate' = array(
'type' => 'date',
'qf_opts' => array(
'addEmptyOption' => TRUE,
'minYear' => 1920,
),
),
);
...
$tableObj->insert($values);
Expected result:
----------------
NULL or 0000-00-00 to be inserted; 0s seem easier
Actual result:
--------------
error:
Insert data not valid for column 'Birthdate' ('0000-0-0')
------------------------------------------------------------------------
--
Edit this bug report at http://pear.php.net/bugs/bug.php?id=5060&edit=1