X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdb%2FDatabaseOracle.php;h=6af6de52fe0bfeeb4a2c15b71cbb589d5d2ffae2;hb=e8276e074fa8add2d66ce9a8a07eb62a0da112b6;hp=876b9bb9fa2551d92ebcf78dd6c1ca3ccfbf96f9;hpb=a97139808acf244936a870fe8bf7ba3667795f3b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 876b9bb9fa..6af6de52fe 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -23,10 +23,12 @@ use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\Database; +use Wikimedia\Rdbms\DatabaseDomain; use Wikimedia\Rdbms\Blob; use Wikimedia\Rdbms\ResultWrapper; use Wikimedia\Rdbms\DBConnectionError; use Wikimedia\Rdbms\DBUnexpectedError; +use Wikimedia\Rdbms\DBExpectedError; /** * @ingroup Database @@ -81,8 +83,9 @@ class DatabaseOracle extends Database { return false; } - function open( $server, $user, $password, $dbName ) { + protected function open( $server, $user, $password, $dbName, $schema, $tablePrefix ) { global $wgDBOracleDRCP; + if ( !function_exists( 'oci_connect' ) ) { throw new DBConnectionError( $this, @@ -94,20 +97,15 @@ class DatabaseOracle extends Database { $this->close(); $this->user = $user; $this->password = $password; - // changed internal variables functions - // mServer now holds the TNS endpoint - // mDBname is schema name if different from username if ( !$server ) { - // backward compatibillity (server used to be null and TNS was supplied in dbname) + // Backward compatibility (server used to be null and TNS was supplied in dbname) $this->server = $dbName; - $this->dbName = $user; + $realDatabase = $user; } else { + // $server now holds the TNS endpoint $this->server = $server; - if ( !$dbName ) { - $this->dbName = $user; - } else { - $this->dbName = $dbName; - } + // $dbName is schema name if different from username + $realDatabase = $dbName ?: $user; } if ( !strlen( $user ) ) { # e.g. the class is being loaded @@ -148,9 +146,15 @@ class DatabaseOracle extends Database { } Wikimedia\restoreWarnings(); - if ( $this->user != $this->dbName ) { + if ( $this->user != $realDatabase ) { // change current schema in session - $this->selectDB( $this->dbName ); + $this->selectDB( $realDatabase ); + } else { + $this->currentDomain = new DatabaseDomain( + $realDatabase, + null, + $tablePrefix + ); } if ( !$this->conn ) { @@ -386,13 +390,12 @@ class DatabaseOracle extends Database { foreach ( $a as &$row ) { $this->insertOneRow( $table, $row, $fname ); } - $retVal = true; if ( in_array( 'IGNORE', $options ) ) { $this->ignoreDupValOnIndex = false; } - return $retVal; + return true; } private function fieldBindStatement( $table, $col, &$val, $includeCol = false ) { @@ -576,19 +579,17 @@ class DatabaseOracle extends Database { $this->ignoreDupValOnIndex = true; } - $retval = $this->query( $sql, $fname ); + $this->query( $sql, $fname ); if ( in_array( 'IGNORE', $insertOptions ) ) { $this->ignoreDupValOnIndex = false; } - - return $retval; } public function upsert( $table, array $rows, array $uniqueIndexes, array $set, $fname = __METHOD__ ) { - if ( !count( $rows ) ) { + if ( $rows === [] ) { return true; // nothing to do } @@ -654,8 +655,8 @@ class DatabaseOracle extends Database { atc.table_name ) || '_' || atc.column_name || '_SEQ' = '{$this->tablePrefix}' || asq.sequence_name - AND asq.sequence_owner = upper('{$this->dbName}') - AND atc.owner = upper('{$this->dbName}')" ); + AND asq.sequence_owner = upper('{$this->getDBname()}') + AND atc.owner = upper('{$this->getDBname()}')" ); while ( ( $row = $result->fetchRow() ) !== false ) { $this->sequenceData[$row[1]] = [ @@ -735,7 +736,7 @@ class DatabaseOracle extends Database { $listWhere = ' AND table_name LIKE \'' . strtoupper( $prefix ) . '%\''; } - $owner = strtoupper( $this->dbName ); + $owner = strtoupper( $this->getDBname() ); $result = $this->doQuery( "SELECT table_name FROM all_tables " . "WHERE owner='$owner' AND table_name NOT LIKE '%!_IDX\$_' ESCAPE '!' $listWhere" ); @@ -813,7 +814,7 @@ class DatabaseOracle extends Database { $table = $this->tableName( $table ); $table = strtoupper( $this->removeIdentifierQuotes( $table ) ); $index = strtoupper( $index ); - $owner = strtoupper( $this->dbName ); + $owner = strtoupper( $this->getDBname() ); $sql = "SELECT 1 FROM all_indexes WHERE owner='$owner' AND index_name='{$table}_{$index}'"; $res = $this->doQuery( $sql ); if ( $res ) { @@ -835,7 +836,7 @@ class DatabaseOracle extends Database { function tableExists( $table, $fname = __METHOD__ ) { $table = $this->tableName( $table ); $table = $this->addQuotes( strtoupper( $this->removeIdentifierQuotes( $table ) ) ); - $owner = $this->addQuotes( strtoupper( $this->dbName ) ); + $owner = $this->addQuotes( strtoupper( $this->getDBname() ) ); $sql = "SELECT 1 FROM all_tables WHERE owner=$owner AND table_name=$table"; $res = $this->doQuery( $sql ); if ( $res && $res->numRows() > 0 ) { @@ -971,7 +972,7 @@ class DatabaseOracle extends Database { if ( $sl < 0 ) { continue; } - if ( '-' == $line[0] && '-' == $line[1] ) { + if ( $line[0] == '-' && $line[1] == '-' ) { continue; } @@ -985,7 +986,7 @@ class DatabaseOracle extends Database { $dollarquote = true; } } elseif ( !$dollarquote ) { - if ( ';' == $line[$sl] && ( $sl < 2 || ';' != $line[$sl - 1] ) ) { + if ( $line[$sl] == ';' && ( $sl < 2 || $line[$sl - 1] != ';' ) ) { $done = true; $line = substr( $line, 0, $sl ); } @@ -1016,7 +1017,7 @@ class DatabaseOracle extends Database { call_user_func( $resultCallback, $res, $this ); } - if ( false === $res ) { + if ( $res === false ) { $err = $this->lastError(); return "Query \"{$cmd}\" failed with error code \"$err\".\n"; @@ -1031,23 +1032,33 @@ class DatabaseOracle extends Database { return true; } - function selectDB( $db ) { - $this->dbName = $db; - if ( $db == null || $db == $this->user ) { + protected function doSelectDomain( DatabaseDomain $domain ) { + if ( $domain->getSchema() !== null ) { + // We use the *database* aspect of $domain for schema, not the domain schema + throw new DBExpectedError( $this, __CLASS__ . ": domain schemas are not supported." ); + } + + $database = $domain->getDatabase(); + if ( $database === null || $database === $this->user ) { + // Backward compatibility + $this->currentDomain = $domain; + return true; } - $sql = 'ALTER SESSION SET CURRENT_SCHEMA=' . strtoupper( $db ); + + // https://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj32268.html + $encDatabase = $this->addIdentifierQuotes( strtoupper( $database ) ); + $sql = "ALTER SESSION SET CURRENT_SCHEMA=$encDatabase"; $stmt = oci_parse( $this->conn, $sql ); Wikimedia\suppressWarnings(); $success = oci_execute( $stmt ); Wikimedia\restoreWarnings(); - if ( !$success ) { + if ( $success ) { + // Update that domain fields on success (no exception thrown) + $this->currentDomain = $domain; + } else { $e = oci_error( $stmt ); - if ( $e['code'] != '1435' ) { - $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); - } - - return false; + $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); } return true; @@ -1179,7 +1190,9 @@ class DatabaseOracle extends Database { // all deletions on these tables have transactions so final failure rollbacks these updates // @todo: Normalize the schema to match MySQL, no special FKs and such $table = $this->tableName( $table ); - if ( $table == $this->tableName( 'user' ) && $wgActorTableSchemaMigrationStage < MIGRATION_NEW ) { + if ( $table == $this->tableName( 'user' ) && + ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_OLD ) + ) { $this->update( 'archive', [ 'ar_user' => 0 ], [ 'ar_user' => $conds['user_id'] ], $fname ); $this->update( 'ipblocks', [ 'ipb_user' => 0 ], @@ -1332,10 +1345,6 @@ class DatabaseOracle extends Database { return 'BITOR(' . $fieldLeft . ', ' . $fieldRight . ')'; } - function getDBname() { - return $this->dbName; - } - function getServer() { return $this->server; }