PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB_Table » Bug #5060

empty date fields cause data to be invalid

Details

Submitted2005-08-10 23:39 UTC
Fromjameslee at cs dot nmt dot edu
Assignedwiesemann
StatusNo Feedback
PackageDB_Table
PHP Version4.3.11
OSIrrelevant
Roadmaps(Not assigned)

Comments

[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')

[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.