MDB2_Schema question

From: Date: Mon, 20 Feb 2006 05:48:25 +0000
Subject: MDB2_Schema question
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-41416@lists.php.net to get a copy of this message
Hi guys, (Not sure if this is a bug, so I'll just describe what happened.) I wanted to create an XML schema of a MySQL database, so I went: $dsn = 'mysql://root@localhost/dbname'; require_once 'MDB2/Schema.php'; $schema =& MDB2_Schema::factory($dsn); $dump_config = array( 'output_mode' => 'file', 'output' => 'whatever.xml' ); $schema->dumpDatabase($dump_config, MDB2_SCHEMA_DUMP_STRUCTURE); Worked fine, but there were no index definitions in the XML file. I peaked into the MDB2_Schema code and here's what I found: getDefinitionFromDatabase() has a call to: $indexes = $this->db->manager->listTableIndexes($table_name); which returns an array of indexes. Every index is passed to: $this->db->reverse->getTableIndexDefinition() which unfortunatelly returns a PEAR error, so no indexes are added to the XML result. getTableIndexDefinition() returns an error, because it passes the index name through: $index_name = $db->getIndexName($index_name); and then compares the index name with the result from $result = $db->query("SHOW INDEX FROM $table"); getIndexName() returns the index name plus an "_idx" appended and the check always fails. I was able to find a workaround by changing an MDB2 option: $mdb2->setOption('idxname_format', '%s'); The default option is '%s_idx' So my example that works is: $dsn = 'mysql://root@localhost/dbname'; require_once 'MDB2.php'; $mdb2 =& MDB2::factory($dsn); $mdb2->setOption('idxname_format', '%s'); require_once 'MDB2/Schema.php'; $schema =& MDB2_Schema::factory($mdb2); $dump_config = array( 'output_mode' => 'file', 'output' => 'whatever.xml' ); $schema->dumpDatabase($dump_config, MDB2_SCHEMA_DUMP_STRUCTURE); Long story, short message. The question is: is this the expected behaviour? Or is it me or my MySQL install. I also have the suspicion that other areas of the XML result might be affected, like the constraints. And last, when looking at the debug log ($schema->db->getDebugOutput()), I noticed queries like: SELECT MAX(sequence) FROM some_table_seq which should return the last consecutive number from the sequence table. This number is not in the XML result though. Is it normal? For the sequences I got only: <sequence> <name>some_table</name> </sequence> BTW, I was testing using: - MySQL 5.0.15 - MDB2_Schema - $Id: Schema.php,v 1.55 2006/01/22 18:38:07 lsmith Exp $ - MDB2_Driver_Reverse_mysql - $Id: mysql.php,v 1.41 2006/01/05 12:05:12 lsmith Exp $ - MDB2_Driver_mysql -$Id: mysql.php,v 1.96 2006/02/08 15:42:04 lsmith Exp $ Best, Stoyan -- Stoyan Stefanov http://www.phpied.com

« previous php.pear.dev (#41416) next »