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

Bug #18057 Result of getDeclaration() can have invalid syntax
Submitted: 2010-11-14 23:41 UTC
From: hschletz Assigned: quipo
Status: Closed Package: MDB2_Driver_mysql (version SVN)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2010-11-14 23:41 UTC] hschletz (Holger Schletz)
Description: ------------ MySQL DDL syntax forbids combining NOT NULL with DEFAULT NULL. This is merely a syntactical twist: having a default of NULL for NOT NULL columns is perfectly valid, but the DEFAULT NULL part must be omitted to achieve this, i.e. no default must be specified at all. However, the SQL fragment returned by getDeclaration() in this case is invalid for MySQL. As a consequence, it's impossible do drop a non-NULL default (equivalent to setting it to NULL) using MDB2_Schema. There may be other consequences as well. The attached patch overrides getDeclaration() for the mysql driver, dropping the default before calling the parent's implementation if the conditions are met. This is preferred over altering the implementation in the base class because this problem is specific to MySQL's syntax. The mysqli driver appears to be affected as well and the solution would be the same, but I haven't tested this. Test script: --------------- $field = array( 'type' => 'integer', 'length' => 4, 'notnull' => true, 'was' => 'foo', 'default' => null ); print $mdb2->getDeclaration('integer', 'foo', $field); Expected result: ---------------- `foo` INT NOT NULL (this will actually result in no default, i.e. a default of NULL, as requested) Actual result: -------------- `foo` INT DEFAULT NULL NOT NULL

Comments

 [2010-11-14 23:43 UTC] hschletz (Holger Schletz)
 [2011-03-06 18:15 UTC] quipo (Lorenzo Alberton)
-Status: Open +Status: Closed -Assigned To: +Assigned To: quipo
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.