/** * Create required SQL tables. This function also performs upgrades of * table contents when required. * * @see SMWSql3SmwIds for documentation of the SMW IDs table. * * @since 1.8 * @param boolean $verbose * @param DatabaseBase $db used for writing */ protected function setupTables($verbose, $db) { global $wgDBtype; $reportTo = $verbose ? $this : null; // Use $this to report back from static SMWSQLHelpers. // Repeatedly used DB field types defined here for convenience. $dbtypes = array('b' => $wgDBtype == 'postgres' ? 'BOOLEAN' : 'TINYINT(1)', 't' => SMWSQLHelpers::getStandardDBType('title'), 'l' => SMWSQLHelpers::getStandardDBType('blob'), 'f' => $wgDBtype == 'postgres' ? 'DOUBLE PRECISION' : 'DOUBLE', 'i' => $wgDBtype == 'postgres' ? 'bigint' : 'INT(8)', 'j' => $wgDBtype == 'postgres' || $wgDBtype == 'sqlite' ? 'INTEGER' : 'INT(8) UNSIGNED', 'p' => SMWSQLHelpers::getStandardDBType('id'), 'n' => SMWSQLHelpers::getStandardDBType('namespace'), 'w' => SMWSQLHelpers::getStandardDBType('iw')); switch ($wgDBtype) { case 'sqlite': $idType = $dbtypes['p'] . ' NOT NULL PRIMARY KEY AUTOINCREMENT'; break; case 'postgres': $idType = $dbtypes['p'] . ' NOT NULL PRIMARY KEY'; break; default: $idType = $dbtypes['p'] . ' NOT NULL KEY AUTO_INCREMENT'; break; } // Set up table for internal IDs used in this store: SMWSQLHelpers::setupTable(SMWSQLStore3::ID_TABLE, array('smw_id' => $idType, 'smw_namespace' => $dbtypes['n'] . ' NOT NULL', 'smw_title' => $dbtypes['t'] . ' NOT NULL', 'smw_iw' => $dbtypes['w'] . ' NOT NULL', 'smw_subobject' => $dbtypes['t'] . ' NOT NULL', 'smw_sortkey' => $dbtypes['t'] . ' NOT NULL', 'smw_proptable_hash' => $dbtypes['l']), $db, $reportTo); SMWSQLHelpers::setupIndex(SMWSQLStore3::ID_TABLE, array('smw_id', 'smw_id,smw_sortkey', 'smw_iw', 'smw_title,smw_namespace,smw_iw,smw_subobject', 'smw_sortkey'), $db); // Set up concept cache: member elements (s)->concepts (o) SMWSQLHelpers::setupTable(SMWSQLStore3::CONCEPT_CACHE_TABLE, array('s_id' => $dbtypes['p'] . ' NOT NULL', 'o_id' => $dbtypes['p'] . ' NOT NULL'), $db, $reportTo); SMWSQLHelpers::setupIndex(SMWSQLStore3::CONCEPT_CACHE_TABLE, array('o_id'), $db); SMWSQLHelpers::setupTable(SMWSQLStore3::QUERY_LINKS_TABLE, array('s_id' => $dbtypes['p'] . ' NOT NULL', 'o_id' => $dbtypes['p'] . ' NOT NULL'), $db, $reportTo); SMWSQLHelpers::setupIndex(SMWSQLStore3::QUERY_LINKS_TABLE, array('s_id', 'o_id', 's_id,o_id'), $db); // Set up table for stats on Properties (only counts for now) SMWSQLHelpers::setupTable(SMWSQLStore3::PROPERTY_STATISTICS_TABLE, array('p_id' => $dbtypes['p'], 'usage_count' => $wgDBtype == 'postgres' ? $dbtypes['i'] : $dbtypes['j']), $db, $reportTo); SMWSQLHelpers::setupIndex(SMWSQLStore3::PROPERTY_STATISTICS_TABLE, array(array('p_id', 'UNIQUE INDEX'), 'usage_count'), $db); // Set up all property tables as defined: $this->setupPropertyTables($dbtypes, $db, $reportTo); $this->reportProgress("Database initialized successfully.\n\n", $verbose); }
/** * Create required SQL tables. This function also performs upgrades of * table contents when required. * * Documentation for the table smw_ids: This table is normally used to * store references to wiki pages (possibly with some external interwiki * prefix). There are, however, some special objects that are also * stored therein. These are marked by special interwiki prefixes (iw) * that cannot occcur in real life: * * - Rows with iw SMW_SQL3_SMWREDIIW are similar to normal entries for * (internal) wiki pages, but the iw indicates that the page is a * redirect, the target of which should be sought using the * smw_fpt_redi table. * * - The (unique) row with iw SMW_SQL3_SMWBORDERIW just marks the * border between predefined ids (rows that are reserved for hardcoded * ids built into SMW) and normal entries. It is no object, but makes * sure that SQL's auto increment counter is high enough to not add any * objects before that marked "border". */ protected function setupTables($verbose, $db) { global $wgDBtype; $reportTo = $verbose ? $this : null; // Use $this to report back from static SMWSQLHelpers. // Repeatedly used DB field types defined here for convenience. $dbtypes = array('b' => $wgDBtype == 'postgres' ? 'BOOLEAN' : 'TINYINT(1)', 't' => SMWSQLHelpers::getStandardDBType('title'), 'l' => SMWSQLHelpers::getStandardDBType('blob'), 'f' => $wgDBtype == 'postgres' ? 'DOUBLE PRECISION' : 'DOUBLE', 'i' => $wgDBtype == 'postgres' ? 'INTEGER' : 'INT(8)', 'j' => $wgDBtype == 'postgres' ? 'INTEGER' : 'INT(8) UNSIGNED', 'p' => SMWSQLHelpers::getStandardDBType('id'), 'n' => SMWSQLHelpers::getStandardDBType('namespace'), 'w' => SMWSQLHelpers::getStandardDBType('iw')); // Set up table for internal IDs used in this store: SMWSQLHelpers::setupTable('smw_ids', array('smw_id' => $dbtypes['p'] . ' NOT NULL' . ($wgDBtype == 'postgres' ? ' PRIMARY KEY' : ' KEY AUTO_INCREMENT'), 'smw_namespace' => $dbtypes['n'] . ' NOT NULL', 'smw_title' => $dbtypes['t'] . ' NOT NULL', 'smw_iw' => $dbtypes['w'] . ' NOT NULL', 'smw_subobject' => $dbtypes['t'] . ' NOT NULL', 'smw_sortkey' => $dbtypes['t'] . ' NOT NULL', 'smw_proptable_hash' => $dbtypes['l']), $db, $reportTo); SMWSQLHelpers::setupIndex('smw_ids', array('smw_id', 'smw_id,smw_sortkey', 'smw_title,smw_namespace,smw_iw,smw_subobject', 'smw_sortkey'), $db); // Set up concept cache: member elements (s)->concepts (o) SMWSQLHelpers::setupTable('smw_conccache', array('s_id' => $dbtypes['p'] . ' NOT NULL', 'o_id' => $dbtypes['p'] . ' NOT NULL'), $db, $reportTo); SMWSQLHelpers::setupIndex('smw_conccache', array('o_id'), $db); // Set up table for stats on Properties (only counts for now) SMWSQLHelpers::setupTable('smw_stats', array('pid' => $dbtypes['p'], 'usage_count' => $dbtypes['j']), $db, $reportTo); SMWSQLHelpers::setupIndex('smw_stats', array(array('pid', 'UNIQUE'), 'usage_count'), $db); // Set up all property tables as defined: $this->setupPropertyTables($dbtypes, $db, $reportTo); $this->reportProgress("Database initialised successfully.\n\n", $verbose); }
/** * Create required SQL tables. This function also performs upgrades of table contents * when required. */ protected function setupTables($verbose, $db) { $reportTo = $verbose ? $this : null; // Use $this to report back from static SMWSQLHelpers. SMWSQLHelpers::setupTable('smwsimple_data', array('pageid' => SMWSQLHelpers::getStandardDBType('id') . ' NOT NULL', 'propname' => SMWSQLHelpers::getStandardDBType('title') . ' NOT NULL', 'value' => SMWSQLHelpers::getStandardDBType('blob') . ' NOT NULL'), $db, $reportTo); SMWSQLHelpers::setupIndex('smwsimple_data', array('pageid', 'propname', 'propname,value(256)'), $db); SMWSQLHelpers::setupTable('smwsimple_special', array('pageid' => SMWSQLHelpers::getStandardDBType('id') . ' NOT NULL', 'propname' => SMWSQLHelpers::getStandardDBType('title') . ' NOT NULL', 'value' => SMWSQLHelpers::getStandardDBType('title') . ' NOT NULL'), $db, $reportTo); SMWSQLHelpers::setupIndex('smwsimple_special', array('pageid', 'pageid,propname', 'propname', 'propname,value'), $db); $this->reportProgress("Database initialised successfully.\n\n", $verbose); }
/** * Create required SQL tables. This function also performs upgrades of * table contents when required. * * Documentation for the table smw_ids: This table is normally used to * store references to wiki pages (possibly with some external interwiki * prefix). There are, however, some special objects that are also * stored therein. These are marked by special interwiki prefixes (iw) * that cannot occcur in real life: * * - Rows with iw SMW_SQL2_SMWREDIIW are similar to normal entries for * (internal) wiki pages, but the iw indicates that the page is a * redirect, the target of which should be sought using the smw_redi2 * table. * * - The (unique) row with iw SMW_SQL2_SMWBORDERIW just marks the * border between predefined ids (rows that are reserved for hardcoded * ids built into SMW) and normal entries. It is no object, but makes * sure that SQL's auto increment counter is high enough to not add any * objects before that marked "border". */ protected function setupTables( $verbose, $db ) { global $wgDBtype; $reportTo = $verbose ? $this : null; // Use $this to report back from static SMWSQLHelpers. // Repeatedly used DB field types defined here for convenience. $dbtypes = array( 't' => SMWSQLHelpers::getStandardDBType( 'title' ), 'l' => SMWSQLHelpers::getStandardDBType( 'blob' ), 'f' => ( $wgDBtype == 'postgres' ? 'DOUBLE PRECISION' : 'DOUBLE' ), 'i' => ( $wgDBtype == 'postgres' ? 'INTEGER' : 'INT(8)' ), 'j' => ( $wgDBtype == 'postgres' ? 'INTEGER' : 'INT(8) UNSIGNED' ), 'p' => SMWSQLHelpers::getStandardDBType( 'id' ), 'n' => SMWSQLHelpers::getStandardDBType( 'namespace' ), 'w' => SMWSQLHelpers::getStandardDBType( 'iw' ) ); $smw_spec2 = $db->tableName( 'smw_spec2' ); // DB update: field renaming between SMW 1.3 and SMW 1.4. if ( ( $db->tableExists( $smw_spec2 ) ) && ( $db->fieldExists( $smw_spec2, 'sp_id', __METHOD__ ) ) ) { if ( $wgDBtype == 'postgres' ) { $db->query( "ALTER TABLE $smw_spec2 ALTER COLUMN sp_id RENAME TO p_id", __METHOD__ ); } else { $db->query( "ALTER TABLE $smw_spec2 CHANGE `sp_id` `p_id` " . $dbtypes['p'] . " NOT NULL", __METHOD__ ); } } // Set up table for internal IDs used in this store: SMWSQLHelpers::setupTable( 'smw_ids', array( 'smw_id' => $dbtypes['p'] . ' NOT NULL' . ( $wgDBtype == 'postgres' ? ' PRIMARY KEY' : ' KEY AUTO_INCREMENT' ), 'smw_namespace' => $dbtypes['n'] . ' NOT NULL', 'smw_title' => $dbtypes['t'] . ' NOT NULL', 'smw_iw' => $dbtypes['w'] . ' NOT NULL', 'smw_subobject' => $dbtypes['t'] . ' NOT NULL', 'smw_sortkey' => $dbtypes['t'] . ' NOT NULL' ), $db, $reportTo ); SMWSQLHelpers::setupIndex( 'smw_ids', array( 'smw_id', 'smw_title,smw_namespace,smw_iw', 'smw_title,smw_namespace,smw_iw,smw_subobject', 'smw_sortkey' ), $db ); // Set up concept cache: member elements (s)->concepts (o) SMWSQLHelpers::setupTable( 'smw_conccache', array( 's_id' => $dbtypes['p'] . ' NOT NULL', 'o_id' => $dbtypes['p'] . ' NOT NULL' ), $db, $reportTo ); SMWSQLHelpers::setupIndex( 'smw_conccache', array( 'o_id' ), $db ); // Set up all property tables as defined: $this->setupPropertyTables( $dbtypes, $db, $reportTo ); $this->reportProgress( "Database initialised successfully.\n\n", $verbose ); }