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

Bug #10457 Dumping database from MySQL is not database agnositc re: Primary Keys
Submitted: 2007-03-22 16:41 UTC
From: fornax Assigned: ifeghali
Status: Closed Package: MDB2_Schema (version 0.7.1)
PHP Version: 4.3.11 OS: Centos 4.3, Apache 1.3
Roadmaps: (Not assigned)    
Subscription  


 [2007-03-22 16:41 UTC] fornax (Andrew Hill)
Description: ------------ When dumping a MySQL database, all primary keys are given an index name of "primary". This is not database agnositc for two reasons: 1) Although MySQL does not allow the naming of primary keys, other databases do allow (or require) primary keys to have names. As a result, some databases (eg. PostgreSQL) will compain that the primary key name "primary" is not permitted (as it's a reserved word, obviously). 2) Some databases (eg. PostgreSQL) require that all constraints have different names. So, each primary key must have a unique key name. I would propose that MDB2_Schema dumps out primary keys with the key name "{$table}_pkey", so that these two problems are resolved. (I'll see if I can get a patch done soon...)

Comments

 [2007-03-22 17:09 UTC] fornax (Andrew Hill)
--- MDB2/Schema/Writer.php (revision 5254) +++ MDB2/Schema/Writer.php (working copy) @@ -330,6 +330,9 @@ if (!empty($table['indexes']) && is_array($table['indexes'])) { foreach ($table['indexes'] as $index_name => $index) { + if ($index_name === 'primary') { + $index_name = $table_name . "_pkey"; + } $buffer.= "$eol <index>$eol <name>$index_name</name>$eol"; if (!empty($index['unique'])) { $buffer.= " <unique>".$this->_dumpBoolean($index['unique'])."</unique>$eol";
 [2007-03-22 21:08 UTC] ifeghali (Igor Feghali)
This bug has been fixed in CVS. 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.