manager->xpdo->package; if (empty ($baseClass)) $baseClass= 'xPDOObject'; if (empty ($tablePrefix)) $tablePrefix= $this->manager->xpdo->config[xPDO::OPT_TABLE_PREFIX]; $schemaVersion = xPDO::SCHEMA_VERSION; $xmlContent = array(); $xmlContent[] = ""; $xmlContent[] = ""; //read list of tables $tableLike= ($tablePrefix && $restrictPrefix) ? " LIKE '{$tablePrefix}%'" : ''; $tablesStmt= $this->manager->xpdo->query("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"); $tables= $tablesStmt->fetchAll(PDO::FETCH_NUM); if ($this->manager->xpdo->getDebug() === true) $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, print_r($tables, true)); foreach ($tables as $table) { $xmlObject= array(); $xmlFields= array(); $xmlIndices= array(); if (!$tableName= $this->getTableName($table[0], $tablePrefix, $restrictPrefix)) { continue; } $class= $this->getClassName($tableName); $extends= $baseClass; $fieldsStmt= $this->manager->xpdo->query("PRAGMA table_info({$table[0]})"); $fields= $fieldsStmt->fetchAll(PDO::FETCH_ASSOC); if ($this->manager->xpdo->getDebug() === true) $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Fields for table {$table[0]}: " . print_r($fields, true)); $cid = 0; foreach ($fields as $field) { $name = ''; $type = ''; $notnull = 0; $dflt_value = null; $pk = 0; extract($field, EXTR_OVERWRITE); $Field= $name; $PhpType= $this->manager->xpdo->driver->getPhpType($type); $Null= ' null="' . ($notnull ? 'false' : 'true') . '"'; $Default= $this->getDefault($dflt_value); $Extra= ''; if (!empty($pk)) { if (preg_match('/INT/i', $type)) { if ($baseClass === 'xPDOObject' && $Field === 'id') { $extends= 'xPDOSimpleObject'; continue; } elseif ($cid == 0) { $Extra= ' generated="native"'; } } $Key = ' index="pk"'; } else { $Key = $this->getIndex($field); } $xmlFields[]= "\t\t"; $cid++; } $indicesStmt= $this->manager->xpdo->query("PRAGMA index_list({$table[0]})"); $indices= $indicesStmt->fetchAll(PDO::FETCH_ASSOC); if ($this->manager->xpdo->getDebug() === true) $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Indices for table {$table[0]}: " . print_r($indices, true)); foreach ($indices as $index) { $primary = preg_match('/^sqlite_autoindex/', $index['name']) ? 'true' : 'false'; $unique = !empty($index['unique']) ? 'true' : 'false'; $xmlIndices[]= "\t\t"; $columnsStmt = $this->manager->xpdo->query("PRAGMA index_info({$index['name']})"); $columns = $columnsStmt->fetchAll(PDO::FETCH_ASSOC); if ($this->manager->xpdo->getDebug() === true) $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Columns of index {$index['name']}: " . print_r($columns, true)); foreach ($columns as $column) { $xmlIndices[]= "\t\t\t"; } $xmlIndices[]= "\t\t"; } $xmlObject[] = "\t"; $xmlObject[] = implode("\n", $xmlFields); if (!empty($xmlIndices)) { $xmlObject[] = ''; $xmlObject[] = implode("\n", $xmlIndices); } $xmlObject[] = "\t"; $xmlContent[] = implode("\n", $xmlObject); } $xmlContent[] = ""; if ($this->manager->xpdo->getDebug() === true) { $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, implode("\n", $xmlContent)); } $file= fopen($schemaFile, 'wb'); $written= fwrite($file, implode("\n", $xmlContent)); fclose($file); return true; } }