public function deleteDatabaseTables() { global $wgDBtype; $db =& wfGetDB(DB_MASTER); $verbose = true; DBHelper::reportProgress("Dropping materialization tables ...\n", $verbose); $db->query('DROP TABLE' . ($wgDBtype == 'postgres' ? '' : ' IF EXISTS') . $this->smw_ws_materialization_hashes, 'WSStorageSQL::drop'); DBHelper::reportProgress(" ... dropped table {$this->smw_ws_materialization_hashes}.\n", $verbose); DBHelper::reportProgress(" ... done!\n", $verbose); }
public function dropTables() { $db =& wfGetDB(DB_MASTER); $verbose = true; DBHelper::reportProgress("Dropping query results cache tables ...\n", $verbose); $tables = array('smw_qrc_cache'); foreach ($tables as $table) { $name = $db->tableName($table); $db->query('DROP TABLE' . ($wgDBtype == 'postgres' ? '' : ' IF EXISTS') . $name, 'SMWQRCSQLStore::drop'); DBHelper::reportProgress(" ... dropped table {$name}.\n", $verbose); } DBHelper::reportProgress(" ... done!\n", $verbose); }
/** * Make sure the table of the given name has the given fields, provided * as an array with entries fieldname => typeparams. typeparams should be * in a normalised form and order to match to existing values. * * The function returns an array that includes all columns that have been * changed. For each such column, the array contains an entry * columnname => action, where action is one of 'up', 'new', or 'del' * If the table was already fine or was created completely anew, an empty * array is returned (assuming that both cases require no action). * * NOTE: the function partly ignores the order in which fields are set up. * Only if the type of some field changes will its order be adjusted explicitly. * * @param string $primaryKeys * This optional string specifies the primary keys if there is more * than one. This is a comma separated list of column names. The primary * keys are not altered, if the table already exists. */ public static function setupTable($table, $fields, $db, $verbose, $primaryKeys = "") { global $wgDBname; DBHelper::reportProgress("Setting up table {$table} ...\n", $verbose); if ($db->tableExists($table) === false) { // create new table $sql = 'CREATE TABLE ' . $wgDBname . '.' . $table . ' ('; $first = true; foreach ($fields as $name => $type) { if ($first) { $first = false; } else { $sql .= ','; } $sql .= $name . ' ' . $type; } if (!empty($primaryKeys)) { $sql .= ", PRIMARY KEY(" . $primaryKeys . ")"; } $sql .= ') TYPE=innodb'; $db->query($sql, 'DBHelper::setupTable'); DBHelper::reportProgress(" ... new table created\n", $verbose); return array(); } else { // check table signature DBHelper::reportProgress(" ... table exists already, checking structure ...\n", $verbose); $res = $db->query('DESCRIBE ' . $table, 'DBHelper::setupTable'); $curfields = array(); $result = array(); while ($row = $db->fetchObject($res)) { $type = strtoupper($row->Type); if ($row->Null != 'YES') { $type .= ' NOT NULL'; } $curfields[$row->Field] = $type; } $position = 'FIRST'; foreach ($fields as $name => $type) { if (!array_key_exists($name, $curfields)) { DBHelper::reportProgress(" ... creating column {$name} ... ", $verbose); $db->query("ALTER TABLE {$table} ADD `{$name}` {$type} {$position}", 'DBHelper::setupTable'); $result[$name] = 'new'; DBHelper::reportProgress("done \n", $verbose); } elseif ($curfields[$name] != $type && stripos("auto_increment", $type) == -1) { DBHelper::reportProgress(" ... changing type of column {$name} from '{$curfields[$name]}' to '{$type}' ... ", $verbose); $db->query("ALTER TABLE {$table} CHANGE `{$name}` `{$name}` {$type} {$position}", 'DBHelper::setupTable'); $result[$name] = 'up'; $curfields[$name] = false; DBHelper::reportProgress("done.\n", $verbose); } else { DBHelper::reportProgress(" ... column {$name} is fine\n", $verbose); $curfields[$name] = false; } $position = "AFTER {$name}"; } foreach ($curfields as $name => $value) { if ($value !== false) { // not encountered yet --> delete DBHelper::reportProgress(" ... deleting obsolete column {$name} ... ", $verbose); $db->query("ALTER TABLE {$table} DROP COLUMN `{$name}`", 'DBHelper::setupTable'); $result[$name] = 'del'; DBHelper::reportProgress("done.\n", $verbose); } } DBHelper::reportProgress(" ... table {$table} set up successfully.\n", $verbose); return $result; } }
/** * Initializes the logging component */ protected function setupLogging($verbose) { DBHelper::reportProgress(" ... Creating logging database \n", $verbose); global $wgDBname; $db =& wfGetDB(DB_MASTER); // create gardening table $smw_logging = $db->tableName('smw_logging'); $fname = 'SMW::setupLogging'; // create relation table DBHelper::setupTable($smw_logging, array('id' => 'INT(10) UNSIGNED NOT NULL auto_increment PRIMARY KEY', 'timestamp' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP', 'user' => 'VARCHAR(255)', 'location' => 'VARCHAR(255)', 'type' => 'VARCHAR(255)', 'function' => 'VARCHAR(255)', 'remotetimestamp' => 'VARCHAR(255)', 'text' => 'LONGTEXT'), $db, $verbose); DBHelper::reportProgress(" ... done!\n", $verbose); }
public function deleteDatabaseTables() { global $wgDBtype; $db =& wfGetDB(DB_MASTER); $verbose = true; DBHelper::reportProgress("Dropping web service tables ...\n", $verbose); $tables = array('smw_ws_wwsd', 'smw_ws_cache', 'smw_ws_parameters', 'smw_ws_articles'); foreach ($tables as $table) { $name = $db->tableName($table); $db->query('DROP TABLE' . ($wgDBtype == 'postgres' ? '' : ' IF EXISTS') . $name, 'WSStorageSQL::drop'); DBHelper::reportProgress(" ... dropped table {$name}.\n", $verbose); } DBHelper::reportProgress(" ... done!\n", $verbose); }