function ExtractSchema($data = FALSE)
{
$old_mode = $this->db->SetFetchMode(ADODB_FETCH_NUM);
$schema = '<?xml version="1.0"?>' . "\n" . '<schema version="' . $this->schemaVersion . '">' . "\n";
if (is_array($tables = $this->db->MetaTables('TABLES'))) {
foreach ($tables as $table) {
$schema .= ' <table name="' . $table . '">' . "\n";
// grab details from database
$rs = $this->db->Execute('SELECT * FROM ' . $table . ' WHERE 1=1');
$fields = $this->db->MetaColumns($table);
$indexes = $this->db->MetaIndexes($table);
if (is_array($fields)) {
foreach ($fields as $details) {
$extra = '';
$content = array();
if ($details->max_length > 0) {
$extra .= ' size="' . $details->max_length . '"';
}
if ($details->primary_key) {
$content[] = '<KEY/>';
} elseif ($details->not_null) {
$content[] = '<NOTNULL/>';
}
if ($details->has_default) {
$content[] = '<DEFAULT value="' . $details->default_value . '"/>';
}
if ($details->auto_increment) {
$content[] = '<AUTOINCREMENT/>';
}
// this stops the creation of 'R' columns,
// AUTOINCREMENT is used to create auto columns
$details->primary_key = 0;
$type = $rs->MetaType($details);
$schema .= ' <field name="' . $details->name . '" type="' . $type . '"' . $extra . '>';
if (!empty($content)) {
$schema .= "\n\t\t\t" . implode("\n\t\t\t", $content) . "\n\t\t";
}
$schema .= '</field>' . "\n";
}
}
if (is_array($indexes)) {
foreach ($indexes as $index => $details) {
$schema .= ' <index name="' . $index . '">' . "\n";
if ($details['unique']) {
$schema .= ' <UNIQUE/>' . "\n";
}
foreach ($details['columns'] as $column) {
$schema .= ' <col>' . $column . '</col>' . "\n";
}
$schema .= ' </index>' . "\n";
}
}
if ($data) {
$rs = $this->db->Execute('SELECT * FROM ' . $table);
if (is_object($rs)) {
$schema .= ' <data>' . "\n";
while ($row = $rs->FetchRow()) {
foreach ($row as $key => $val) {
$row[$key] = htmlentities($val);
}
$schema .= ' <row><f>' . implode('</f><f>', $row) . '</f></row>' . "\n";
}
$schema .= ' </data>' . "\n";
}
}
$schema .= ' </table>' . "\n";
}
}
$this->db->SetFetchMode($old_mode);
$schema .= '</schema>';
return $schema;
}