* fixed Oracle code for installer and phpunit tests
authorJure Kajzer <freakolowsky@users.mediawiki.org>
Mon, 10 Jan 2011 19:22:27 +0000 (19:22 +0000)
committerJure Kajzer <freakolowsky@users.mediawiki.org>
Mon, 10 Jan 2011 19:22:27 +0000 (19:22 +0000)
* removed ORABlob class

includes/AutoLoader.php
includes/db/DatabaseOracle.php
includes/installer/DatabaseInstaller.php
includes/installer/OracleInstaller.php
maintenance/oracle/tables.sql
tests/phpunit/MediaWikiTestCase.php

index 617aa8c..d99bf51 100644 (file)
@@ -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',
index 28af807..86323d3 100644 (file)
@@ -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';
index dacb1d9..c212ef7 100644 (file)
@@ -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__ );
index 2f1dad7..4223402 100644 (file)
@@ -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 );
index cfbca0e..217fe1f 100644 (file)
@@ -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;
index d151178..4cd9c81 100644 (file)
@@ -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 ) {
                        }