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)    
Comments Add Comment Add patch

Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem : 28 + 26 = ?

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


 [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 by the end of next Sunday (CET). If this was a problem with the 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.