Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.6

Bug #5060 empty date fields cause data to be invalid
Submitted: 2005-08-10 23:39 UTC
From: jameslee at cs dot nmt dot edu Assigned: wiesemann
Status: No Feedback Package: DB_Table
PHP Version: 4.3.11 OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 13 - 5 = ?

 
 [2005-08-10 23:39 UTC] 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')

Comments

 [2005-08-10 23:45 UTC] 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-16 17:37 UTC] 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-24 20:22 UTC] 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-09-10 14:40 UTC] 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.
 [2009-04-01 13:47 UTC] samwilson (Sam Wilson)
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.