FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=18057&edit=1

ID: 18057
Updated by: l.alberton@quipo.it
Reported By: holger dot schletz at web dot de
Summary: Result of getDeclaration() can have invalid syntax
-Status: Open
+Status: Closed
Type: Bug
Package: MDB2_Driver_mysql
Package Version: SVN
PHP Version: Irrelevant
-Assigned To:
+Assigned To: quipo
Roadmap Versions:
New Comment:

-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.




Previous Comments:
------------------------------------------------------------------------

[2010-11-14 18:43:05] hschletz

Added #patch
bug:18057;patch:fix-incorrect-sql-syntax.diff;revision:1289760185;.

------------------------------------------------------------------------

[2010-11-14 18:41:47] hschletz

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

------------------------------------------------------------------------

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedMar 6, '11 at 12:12p
activeMar 6, '11 at 12:12p
posts1
users1
websitepear.php.net

1 user in discussion

L Alberton: 1 post

People

Translate

site design / logo © 2022 Grokbase