* @ingroup Database
*/
-use MediaWiki\MediaWikiServices;
+use Wikimedia\Timestamp\ConvertibleTimestamp;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\DatabaseDomain;
use Wikimedia\Rdbms\Blob;
function __construct( array $p ) {
$p['tablePrefix'] = strtoupper( $p['tablePrefix'] );
parent::__construct( $p );
+
+ // @TODO: dependency inject
Hooks::run( 'DatabaseOraclePostInit', [ $this ] );
}
}
protected function open( $server, $user, $password, $dbName, $schema, $tablePrefix ) {
- global $wgDBOracleDRCP;
-
if ( !function_exists( 'oci_connect' ) ) {
throw new DBConnectionError(
$this,
return null;
}
- if ( $wgDBOracleDRCP ) {
- $this->setFlag( DBO_PERSISTENT );
- }
-
$session_mode = ( $this->flags & DBO_SYSDBA ) ? OCI_SYSDBA : OCI_DEFAULT;
Wikimedia\suppressWarnings();
*/
protected function doQuery( $sql ) {
wfDebug( "SQL: [$sql]\n" );
- if ( !StringUtils::isUtf8( $sql ) ) {
- throw new InvalidArgumentException( "SQL encoding is invalid\n$sql" );
+ if ( !mb_check_encoding( (string)$sql, 'UTF-8' ) ) {
+ throw new DBUnexpectedError( $this, "SQL encoding is invalid\n$sql" );
}
// handle some oracle specifics
}
if ( $val === null ) {
- if ( $col_info != false && $col_info->isNullable() == 0 && $col_info->defaultValue() != null ) {
+ if (
+ $col_info != false &&
+ $col_info->isNullable() == 0 &&
+ $col_info->defaultValue() != null
+ ) {
$bind .= 'DEFAULT';
} else {
$bind .= 'NULL';
}
// backward compatibility
- if ( preg_match( '/^timestamp.*/i', $col_type ) == 1 && strtolower( $val ) == 'infinity' ) {
+ if (
+ preg_match( '/^timestamp.*/i', $col_type ) == 1 &&
+ strtolower( $val ) == 'infinity'
+ ) {
$val = $this->getInfinity();
}
- $val = MediaWikiServices::getInstance()->getContentLanguage()->
- checkTitleEncoding( $val );
+ $val = $this->getVerifiedUTF8( $val );
if ( oci_bind_by_name( $stmt, ":$col", $val, -1, SQLT_CHR ) === false ) {
$e = oci_error( $stmt );
$this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
$lob[$col] = oci_new_descriptor( $this->conn, OCI_D_LOB );
if ( $lob[$col] === false ) {
$e = oci_error( $stmt );
- throw new DBUnexpectedError( $this, "Cannot create LOB descriptor: " . $e['message'] );
+ throw new DBUnexpectedError(
+ $this,
+ "Cannot create LOB descriptor: " . $e['message']
+ );
}
if ( is_object( $val ) ) {
if ( $sequenceData !== false &&
!isset( $varMap[$sequenceData['column']] )
) {
- $varMap[$sequenceData['column']] = 'GET_SEQUENCE_VALUE(\'' . $sequenceData['sequence'] . '\')';
+ $varMap[$sequenceData['column']] =
+ 'GET_SEQUENCE_VALUE(\'' . $sequenceData['sequence'] . '\')';
}
// count-alias subselect fields to avoid abigious definition errors
$selectJoinConds
);
- $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ') ' . $selectSql;
+ $sql = "INSERT INTO $destTable (" .
+ implode( ',', array_keys( $varMap ) ) . ') ' . $selectSql;
if ( in_array( 'IGNORE', $insertOptions ) ) {
$this->ignoreDupValOnIndex = true;
return $this->doQuery( "DROP TABLE $tableName CASCADE CONSTRAINTS PURGE" );
}
- function timestamp( $ts = 0 ) {
- return wfTimestamp( TS_ORACLE, $ts );
+ public function timestamp( $ts = 0 ) {
+ $t = new ConvertibleTimestamp( $ts );
+ // Let errors bubble up to avoid putting garbage in the DB
+ return $t->getTimestamp( TS_ORACLE );
}
/**
*/
function fieldInfo( $table, $field ) {
if ( is_array( $table ) ) {
- throw new DBUnexpectedError( $this, 'DatabaseOracle::fieldInfo called with table array!' );
+ throw new DBUnexpectedError(
+ $this,
+ 'DatabaseOracle::fieldInfo called with table array!'
+ );
}
return $this->fieldInfoMulti( $table, $field );
}
function addQuotes( $s ) {
- $contLang = MediaWikiServices::getInstance()->getContentLanguage();
- if ( isset( $contLang->mLoaded ) && $contLang->mLoaded ) {
- $s = $contLang->checkTitleEncoding( $s );
- }
-
- return "'" . $this->strencode( $s ) . "'";
+ return "'" . $this->strencode( $this->getVerifiedUTF8( $s ) ) . "'";
}
public function addIdentifierQuotes( $s ) {
$col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
if ( $col_type == 'CLOB' ) {
$col = 'TO_CHAR(' . $col . ')';
- $val =
- MediaWikiServices::getInstance()->getContentLanguage()->checkTitleEncoding( $val );
+ $val = $this->getVerifiedUTF8( $val );
} elseif ( $col_type == 'VARCHAR2' ) {
- $val =
- MediaWikiServices::getInstance()->getContentLanguage()->checkTitleEncoding( $val );
+ $val = $this->getVerifiedUTF8( $val );
}
}
$val = $val->getData();
}
- if ( preg_match( '/^timestamp.*/i', $col_type ) == 1 && strtolower( $val ) == 'infinity' ) {
+ if (
+ preg_match( '/^timestamp.*/i', $col_type ) == 1 &&
+ strtolower( $val ) == 'infinity'
+ ) {
$val = '31-12-2030 12:00:00.000000';
}
- $val = MediaWikiServices::getInstance()->getContentLanguage()->
- checkTitleEncoding( $val );
+ $val = $this->getVerifiedUTF8( $val );
if ( oci_bind_by_name( $stmt, ":$col", $val ) === false ) {
$e = oci_error( $stmt );
$this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
$lob[$col] = oci_new_descriptor( $this->conn, OCI_D_LOB );
if ( $lob[$col] === false ) {
$e = oci_error( $stmt );
- throw new DBUnexpectedError( $this, "Cannot create LOB descriptor: " . $e['message'] );
+ throw new DBUnexpectedError(
+ $this,
+ "Cannot create LOB descriptor: " . $e['message']
+ );
}
if ( is_object( $val ) ) {
public function getInfinity() {
return '31-12-2030 12:00:00.000000';
}
+
+ /**
+ * @param string $s
+ * @return string
+ */
+ private function getVerifiedUTF8( $s ) {
+ if ( mb_check_encoding( (string)$s, 'UTF-8' ) ) {
+ return $s; // valid
+ }
+
+ throw new DBUnexpectedError( $this, "Non BLOB/CLOB field must be UTF-8." );
+ }
}