List Info

Thread: MDB2_Schema question




MDB2_Schema question
user name
2006-02-20 05:48:25
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://rootlocalhost/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://rootlocalhost/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

-- 
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

MDB2_Schema question
user name
2006-02-20 12:12:19
Stoyan Stefanov wrote:

> I was able to find a workaround by changing an MDB2
option:
> $mdb2->setOption('idxname_format', '%s');
> The default option is '%s_idx'

thats the proper way to do things indeed.

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

it is the expected behavior. mdb2 by default runs in maximum
portability 
mode. for this to work mdb2 needs to enforce some specific
datatypes and 
naming conventions. the aim is to have all of this optional.

so the idea is that people can either "step into mdb2
portability world" 
and change their schemas accordingly and gain a very high
level of 
portability.

if they do not want to do this, they should just need to
change a few 
options to be able to get around all of this portability
stuff.

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

You only requested to get a dump of the structure. But it
seems odd that 
  this query is still executed. Could you file a bug report
on this, so 
I do not forget to investigate this?

regards,
Lukas

-- 
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )