PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_Table » Bug #2918

DB_Table::recast($data) timestamp zero packing

Details

Submitted2004-12-08 08:58 UTC
Fromsimon_massey at hotmail dot com
Assignedpmjones
StatusClosed
PackageDB_Table
PHP Version4.3.8
OSLinux (Fedora Core 2)
Roadmaps(Not assigned)

Comments

[2004-12-08 08:58 UTC] simon_massey at hotmail dot com

Description:
------------
I am using a timestamp column as a 'creation date'
attribute. I freeze the corresponding QuickForm element to
ensure that it is displayed in read-only format when
presenting a row for editing. I am rendering the QuickForm
for the row using HTML_QuickForm_Renderer_QuickHtml. This
results in the following html for the frozen timestamp:

2004<input type="hidden" name="property[createdate][Y]"
value="2004" />-12<input type="hidden"
name="property[createdate][m]" value="12" />-07<input
type="hidden" name="property[createdate][d]"
value="07" /> 21<input type="hidden"
name="property[createdate][H]" value="21" />:14<input
type="hidden" name="property[createdate][i]"
value="14" />:30<input type="hidden"
name="property[createdate][s]" value="30" />

Note that the hidden input value for the day entry is
'07'. When I come to save the form with an update command
the method DB_Table::recast($data) prepends a zero to the
'07' day value to give '007' resulting in the DB::Error
message:

Update data not valid for column createdate ('2004-12-007
21:14:30')

I provide a patch in a section below which fixes the issue
by inspecting the string length of the posted value rather
than its numeric conversion as php is evaluating
($val['d'] < 10) to be true where ($val['d'] == '07')
which always leads to a zero being prepended to the
string. I would expect the month field to be effected by
the same problem. The patch is agains the current release
of 0.22.

Reproduce code:
---------------
//-------------- reproduce issue

// set the creation date to be readonly
$createdateobj = $form->getElement('property[createdate]');
$createdateobj->freeze();

// set the form html renderer
$renderer =& new HTML_QuickForm_Renderer_QuickHtml();
$form->accept($renderer);

// render the form element into html
$createdate = $renderer->elementToHtml('property[createdate]');

// wrap form tag
$form_html = $renderer->toHtml($createdate);

//-------------- patch below this point

--- Table.php 2004-12-07 23:52:31.860798304 +0000
+++ Table2.php 2004-12-07 23:52:31.857798760 +0000
@@ -1435,7 +1435,7 @@
$m = ($val['m'] < 10)
? '0'.$val['m'] : $val['m'];

- $d = ($val['d'] < 10)
+ $d = (strlen($val['d']) < 2) // sjm
? '0'.$val['d'] : $val['d'];

$h = ($val['H'] < 10)

Expected result:
----------------