Bug #16280 [Asn->Csd]: compareDefinition() turns NULL defaults into empty strings for NOT NULL columns

From: Date: Wed, 24 Oct 2012 14:25:00 +0000
Subject: Bug #16280 [Asn->Csd]: compareDefinition() turns NULL defaults into empty strings for NOT NULL columns
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-9215@lists.php.net to get a copy of this message
Edit report at https://pear.php.net/bugs/bug.php?id=16280&edit=1 ID: 16280 Updated by: danielc@analysisandsolutions.com Reported By: holger dot schletz at web dot de Summary: compareDefinition() turns NULL defaults into empty strings for NOT NULL columns -Status: Assigned +Status: Closed Type: Bug Package: MDB2 Package Version: 2.5.0b2 PHP Version: Irrelevant -Assigned To: quipo +Assigned To: danielc Roadmap Versions: New Comment: -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. Previous Comments: ------------------------------------------------------------------------ [2009-06-03 03:58:08] doconnor -Assigned To: +Assigned To: quipo ------------------------------------------------------------------------ [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 ( ) ------------------------------------------------------------------------ -- Edit this bug report at https://pear.php.net/bugs/bug.php?id=16280&edit=1

« previous php.pear.bugs (#9215) next »