Edit report at http://pear.php.net/bugs/bug.php?id=16280&edit=1
ID: 16280
Updated by: daniel.oconnor@gmail.com
Reported By: holger dot schletz at web dot de
Summary: compareDefinition() turns NULL defaults into empty
strings for NOT NULL columns
Status: Open
Type: Bug
Package: MDB2
Package Version: 2.5.0b2
PHP Version: Irrelevant
-Assigned To:
+Assigned To: quipo
Roadmap Versions:
New Comment:
-Assigned To:
+Assigned To: quipo
Previous Comments:
------------------------------------------------------------------------
[2009-06-02 16:56:17] hschletz
The following patch has been added/updated:
Patch Name: implicit-null-defaults
Revision: 1243958177
URL:
http://pear.php.net/bugs/patch-display.php?bug=16280&patch=implicit-null-defaults&revision=1243958177&display=1
------------------------------------------------------------------------
[2009-06-02 16:53:14] hschletz
The following patch has been added/updated:
Patch Name: implicit-null-defaults
Revision: 1243957994
URL:
http://pear.php.net/bugs/patch-display.php?bug=16280&patch=implicit-null-defaults&revision=1243957994&display=1
------------------------------------------------------------------------
[2009-06-02 16:52:39] hschletz
Description:
------------
I stumbled upon this bug when I tried to remove a default value (i.e.
setting it to NULL) with MDB2_Schema. The code example below is based on
the intermediate results from this operation.
It turned out to be a bug in the compareDefinition() method of the
MDB2_Driver_Datatype_Common class. If the column has the notnull
attribute set to true and the default attribute is not present in the
new definition, an empty string is assumed instead od NULL. In my case
the old value was an empty string, so that the change did not get
detected.
If the 'default' attribute is present and set to NULL, everything works
as expected. However, the assumption of the empty string is incorrect:
NULL is a perfectly valid default even for NOT NULL columns.
I'm not sure whether the MDB2_PORTABILITY_EMPTY_TO_NULL should affect
the behavior. The attached patch ignores this option.
Test script:
---------------
$previous =array (
'notnull' => true,
'nativetype' => 'varchar',
'length' => '50',
'fixed' => false,
'default' => '',
'type' => 'text',
'mdb2type' => 'text',
'was' => 'name'
);
$current = array (
'type' => 'text',
'length' => '50',
'notnull' => true,
'was' => 'name');
);
print_r ($mdb2->compareDefinition ($current, $previous));
Expected result:
----------------
array (
[default] => 1
)
Actual result:
--------------
array (
)
------------------------------------------------------------------------