| ';
$o.= ' ' . $this->str['confirmcheckbigints'] . ' ';
- if ($CFG->dbfamily == 'mysql') {
+ if ($dbfamily == 'mysql') {
$o.= ' ' . $this->str['mysqlextracheckbigints'] . ' ';
}
$o.= ' ';
@@ -140,10 +143,6 @@ class check_bigints extends XMLDBAction {
}
/// Load the XML file
$xmldb_file = new XMLDBFile($dbdir->path . '/install.xml');
- /// Load the needed XMLDB generator
- $classname = 'XMLDB' . $CFG->dbtype;
- $generator = new $classname();
- $generator->setPrefix($CFG->prefix);
/// Only if the file exists
if (!$xmldb_file->fileExists()) {
@@ -164,13 +163,11 @@ class check_bigints extends XMLDBAction {
/// Foreach table, process its fields
foreach ($xmldb_tables as $xmldb_table) {
/// Skip table if not exists
- if (!table_exists($xmldb_table)) {
+ if (!$dbman->table_exists($xmldb_table)) {
continue;
}
/// Fetch metadata from phisical DB. All the columns info.
- if ($metacolumns = $db->MetaColumns($CFG->prefix . $xmldb_table->getName())) {
- $metacolumns = array_change_key_case($metacolumns, CASE_LOWER);
- } else {
+ if (!$metacolumns = $DB->get_columns($xmldb_table->getName())) {
//// Skip table if no metacolumns is available for it
continue;
}
@@ -193,7 +190,7 @@ class check_bigints extends XMLDBAction {
/// Going to check this field in DB
$o.=' ' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' ';
/// Detect if the phisical field is wrong and, under mysql, check for incorrect signed fields too
- if ($metacolumn->type != $correct_type || ($CFG->dbfamily == 'mysql' && $xmldb_field->getUnsigned() && !$metacolumn->unsigned)) {
+ if ($metacolumn->type != $correct_type || ($dbfamily == 'mysql' && $xmldb_field->getUnsigned() && !$metacolumn->unsigned)) {
$o.='' . $this->str['wrong'] . '';
/// Add the wrong field to the list
$obj = new object;
@@ -233,18 +230,22 @@ class check_bigints extends XMLDBAction {
$xmldb_table = $obj->table;
$xmldb_field = $obj->field;
/// MySQL directly supports this
- if ($CFG->dbfamily == 'mysql') {
- $sqlarr = $xmldb_table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $xmldb_field, true);
+
+// TODO: move this hack to generators!!
+
+ if ($dbfamily == 'mysql') {
+ $sqlarr = $dbman->generator->getAlterFieldSQL($xmldb_table, $xmldb_field);
/// PostgreSQL (XMLDB implementation) is a bit, er... imperfect.
- } else if ($CFG->dbfamily == 'postgres') {
- $sqlarr = array('ALTER TABLE ' . $CFG->prefix . $xmldb_table->getName() .
+ } else if ($dbfamily == 'postgres') {
+ $sqlarr = array('ALTER TABLE ' . $DB->get_prefix() . $xmldb_table->getName() .
' ALTER COLUMN ' . $xmldb_field->getName() . ' TYPE BIGINT;');
}
$r.= ' ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' .
$this->str['field'] . ': ' . $xmldb_field->getName() . '';
/// Add to output if we have sentences
if ($sqlarr) {
- $s.= '' . str_replace("\n", ' ', implode(' ', $sqlarr)) . ' ';
+ $sqlarr = $dbman->generator->getEndedStatements($sqlarr);
+ $s.= '' . str_replace("\n", implode(' ', $sqlarr)). ' ';
}
}
$r.= ' ';
diff --git a/admin/xmldb/actions/check_defaults/check_defaults.class.php b/admin/xmldb/actions/check_defaults/check_defaults.class.php
index 0b9fa3fa964..5b22238f4c3 100644
--- a/admin/xmldb/actions/check_defaults/check_defaults.class.php
+++ b/admin/xmldb/actions/check_defaults/check_defaults.class.php
@@ -26,7 +26,7 @@
/// This class will check all the default values existing in the DB
/// match those specified in the xml specs
-/// and providing one SQL script to fix all them.
+/// and providing one SQL script to fix all them.
class check_defaults extends XMLDBAction {
@@ -76,10 +76,11 @@ class check_defaults extends XMLDBAction {
$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
- global $CFG, $XMLDB, $db;
+ global $CFG, $XMLDB, $DB;
/// And we nedd some ddl suff
require_once ($CFG->libdir . '/ddllib.php');
+ $dbman = $DB->get_manager();
/// Here we'll acummulate all the wrong fields found
$wrong_fields = array();
@@ -125,10 +126,6 @@ class check_defaults extends XMLDBAction {
}
/// Load the XML file
$xmldb_file = new XMLDBFile($dbdir->path . '/install.xml');
- /// Load the needed XMLDB generator
- $classname = 'XMLDB' . $CFG->dbtype;
- $generator = new $classname();
- $generator->setPrefix($CFG->prefix);
/// Only if the file exists
if (!$xmldb_file->fileExists()) {
@@ -142,7 +139,7 @@ class check_defaults extends XMLDBAction {
}
/// Arriving here, everything is ok, get the XMLDB structure
$structure = $xmldb_file->getStructure();
-//echo ""; print_r( $structure ); die;
+
$o.=' ' . str_replace($CFG->dirroot . '/', '', $dbdir->path . '/install.xml');
/// Getting tables
if ($xmldb_tables = $structure->getTables()) {
@@ -150,14 +147,11 @@ class check_defaults extends XMLDBAction {
/// Foreach table, process its fields
foreach ($xmldb_tables as $xmldb_table) {
/// Skip table if not exists
- if (!table_exists($xmldb_table)) {
+ if (!$dbman->table_exists($xmldb_table)) {
continue;
}
/// Fetch metadata from phisical DB. All the columns info.
- if ($metacolumns = $db->MetaColumns($CFG->prefix . $xmldb_table->getName())) {
- $metacolumns = array_change_key_case($metacolumns, CASE_LOWER);
-// echo "".$xmldb_table->getName(); print_r( $metacolumns ); die;
- } else {
+ if (!$metacolumns = $DB->get_columns($xmldb_table->getName())) {
//// Skip table if no metacolumns is available for it
continue;
}
@@ -167,33 +161,32 @@ class check_defaults extends XMLDBAction {
if ($xmldb_fields = $xmldb_table->getFields()) {
$o.=' ';
foreach ($xmldb_fields as $xmldb_field) {
-//echo " "; print_r( $xmldb_field ); die;
- // Get the default value for the field
- $xmldbdefault = $xmldb_field->getDefault();
-
- /// If the metadata for that column doesn't exist, skip
- if (!isset($metacolumns[$xmldb_field->getName()])) {
- continue;
- }
+ // Get the default value for the field
+ $xmldbdefault = $xmldb_field->getDefault();
- /// To variable for better handling
- $metacolumn = $metacolumns[$xmldb_field->getName()];
+ /// If the metadata for that column doesn't exist or 'id' field found, skip
+ if (!isset($metacolumns[$xmldb_field->getName()]) or $xmldb_field->getName() == 'id') {
+ continue;
+ }
- /// Going to check this field in DB
- $o.=' ' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' ';
+ /// To variable for better handling
+ $metacolumn = $metacolumns[$xmldb_field->getName()];
- // get the value of the physical default (or blank if there isn't one)
- if ($metacolumn->has_default==1) {
- $physicaldefault = $metacolumn->default_value;
- }
- else {
- $physicaldefault = '';
- }
+ /// Going to check this field in DB
+ $o.=' ' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' ';
- // there *is* a default and it's wrong
- if ($physicaldefault != $xmldbdefault) {
- $info = '['.$this->str['shouldbe']." '$xmldbdefault' ".$this->str['butis'].
+ // get the value of the physical default (or blank if there isn't one)
+ if ($metacolumn->has_default==1) {
+ $physicaldefault = $metacolumn->default_value;
+ }
+ else {
+ $physicaldefault = '';
+ }
+
+ // there *is* a default and it's wrong
+ if ($physicaldefault != $xmldbdefault) {
+ $info = '['.$this->str['shouldbe']." '$xmldbdefault' ".$this->str['butis'].
" '$physicaldefault']";
$o.='' . $this->str['wrong'] . " $info";
/// Add the wrong field to the list
@@ -237,9 +230,9 @@ class check_defaults extends XMLDBAction {
$xmldb_field = $obj->field;
$physicaldefault = $obj->physicaldefault;
$xmldbdefault = $obj->xmldbdefault;
-
+
// get the alter table command
- $sqlarr = $xmldb_table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $xmldb_field, true);
+ $sqlarr = $dbman->generator->getAlterFieldSQL($xmldb_table, $xmldb_field);
$r.= ' ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' .
$this->str['field'] . ': ' . $xmldb_field->getName() . ', ' .
@@ -247,6 +240,7 @@ class check_defaults extends XMLDBAction {
$this->str['butis'] . ' ' . "'$physicaldefault'" . '';
/// Add to output if we have sentences
if ($sqlarr) {
+ $sqlarr = $dbman->generator->getEndedStatements($sqlarr);
$s.= '' . str_replace("\n", ' ', implode(' ', $sqlarr)) . ' ';
}
}
diff --git a/admin/xmldb/actions/check_indexes/check_indexes.class.php b/admin/xmldb/actions/check_indexes/check_indexes.class.php
index e5989e6839c..a7596b36712 100644
--- a/admin/xmldb/actions/check_indexes/check_indexes.class.php
+++ b/admin/xmldb/actions/check_indexes/check_indexes.class.php
@@ -74,7 +74,9 @@ class check_indexes extends XMLDBAction {
$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
- global $CFG, $XMLDB;
+ global $CFG, $XMLDB, $DB;
+
+ $dbman = $DB->get_manager();
/// And we nedd some ddl suff
require_once ($CFG->libdir . '/ddllib.php');
@@ -123,10 +125,6 @@ class check_indexes extends XMLDBAction {
}
/// Load the XML file
$xmldb_file = new XMLDBFile($dbdir->path . '/install.xml');
- /// Load the needed XMLDB generator
- $classname = 'XMLDB' . $CFG->dbtype;
- $generator = new $classname();
- $generator->setPrefix($CFG->prefix);
/// Only if the file exists
if (!$xmldb_file->fileExists()) {
@@ -147,7 +145,7 @@ class check_indexes extends XMLDBAction {
/// Foreach table, process its indexes and keys
foreach ($xmldb_tables as $xmldb_table) {
/// Skip table if not exists
- if (!table_exists($xmldb_table)) {
+ if (!$dbman->table_exists($xmldb_table)) {
continue;
}
$o.=' ' . $xmldb_table->getName();
@@ -163,7 +161,7 @@ class check_indexes extends XMLDBAction {
}
/// If we aren't creating the keys or the key is a XMLDB_KEY_FOREIGN (not underlying index generated
/// automatically by the RDBMS) create the underlying (created by us) index (if doesn't exists)
- if (!$generator->getKeySQL($xmldb_table, $xmldb_key) || $xmldb_key->getType() == XMLDB_KEY_FOREIGN) {
+ if (!$dbman->generator->getKeySQL($xmldb_table, $xmldb_key) || $xmldb_key->getType() == XMLDB_KEY_FOREIGN) {
/// Create the interim index
$xmldb_index = new XMLDBIndex('anyname');
$xmldb_index->setFields($xmldb_key->getFields());
@@ -177,7 +175,7 @@ class check_indexes extends XMLDBAction {
break;
}
/// Check if the index exists in DB
- if (index_exists($xmldb_table, $xmldb_index)) {
+ if ($dbman->index_exists($xmldb_table, $xmldb_index)) {
$o.='' . $this->str['ok'] . '';
} else {
$o.='' . $this->str['missing'] . '';
@@ -198,7 +196,7 @@ class check_indexes extends XMLDBAction {
foreach ($xmldb_indexes as $xmldb_index) {
$o.=' ' . $this->str['index'] . ': ' . $xmldb_index->readableInfo() . ' ';
/// Check if the index exists in DB
- if (index_exists($xmldb_table, $xmldb_index)) {
+ if ($dbman->index_exists($xmldb_table, $xmldb_index)) {
$o.='' . $this->str['ok'] . '';
} else {
$o.='' . $this->str['missing'] . '';
@@ -237,11 +235,12 @@ class check_indexes extends XMLDBAction {
foreach ($missing_indexes as $obj) {
$xmldb_table = $obj->table;
$xmldb_index = $obj->index;
- $sqlarr = $xmldb_table->getAddIndexSQL($CFG->dbtype, $CFG->prefix, $xmldb_index, true);
+ $sqlarr = $dbman->generator->getAddIndexSQL($xmldb_table, $xmldb_index);
$r.= ' ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' .
$this->str['index'] . ': ' . $xmldb_index->readableInfo() . '';
+ $sqlarr = $dbman->generator->getEndedStatements($sqlarr);
$s.= '' . str_replace("\n", ' ', implode(' ', $sqlarr)) . ' ';
-
+
}
$r.= ' ';
/// Add the SQL statements (all together)
diff --git a/admin/xmldb/actions/edit_statement/edit_statement.class.php b/admin/xmldb/actions/edit_statement/edit_statement.class.php
index 7a9608a39f9..1e2a5faf797 100644
--- a/admin/xmldb/actions/edit_statement/edit_statement.class.php
+++ b/admin/xmldb/actions/edit_statement/edit_statement.class.php
@@ -103,7 +103,7 @@ class edit_statement extends XMLDBAction {
/// Add the main form
$o = ' |
|