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

Bug #16280 compareDefinition() turns NULL defaults into empty strings for NOT NULL columns
Submitted: 2009-06-02 20:52 UTC
From: hschletz Assigned: danielc
Status: Closed Package: MDB2 (version 2.5.0b2)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2009-06-02 20:52 UTC] hschletz (Holger Schletz)
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 ( )

Comments

 [2009-06-02 20:53 UTC] hschletz (Holger Schletz)
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 20:56 UTC] hschletz (Holger Schletz)
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-03 07:58 UTC] doconnor (Daniel O'Connor)
-Assigned To: +Assigned To: quipo
 [2012-10-24 19:25 UTC] danielc (Daniel Convissor)
-Status: Assigned +Status: Closed -Assigned To: quipo +Assigned To: danielc
Added patch and test to SVN. The change will show up in the next release.