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

Bug #16557 getTableFieldDefinition() returns bogus defaults for NOTNULL columns
Submitted: 2009-08-31 17:28 UTC
From: hschletz Assigned:
Status: Open Package: MDB2_Driver_mysql (version CVS)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2009-08-31 17:28 UTC] hschletz (Holger Schletz)
Description: ------------ If a column has a NOT NULL attribute and a default value of NULL, getTableFieldDefinition() changes the default to '' for text columns and '0000-00-00 00:00:00' for timestamp columns. This behavior is incorrect and not portable. There is no relationship between a NOT NULL constraint and a default value. MySQL reports a NULL default because the default is NULL, not '' or '0000-00-00 00:00:00'. The attached patch leaves the null value untouched. This also reverts the patch from #12336 completely, which says: "MySQL uses '0000-00-00 00:00:00' for any timestamp fields with 'NOT NULL'. This driver should set that for any non-null fields that it finds. This will make it work better with MDB2_Schema." I disagree (the following statements also apply to text columns): - The NOT NULL / DEFAULT NULL combination is expected to force the application to provide valid input data. Depending on server SQL mode, MySQL allows NULL anyway, turns it into a pseudo-NULL value and just throws a warning. See also: http://dev.mysql.com/doc/refman/5.0/en/constraint-invalid-data.html However, this behavior only applies to MySQL and only in a specific server SQL mode. It does not change the column's definition itself and should not leak out to the application, which might run in a different environment that behaves correctly. In this case it's really up to the developer to stop doing stupid things - MySQL with default settings cannot do this for us. - As MDB2_Schema is concerned, I had to disable these implicit conversions to make it work as expected.

Comments

 [2009-08-31 17:29 UTC] hschletz (Holger Schletz)
The following patch has been added/updated: Patch Name: do_not_convert_null_defaults Revision: 1251721798 URL: http://pear.php.net/bugs/patch-display.php?bug=16557&patch=do_not_convert_null_defaults&revision=1251721798&display=1