* @ingroup Database
*/
+use Wikimedia\AtEase\AtEase;
use Wikimedia\Timestamp\ConvertibleTimestamp;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\DatabaseDomain;
* @param array $params Additional parameters include:
* - keywordTableMap : Map of reserved table names to alternative table names to use
*/
- function __construct( array $params ) {
+ public function __construct( array $params ) {
$this->keywordTableMap = $params['keywordTableMap'] ?? [];
$params['tablePrefix'] = strtoupper( $params['tablePrefix'] );
parent::__construct( $params );
}
function __destruct() {
- if ( $this->opened ) {
- Wikimedia\suppressWarnings();
+ if ( $this->conn ) {
+ AtEase::suppressWarnings();
$this->close();
- Wikimedia\restoreWarnings();
+ AtEase::restoreWarnings();
}
}
"and database)\n" );
}
+ if ( $schema !== null ) {
+ // We use the *database* aspect of $domain for schema, not the domain schema
+ throw new DBExpectedError(
+ $this,
+ __CLASS__ . ": cannot use schema '$schema'; " .
+ "the database component '$dbName' is actually interpreted as the Oracle schema."
+ );
+ }
+
$this->close();
$this->user = $user;
$this->password = $password;
throw new DBConnectionError( $this, $this->lastError() );
}
- $this->opened = true;
-
# removed putenv calls because they interfere with the system globaly
$this->doQuery( 'ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'' );
$this->doQuery( 'ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'' );
}
function execFlags() {
- return $this->trxLevel ? OCI_NO_AUTO_COMMIT : OCI_COMMIT_ON_SUCCESS;
+ return $this->trxLevel() ? OCI_NO_AUTO_COMMIT : OCI_COMMIT_ON_SUCCESS;
}
/**
* @param IResultWrapper|ORAResult $res
*/
function freeResult( $res ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
-
- $res->free();
+ ResultWrapper::unwrap( $res )->free();
}
/**
* @return stdClass|bool
*/
function fetchObject( $res ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
-
- return $res->fetchObject();
+ return ResultWrapper::unwrap( $res )->fetchObject();
}
/**
* @return stdClass|bool
*/
function fetchRow( $res ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
-
- return $res->fetchRow();
+ return ResultWrapper::unwrap( $res )->fetchRow();
}
/**
* @return int
*/
function numRows( $res ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
-
- return $res->numRows();
+ return ResultWrapper::unwrap( $res )->numRows();
}
/**
* @return int
*/
function numFields( $res ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
-
- return $res->numFields();
+ return ResultWrapper::unwrap( $res )->numFields();
}
function fieldName( $stmt, $n ) {
if ( $res instanceof ORAResult ) {
$res->seek( $row );
} else {
- $res->result->seek( $row );
+ ResultWrapper::unwrap( $res )->seek( $row );
}
}
}
}
- if ( !$this->trxLevel ) {
+ if ( !$this->trxLevel() ) {
oci_commit( $this->conn );
}
}
protected function doBegin( $fname = __METHOD__ ) {
- $this->trxLevel = 1;
- $this->doQuery( 'SET CONSTRAINTS ALL DEFERRED' );
+ $this->query( 'SET CONSTRAINTS ALL DEFERRED' );
}
protected function doCommit( $fname = __METHOD__ ) {
- if ( $this->trxLevel ) {
+ if ( $this->trxLevel() ) {
$ret = oci_commit( $this->conn );
if ( !$ret ) {
throw new DBUnexpectedError( $this, $this->lastError() );
}
- $this->trxLevel = 0;
- $this->doQuery( 'SET CONSTRAINTS ALL IMMEDIATE' );
+ $this->query( 'SET CONSTRAINTS ALL IMMEDIATE' );
}
}
protected function doRollback( $fname = __METHOD__ ) {
- if ( $this->trxLevel ) {
+ if ( $this->trxLevel() ) {
oci_rollback( $this->conn );
- $this->trxLevel = 0;
- $this->doQuery( 'SET CONSTRAINTS ALL IMMEDIATE' );
+ $ignoreErrors = true;
+ $this->query( 'SET CONSTRAINTS ALL IMMEDIATE', $fname, $ignoreErrors );
}
}
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." );
+ throw new DBExpectedError(
+ $this,
+ __CLASS__ . ": domain '{$domain->getId()}' has a schema component; " .
+ "the database component is actually interpreted as the Oracle schema."
+ );
}
$database = $domain->getDatabase();
}
}
- if ( !$this->trxLevel ) {
+ if ( !$this->trxLevel() ) {
oci_commit( $this->conn );
}