From f853d711accbc83b7930e18390e71c9dcd590170 Mon Sep 17 00:00:00 2001 From: Jure Kajzer Date: Mon, 10 Jan 2011 19:22:27 +0000 Subject: [PATCH] * fixed Oracle code for installer and phpunit tests * removed ORABlob class --- includes/AutoLoader.php | 1 - includes/db/DatabaseOracle.php | 91 +++++++++++++++--------- includes/installer/DatabaseInstaller.php | 1 + includes/installer/OracleInstaller.php | 21 +++--- maintenance/oracle/tables.sql | 1 - tests/phpunit/MediaWikiTestCase.php | 5 +- 6 files changed, 75 insertions(+), 45 deletions(-) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 617aa8c19f..d99bf51035 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -397,7 +397,6 @@ $wgAutoloadLocalClasses = array( 'LoadMonitor_MySQL' => 'includes/db/LoadMonitor.php', 'MySQLField' => 'includes/db/DatabaseMysql.php', 'MySQLMasterPos' => 'includes/db/DatabaseMysql.php', - 'ORABlob' => 'includes/db/DatabaseOracle.php', 'ORAField' => 'includes/db/DatabaseOracle.php', 'ORAResult' => 'includes/db/DatabaseOracle.php', 'PostgresField' => 'includes/db/DatabasePostgres.php', diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 28af807822..86323d32b9 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -6,21 +6,6 @@ * @ingroup Database */ -/** - * @ingroup Database - */ -class ORABlob { - var $mData; - - function __construct( $data ) { - $this->mData = $data; - } - - function getData() { - return $this->mData; - } -} - /** * The oci8 extension is fairly weak and doesn't support oci_num_rows, among * other things. We use a wrapper class to handle that and other @@ -491,7 +476,7 @@ class DatabaseOracle extends DatabaseBase { } if ( $val === null ) { - if ( $col_info != false && $col_info->nullable() == 0 && $col_info->defaultValue() != null ) { + if ( $col_info != false && $col_info->isNullable() == 0 && $col_info->defaultValue() != null ) { $bind .= 'DEFAULT'; } else { $bind .= 'NULL'; @@ -853,6 +838,37 @@ class DatabaseOracle extends DatabaseBase { return $this->doQuery( 'BEGIN DUPLICATE_TABLE(\'' . $tabName . '\', \'' . $oldPrefix . '\', \'' . strtoupper( $wgDBprefix ) . '\', ' . $temporary . '); END;' ); } + function listTables( $prefix = null, $fname = 'DatabaseOracle::listTables' ) { + $listWhere = ''; + if (!empty($prefix)) { + $listWhere = ' AND table_name LIKE \''.strtoupper($prefix).'%\''; + } + + $result = $this->doQuery( "SELECT table_name FROM user_tables WHERE table_name NOT LIKE '%!_IDX$_' ESCAPE '!' $listWhere" ); + + // dirty code ... i know + $endArray = array(); + $endArray[] = $prefix.'MWUSER'; + $endArray[] = $prefix.'PAGE'; + $endArray[] = $prefix.'IMAGE'; + $fixedOrderTabs = $endArray; + while (($row = $result->fetchRow()) !== false) { + if (!in_array($row['table_name'], $fixedOrderTabs)) + $endArray[] = $row['table_name']; + } + + return $endArray; + } + + public function dropTable( $tableName, $fName = 'DatabaseOracle::dropTable' ) { + $tableName = $this->tableName($tableName); + if( !$this->tableExists( $tableName ) ) { + return false; + } + + return $this->doQuery( "DROP TABLE $tableName CASCADE CONSTRAINTS PURGE" ); + } + function timestamp( $ts = 0 ) { return wfTimestamp( TS_ORACLE, $ts ); } @@ -1046,7 +1062,7 @@ class DatabaseOracle extends DatabaseBase { } } else { foreach ( $replacements as $mwVar => $scVar ) { - $cmd = str_replace( '&' . $scVar . '.', '{$' . $mwVar . '}', $cmd ); + $cmd = str_replace( '&' . $scVar . '.', '`{$' . $mwVar . '}`', $cmd ); } $cmd = $this->replaceVars( $cmd ); @@ -1094,24 +1110,35 @@ class DatabaseOracle extends DatabaseBase { return "'" . $this->strencode( $s ) . "'"; } + public function addIdentifierQuotes( $s ) { + if ( !$this->mFlags & DBO_DDLMODE ) { + $s = '"' . str_replace( '"', '""', $s ) . '"'; + } + return $s; + } + function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) { global $wgContLang; - $conds2 = array(); - $conds = ( $conds != null && !is_array( $conds ) ) ? array( $conds ) : $conds; - foreach ( $conds as $col => $val ) { - $col_info = $this->fieldInfoMulti( $table, $col ); - $col_type = $col_info != false ? $col_info->type() : 'CONSTANT'; - if ( $col_type == 'CLOB' ) { - $conds2['TO_CHAR(' . $col . ')'] = $wgContLang->checkTitleEncoding( $val ); - } elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) { - $conds2[$col] = $wgContLang->checkTitleEncoding( $val ); - } else { - $conds2[$col] = $val; + if ($conds != null) { + $conds2 = array(); + $conds = ( !is_array( $conds ) ) ? array( $conds ) : $conds; + foreach ( $conds as $col => $val ) { + $col_info = $this->fieldInfoMulti( $table, $col ); + $col_type = $col_info != false ? $col_info->type() : 'CONSTANT'; + if ( $col_type == 'CLOB' ) { + $conds2['TO_CHAR(' . $col . ')'] = $wgContLang->checkTitleEncoding( $val ); + } elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) { + $conds2[$col] = $wgContLang->checkTitleEncoding( $val ); + } else { + $conds2[$col] = $val; + } } + + return parent::selectRow( $table, $vars, $conds2, $fname, $options, $join_conds ); + } else { + return parent::selectRow( $table, $vars, $conds, $fname, $options, $join_conds ); } - - return parent::selectRow( $table, $vars, $conds2, $fname, $options, $join_conds ); } /** @@ -1160,9 +1187,9 @@ class DatabaseOracle extends DatabaseBase { public function delete( $table, $conds, $fname = 'DatabaseOracle::delete' ) { global $wgContLang; - if ( $wgContLang != null && $conds != '*' ) { + if ( $wgContLang != null && $conds != null && $conds != '*' ) { $conds2 = array(); - $conds = ( $conds != null && !is_array( $conds ) ) ? array( $conds ) : $conds; + $conds = ( !is_array( $conds ) ) ? array( $conds ) : $conds; foreach ( $conds as $col => $val ) { $col_info = $this->fieldInfoMulti( $table, $col ); $col_type = $col_info != false ? $col_info->type() : 'CONSTANT'; diff --git a/includes/installer/DatabaseInstaller.php b/includes/installer/DatabaseInstaller.php index dacb1d9faa..c212ef7e4a 100644 --- a/includes/installer/DatabaseInstaller.php +++ b/includes/installer/DatabaseInstaller.php @@ -129,6 +129,7 @@ abstract class DatabaseInstaller { return $status; } + $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files $error = $this->db->sourceFile( $this->db->getSchema() ); if( $error !== true ) { $this->db->reportQueryError( $error, 0, '', __METHOD__ ); diff --git a/includes/installer/OracleInstaller.php b/includes/installer/OracleInstaller.php index 2f1dad7561..4223402e28 100644 --- a/includes/installer/OracleInstaller.php +++ b/includes/installer/OracleInstaller.php @@ -24,9 +24,10 @@ class OracleInstaller extends DatabaseInstaller { protected $internalDefaults = array( '_OracleDefTS' => 'USERS', - '_OracleTempTS' => 'TEMP', - '_OracleUseSysdba' => true + '_OracleTempTS' => 'TEMP' ); + + protected $useSysDBA = false; public $minimumVersion = '9.0.1'; // 9iR1 @@ -92,6 +93,7 @@ class OracleInstaller extends DatabaseInstaller { } // Try to connect + $this->useSysDBA = true; $status = $this->getConnection(); if ( !$status->isOK() ) { return $status; @@ -110,13 +112,13 @@ class OracleInstaller extends DatabaseInstaller { public function getConnection() { $status = Status::newGood(); try { - if ( $this->getVar( '_OracleUseSysdba' ) ) { + if ( $this->useSysDBA ) { $this->db = new DatabaseOracle( $this->getVar( 'wgDBserver' ), $this->getVar( '_InstallUser' ), $this->getVar( '_InstallPassword' ), $this->getVar( 'wgDBname' ), - DBO_SYSDBA, + DBO_SYSDBA | DBO_DDLMODE, $this->getVar( 'wgDBprefix' ) ); } else { @@ -147,17 +149,15 @@ class OracleInstaller extends DatabaseInstaller { public function preInstall() { # Add our user callback to installSteps, right before the tables are created. $callback = array( - array( - 'name' => 'user', - 'callback' => array( $this, 'setupUser' ), - ) + 'name' => 'user', + 'callback' => array( $this, 'setupUser' ) ); $this->parent->addInstallStep( $callback, 'database' ); } public function setupDatabase() { - $this->parent->setVar( '_OracleUseSysdba', false ); + $this->useSysDBA = false; $status = Status::newGood(); return $status; } @@ -168,6 +168,8 @@ class OracleInstaller extends DatabaseInstaller { if ( !$this->getVar( '_CreateDBAccount' ) ) { return Status::newGood(); } + + $this->useSysDBA = true; $status = $this->getConnection(); if ( !$status->isOK() ) { return $status; @@ -180,6 +182,7 @@ class OracleInstaller extends DatabaseInstaller { */ $GLOBALS['_OracleDefTS'] = $this->getVar( '_OracleDefTS' ); $GLOBALS['_OracleTempTS'] = $this->getVar( '_OracleTempTS' ); + $this->db->setFlag( DBO_DDLMODE ); $error = $this->db->sourceFile( "$IP/maintenance/oracle/user.sql" ); if ( $error !== true || !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) { $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error ); diff --git a/maintenance/oracle/tables.sql b/maintenance/oracle/tables.sql index cfbca0e4b3..217fe1fa9b 100644 --- a/maintenance/oracle/tables.sql +++ b/maintenance/oracle/tables.sql @@ -803,7 +803,6 @@ BEGIN FROM user_triggers WHERE table_name = p_oldprefix || p_tabname) LOOP l_temp_ei_sql := SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'ALTER ') - 1); - dbms_output.put_line(l_temp_ei_sql); EXECUTE IMMEDIATE l_temp_ei_sql; END LOOP; END; diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index d15117886e..4cd9c8152f 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -18,7 +18,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected $supportedDBs = array( 'mysql', - 'sqlite' + 'sqlite', + 'oracle' ); function __construct( $name = null, array $data = array(), $dataName = '' ) { @@ -155,7 +156,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { foreach ( $tables as $table ) { try { - $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table DROP CONSTRAINTS" : "DROP TABLE `$table`"; + $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table CASCADE CONSTRAINTS PURGE" : "DROP TABLE `$table`"; $this->db->query( $sql, __METHOD__ ); } catch( Exception $e ) { } -- 2.20.1