r79951 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79950‎ | r79951 | r79952 >
Date:19:22, 10 January 2011
Author:freakolowsky
Status:ok
Tags:
Comment:
* fixed Oracle code for installer and phpunit tests
* removed ORABlob class
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/installer/DatabaseInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/OracleInstaller.php (modified) (history)
  • /trunk/phase3/maintenance/oracle/tables.sql (modified) (history)
  • /trunk/phase3/tests/phpunit/MediaWikiTestCase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/oracle/tables.sql
@@ -803,7 +803,6 @@
804804 FROM user_triggers
805805 WHERE table_name = p_oldprefix || p_tabname) LOOP
806806 l_temp_ei_sql := SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'ALTER ') - 1);
807 - dbms_output.put_line(l_temp_ei_sql);
808807 EXECUTE IMMEDIATE l_temp_ei_sql;
809808 END LOOP;
810809 END;
Index: trunk/phase3/tests/phpunit/MediaWikiTestCase.php
@@ -18,7 +18,8 @@
1919
2020 protected $supportedDBs = array(
2121 'mysql',
22 - 'sqlite'
 22+ 'sqlite',
 23+ 'oracle'
2324 );
2425
2526 function __construct( $name = null, array $data = array(), $dataName = '' ) {
@@ -155,7 +156,7 @@
156157
157158 foreach ( $tables as $table ) {
158159 try {
159 - $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table DROP CONSTRAINTS" : "DROP TABLE `$table`";
 160+ $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table CASCADE CONSTRAINTS PURGE" : "DROP TABLE `$table`";
160161 $this->db->query( $sql, __METHOD__ );
161162 } catch( Exception $e ) {
162163 }
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -7,21 +7,6 @@
88 */
99
1010 /**
11 - * @ingroup Database
12 - */
13 -class ORABlob {
14 - var $mData;
15 -
16 - function __construct( $data ) {
17 - $this->mData = $data;
18 - }
19 -
20 - function getData() {
21 - return $this->mData;
22 - }
23 -}
24 -
25 -/**
2611 * The oci8 extension is fairly weak and doesn't support oci_num_rows, among
2712 * other things. We use a wrapper class to handle that and other
2813 * Oracle-specific bits, like converting column names back to lowercase.
@@ -491,7 +476,7 @@
492477 }
493478
494479 if ( $val === null ) {
495 - if ( $col_info != false && $col_info->nullable() == 0 && $col_info->defaultValue() != null ) {
 480+ if ( $col_info != false && $col_info->isNullable() == 0 && $col_info->defaultValue() != null ) {
496481 $bind .= 'DEFAULT';
497482 } else {
498483 $bind .= 'NULL';
@@ -853,6 +838,37 @@
854839 return $this->doQuery( 'BEGIN DUPLICATE_TABLE(\'' . $tabName . '\', \'' . $oldPrefix . '\', \'' . strtoupper( $wgDBprefix ) . '\', ' . $temporary . '); END;' );
855840 }
856841
 842+ function listTables( $prefix = null, $fname = 'DatabaseOracle::listTables' ) {
 843+ $listWhere = '';
 844+ if (!empty($prefix)) {
 845+ $listWhere = ' AND table_name LIKE \''.strtoupper($prefix).'%\'';
 846+ }
 847+
 848+ $result = $this->doQuery( "SELECT table_name FROM user_tables WHERE table_name NOT LIKE '%!_IDX$_' ESCAPE '!' $listWhere" );
 849+
 850+ // dirty code ... i know
 851+ $endArray = array();
 852+ $endArray[] = $prefix.'MWUSER';
 853+ $endArray[] = $prefix.'PAGE';
 854+ $endArray[] = $prefix.'IMAGE';
 855+ $fixedOrderTabs = $endArray;
 856+ while (($row = $result->fetchRow()) !== false) {
 857+ if (!in_array($row['table_name'], $fixedOrderTabs))
 858+ $endArray[] = $row['table_name'];
 859+ }
 860+
 861+ return $endArray;
 862+ }
 863+
 864+ public function dropTable( $tableName, $fName = 'DatabaseOracle::dropTable' ) {
 865+ $tableName = $this->tableName($tableName);
 866+ if( !$this->tableExists( $tableName ) ) {
 867+ return false;
 868+ }
 869+
 870+ return $this->doQuery( "DROP TABLE $tableName CASCADE CONSTRAINTS PURGE" );
 871+ }
 872+
857873 function timestamp( $ts = 0 ) {
858874 return wfTimestamp( TS_ORACLE, $ts );
859875 }
@@ -1046,7 +1062,7 @@
10471063 }
10481064 } else {
10491065 foreach ( $replacements as $mwVar => $scVar ) {
1050 - $cmd = str_replace( '&' . $scVar . '.', '{$' . $mwVar . '}', $cmd );
 1066+ $cmd = str_replace( '&' . $scVar . '.', '`{$' . $mwVar . '}`', $cmd );
10511067 }
10521068
10531069 $cmd = $this->replaceVars( $cmd );
@@ -1094,24 +1110,35 @@
10951111 return "'" . $this->strencode( $s ) . "'";
10961112 }
10971113
 1114+ public function addIdentifierQuotes( $s ) {
 1115+ if ( !$this->mFlags & DBO_DDLMODE ) {
 1116+ $s = '"' . str_replace( '"', '""', $s ) . '"';
 1117+ }
 1118+ return $s;
 1119+ }
 1120+
10981121 function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) {
10991122 global $wgContLang;
11001123
1101 - $conds2 = array();
1102 - $conds = ( $conds != null && !is_array( $conds ) ) ? array( $conds ) : $conds;
1103 - foreach ( $conds as $col => $val ) {
1104 - $col_info = $this->fieldInfoMulti( $table, $col );
1105 - $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
1106 - if ( $col_type == 'CLOB' ) {
1107 - $conds2['TO_CHAR(' . $col . ')'] = $wgContLang->checkTitleEncoding( $val );
1108 - } elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) {
1109 - $conds2[$col] = $wgContLang->checkTitleEncoding( $val );
1110 - } else {
1111 - $conds2[$col] = $val;
 1124+ if ($conds != null) {
 1125+ $conds2 = array();
 1126+ $conds = ( !is_array( $conds ) ) ? array( $conds ) : $conds;
 1127+ foreach ( $conds as $col => $val ) {
 1128+ $col_info = $this->fieldInfoMulti( $table, $col );
 1129+ $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
 1130+ if ( $col_type == 'CLOB' ) {
 1131+ $conds2['TO_CHAR(' . $col . ')'] = $wgContLang->checkTitleEncoding( $val );
 1132+ } elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) {
 1133+ $conds2[$col] = $wgContLang->checkTitleEncoding( $val );
 1134+ } else {
 1135+ $conds2[$col] = $val;
 1136+ }
11121137 }
 1138+
 1139+ return parent::selectRow( $table, $vars, $conds2, $fname, $options, $join_conds );
 1140+ } else {
 1141+ return parent::selectRow( $table, $vars, $conds, $fname, $options, $join_conds );
11131142 }
1114 -
1115 - return parent::selectRow( $table, $vars, $conds2, $fname, $options, $join_conds );
11161143 }
11171144
11181145 /**
@@ -1160,9 +1187,9 @@
11611188 public function delete( $table, $conds, $fname = 'DatabaseOracle::delete' ) {
11621189 global $wgContLang;
11631190
1164 - if ( $wgContLang != null && $conds != '*' ) {
 1191+ if ( $wgContLang != null && $conds != null && $conds != '*' ) {
11651192 $conds2 = array();
1166 - $conds = ( $conds != null && !is_array( $conds ) ) ? array( $conds ) : $conds;
 1193+ $conds = ( !is_array( $conds ) ) ? array( $conds ) : $conds;
11671194 foreach ( $conds as $col => $val ) {
11681195 $col_info = $this->fieldInfoMulti( $table, $col );
11691196 $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
Index: trunk/phase3/includes/installer/DatabaseInstaller.php
@@ -129,6 +129,7 @@
130130 return $status;
131131 }
132132
 133+ $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
133134 $error = $this->db->sourceFile( $this->db->getSchema() );
134135 if( $error !== true ) {
135136 $this->db->reportQueryError( $error, 0, '', __METHOD__ );
Index: trunk/phase3/includes/installer/OracleInstaller.php
@@ -24,9 +24,10 @@
2525
2626 protected $internalDefaults = array(
2727 '_OracleDefTS' => 'USERS',
28 - '_OracleTempTS' => 'TEMP',
29 - '_OracleUseSysdba' => true
 28+ '_OracleTempTS' => 'TEMP'
3029 );
 30+
 31+ protected $useSysDBA = false;
3132
3233 public $minimumVersion = '9.0.1'; // 9iR1
3334
@@ -92,6 +93,7 @@
9394 }
9495
9596 // Try to connect
 97+ $this->useSysDBA = true;
9698 $status = $this->getConnection();
9799 if ( !$status->isOK() ) {
98100 return $status;
@@ -110,13 +112,13 @@
111113 public function getConnection() {
112114 $status = Status::newGood();
113115 try {
114 - if ( $this->getVar( '_OracleUseSysdba' ) ) {
 116+ if ( $this->useSysDBA ) {
115117 $this->db = new DatabaseOracle(
116118 $this->getVar( 'wgDBserver' ),
117119 $this->getVar( '_InstallUser' ),
118120 $this->getVar( '_InstallPassword' ),
119121 $this->getVar( 'wgDBname' ),
120 - DBO_SYSDBA,
 122+ DBO_SYSDBA | DBO_DDLMODE,
121123 $this->getVar( 'wgDBprefix' )
122124 );
123125 } else {
@@ -147,17 +149,15 @@
148150 public function preInstall() {
149151 # Add our user callback to installSteps, right before the tables are created.
150152 $callback = array(
151 - array(
152 - 'name' => 'user',
153 - 'callback' => array( $this, 'setupUser' ),
154 - )
 153+ 'name' => 'user',
 154+ 'callback' => array( $this, 'setupUser' )
155155 );
156156 $this->parent->addInstallStep( $callback, 'database' );
157157 }
158158
159159
160160 public function setupDatabase() {
161 - $this->parent->setVar( '_OracleUseSysdba', false );
 161+ $this->useSysDBA = false;
162162 $status = Status::newGood();
163163 return $status;
164164 }
@@ -168,6 +168,8 @@
169169 if ( !$this->getVar( '_CreateDBAccount' ) ) {
170170 return Status::newGood();
171171 }
 172+
 173+ $this->useSysDBA = true;
172174 $status = $this->getConnection();
173175 if ( !$status->isOK() ) {
174176 return $status;
@@ -180,6 +182,7 @@
181183 */
182184 $GLOBALS['_OracleDefTS'] = $this->getVar( '_OracleDefTS' );
183185 $GLOBALS['_OracleTempTS'] = $this->getVar( '_OracleTempTS' );
 186+ $this->db->setFlag( DBO_DDLMODE );
184187 $error = $this->db->sourceFile( "$IP/maintenance/oracle/user.sql" );
185188 if ( $error !== true || !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
186189 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
Index: trunk/phase3/includes/AutoLoader.php
@@ -397,7 +397,6 @@
398398 'LoadMonitor_MySQL' => 'includes/db/LoadMonitor.php',
399399 'MySQLField' => 'includes/db/DatabaseMysql.php',
400400 'MySQLMasterPos' => 'includes/db/DatabaseMysql.php',
401 - 'ORABlob' => 'includes/db/DatabaseOracle.php',
402401 'ORAField' => 'includes/db/DatabaseOracle.php',
403402 'ORAResult' => 'includes/db/DatabaseOracle.php',
404403 'PostgresField' => 'includes/db/DatabasePostgres.php',

Follow-up revisions

RevisionCommit summaryAuthorDate
r81182MFT a bunch of installer fixes. r80238, r80128, r80124, r80083, r80080, r800...demon01:59, 29 January 2011

Status & tagging log