2007-03-11 04:00:43 +00:00
< ? php
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
/**
* @ ingroup Database
* @ file
*/
2007-03-11 04:00:43 +00:00
/**
* This is the Oracle database abstraction layer .
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
* @ ingroup Database
2007-03-11 04:00:43 +00:00
*/
class ORABlob {
var $mData ;
2009-12-10 23:22:34 +00:00
function __construct ( $data ) {
2007-03-11 04:00:43 +00:00
$this -> mData = $data ;
}
function getData () {
return $this -> mData ;
}
2007-04-04 05:22:37 +00:00
}
2007-03-11 04:00:43 +00:00
2007-04-04 05:22:37 +00:00
/**
2008-04-14 07:45:50 +00:00
* 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
2007-03-11 04:00:43 +00:00
* Oracle - specific bits , like converting column names back to lowercase .
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
* @ ingroup Database
2007-03-11 04:00:43 +00:00
*/
class ORAResult {
private $rows ;
private $cursor ;
private $stmt ;
private $nrows ;
2009-06-05 11:45:32 +00:00
private $unique ;
2009-12-10 23:22:34 +00:00
private function array_unique_md ( $array_in ) {
2009-10-28 19:15:19 +00:00
$array_out = array ();
$array_hashes = array ();
2009-12-10 23:22:34 +00:00
foreach ( $array_in as $key => $item ) {
$hash = md5 ( serialize ( $item ) );
if ( ! isset ( $array_hashes [ $hash ] ) ) {
$array_hashes [ $hash ] = $hash ;
2009-10-28 19:15:19 +00:00
$array_out [] = $item ;
2009-12-10 23:22:34 +00:00
}
}
2010-01-05 13:35:19 +00:00
2009-12-10 23:22:34 +00:00
return $array_out ;
2009-10-28 19:15:19 +00:00
}
2010-01-05 13:35:19 +00:00
2009-12-10 23:22:34 +00:00
function __construct ( & $db , $stmt , $unique = false ) {
2007-03-11 04:00:43 +00:00
$this -> db =& $db ;
2009-06-05 11:45:32 +00:00
2009-12-10 23:22:34 +00:00
if ( ( $this -> nrows = oci_fetch_all ( $stmt , $this -> rows , 0 , - 1 , OCI_FETCHSTATEMENT_BY_ROW | OCI_NUM ) ) === false ) {
$e = oci_error ( $stmt );
$db -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], '' , __FUNCTION__ );
2007-03-11 04:00:43 +00:00
return ;
}
2009-12-10 23:22:34 +00:00
if ( $unique ) {
$this -> rows = $this -> array_unique_md ( $this -> rows );
$this -> nrows = count ( $this -> rows );
2009-06-05 11:45:32 +00:00
}
2007-03-11 04:00:43 +00:00
$this -> cursor = 0 ;
$this -> stmt = $stmt ;
}
2009-06-05 11:45:32 +00:00
public function free () {
2009-12-10 23:22:34 +00:00
oci_free_statement ( $this -> stmt );
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
public function seek ( $row ) {
$this -> cursor = min ( $row , $this -> nrows );
2007-03-11 04:00:43 +00:00
}
2009-06-05 11:45:32 +00:00
public function numRows () {
2007-03-11 04:00:43 +00:00
return $this -> nrows ;
}
2009-06-05 11:45:32 +00:00
public function numFields () {
2009-12-10 23:22:34 +00:00
return oci_num_fields ( $this -> stmt );
2007-03-11 04:00:43 +00:00
}
2009-06-05 11:45:32 +00:00
public function fetchObject () {
2009-12-11 18:23:24 +00:00
if ( $this -> cursor >= $this -> nrows ) {
2007-03-11 04:00:43 +00:00
return false ;
2009-12-11 18:23:24 +00:00
}
2007-03-11 04:00:43 +00:00
$row = $this -> rows [ $this -> cursor ++ ];
$ret = new stdClass ();
2009-12-10 23:22:34 +00:00
foreach ( $row as $k => $v ) {
$lc = strtolower ( oci_field_name ( $this -> stmt , $k + 1 ) );
2007-03-11 04:00:43 +00:00
$ret -> $lc = $v ;
}
return $ret ;
}
2009-06-05 11:45:32 +00:00
public function fetchRow () {
2009-12-11 18:23:24 +00:00
if ( $this -> cursor >= $this -> nrows ) {
2007-03-11 04:00:43 +00:00
return false ;
2009-12-11 18:23:24 +00:00
}
2007-03-11 04:00:43 +00:00
$row = $this -> rows [ $this -> cursor ++ ];
$ret = array ();
2009-12-10 23:22:34 +00:00
foreach ( $row as $k => $v ) {
$lc = strtolower ( oci_field_name ( $this -> stmt , $k + 1 ) );
2007-03-11 04:00:43 +00:00
$ret [ $lc ] = $v ;
$ret [ $k ] = $v ;
}
return $ret ;
}
2007-04-20 08:55:14 +00:00
}
2007-03-11 04:00:43 +00:00
2009-06-05 11:45:32 +00:00
/**
* Utility class .
* @ ingroup Database
*/
class ORAField {
private $name , $tablename , $default , $max_length , $nullable ,
$is_pk , $is_unique , $is_multiple , $is_key , $type ;
2009-12-10 23:22:34 +00:00
function __construct ( $info ) {
2009-06-05 11:45:32 +00:00
$this -> name = $info [ 'column_name' ];
$this -> tablename = $info [ 'table_name' ];
$this -> default = $info [ 'data_default' ];
$this -> max_length = $info [ 'data_length' ];
$this -> nullable = $info [ 'not_null' ];
2009-12-10 23:22:34 +00:00
$this -> is_pk = isset ( $info [ 'prim' ] ) && $info [ 'prim' ] == 1 ? 1 : 0 ;
$this -> is_unique = isset ( $info [ 'uniq' ] ) && $info [ 'uniq' ] == 1 ? 1 : 0 ;
$this -> is_multiple = isset ( $info [ 'nonuniq' ] ) && $info [ 'nonuniq' ] == 1 ? 1 : 0 ;
$this -> is_key = ( $this -> is_pk || $this -> is_unique || $this -> is_multiple );
2009-06-05 11:45:32 +00:00
$this -> type = $info [ 'data_type' ];
}
2010-01-05 13:35:19 +00:00
2009-06-05 11:45:32 +00:00
function name () {
return $this -> name ;
}
function tableName () {
return $this -> tablename ;
}
function defaultValue () {
return $this -> default ;
}
function maxLength () {
return $this -> max_length ;
}
function nullable () {
return $this -> nullable ;
}
2010-01-05 13:35:19 +00:00
2009-06-05 11:45:32 +00:00
function isKey () {
return $this -> is_key ;
}
function isMultipleKey () {
return $this -> is_multiple ;
}
function type () {
return $this -> type ;
}
}
2007-04-20 08:55:14 +00:00
/**
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
* @ ingroup Database
2007-04-20 08:55:14 +00:00
*/
2009-06-12 17:59:04 +00:00
class DatabaseOracle extends DatabaseBase {
2009-12-11 18:23:24 +00:00
var $mInsertId = null ;
var $mLastResult = null ;
var $numeric_version = null ;
2007-03-11 04:00:43 +00:00
var $lastResult = null ;
var $cursor = 0 ;
var $mAffectedRows ;
2009-06-05 11:45:32 +00:00
var $ignore_DUP_VAL_ON_INDEX = false ;
2009-10-28 19:15:19 +00:00
var $sequenceData = null ;
2009-06-05 11:45:32 +00:00
2009-11-17 09:41:26 +00:00
var $defaultCharset = 'AL32UTF8' ;
2010-01-06 13:52:58 +00:00
var $mFieldInfoCache = array ();
2010-01-05 13:35:19 +00:00
2009-12-11 18:23:24 +00:00
function __construct ( $server = false , $user = false , $password = false , $dbName = false ,
2009-06-05 11:45:32 +00:00
$failFunction = false , $flags = 0 , $tablePrefix = 'get from global' )
2007-03-11 04:00:43 +00:00
{
2009-12-10 23:22:34 +00:00
$tablePrefix = $tablePrefix == 'get from global' ? $tablePrefix : strtoupper ( $tablePrefix );
parent :: __construct ( $server , $user , $password , $dbName , $failFunction , $flags , $tablePrefix );
wfRunHooks ( 'DatabaseOraclePostInit' , array ( & $this ) );
2007-03-11 04:00:43 +00:00
}
2010-01-08 00:31:24 +00:00
function getType () {
return 'oracle' ;
}
2007-03-21 18:19:35 +00:00
function cascadingDeletes () {
return true ;
}
function cleanupTriggers () {
return true ;
}
function strictIPs () {
return true ;
}
2007-03-11 04:00:43 +00:00
function realTimestamps () {
return true ;
}
function implicitGroupby () {
return false ;
}
2007-09-02 18:03:10 +00:00
function implicitOrderby () {
return false ;
}
2007-03-11 04:00:43 +00:00
function searchableIPs () {
return true ;
}
2009-11-04 19:09:11 +00:00
static function newFromParams ( $server , $user , $password , $dbName , $failFunction = false , $flags = 0 )
2007-03-11 04:00:43 +00:00
{
return new DatabaseOracle ( $server , $user , $password , $dbName , $failFunction , $flags );
}
/**
* Usually aborts on failure
* If the failFunction is set to a non - zero integer , returns success
*/
function open ( $server , $user , $password , $dbName ) {
if ( ! function_exists ( 'oci_connect' ) ) {
throw new DBConnectionError ( $this , " Oracle functions missing, have you compiled PHP with the --with-oci8 option? \n (Note: if you recently installed PHP, you may need to restart your webserver and database) \n " );
}
$this -> close ();
$this -> mServer = $server ;
$this -> mUser = $user ;
$this -> mPassword = $password ;
$this -> mDBname = $dbName ;
2009-12-11 18:23:24 +00:00
if ( ! strlen ( $user ) ) { # e.g. the class is being loaded
return ;
2007-03-11 04:00:43 +00:00
}
2009-06-08 18:30:27 +00:00
$session_mode = $this -> mFlags & DBO_SYSDBA ? OCI_SYSDBA : OCI_DEFAULT ;
2009-12-11 18:23:24 +00:00
if ( $this -> mFlags & DBO_DEFAULT ) {
2009-12-10 23:22:34 +00:00
$this -> mConn = oci_new_connect ( $user , $password , $dbName , $this -> defaultCharset , $session_mode );
2009-12-11 18:23:24 +00:00
} else {
2009-12-10 23:22:34 +00:00
$this -> mConn = oci_connect ( $user , $password , $dbName , $this -> defaultCharset , $session_mode );
2009-12-11 18:23:24 +00:00
}
2007-03-11 04:00:43 +00:00
2009-12-10 23:22:34 +00:00
if ( $this -> mConn == false ) {
wfDebug ( " DB connection error \n " );
wfDebug ( " Server: $server , Database: $dbName , User: $user , Password: " . substr ( $password , 0 , 3 ) . " ... \n " );
wfDebug ( $this -> lastError () . " \n " );
2007-03-11 04:00:43 +00:00
return false ;
}
$this -> mOpened = true ;
2010-01-05 13:35:19 +00:00
2009-12-10 23:22:34 +00:00
# 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\'' );
2007-03-11 04:00:43 +00:00
return $this -> mConn ;
}
/**
* Closes a database connection , if it is open
* Returns success , true if already closed
*/
function close () {
$this -> mOpened = false ;
if ( $this -> mConn ) {
return oci_close ( $this -> mConn );
} else {
return true ;
}
}
function execFlags () {
return $this -> mTrxLevel ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS ;
}
2009-12-10 23:22:34 +00:00
function doQuery ( $sql ) {
wfDebug ( " SQL: [ $sql ] \n " );
if ( ! mb_check_encoding ( $sql ) ) {
throw new MWException ( " SQL encoding is invalid \n $sql " );
2009-11-05 20:04:47 +00:00
}
2007-03-30 19:35:24 +00:00
2009-12-10 23:22:34 +00:00
// handle some oracle specifics
// remove AS column/table/subquery namings
2009-12-11 18:23:24 +00:00
if ( ! defined ( 'MEDIAWIKI_INSTALL' ) ) {
2009-12-10 23:22:34 +00:00
$sql = preg_replace ( '/ as /i' , ' ' , $sql );
2009-12-11 18:23:24 +00:00
}
2009-06-05 11:45:32 +00:00
// Oracle has issues with UNION clause if the statement includes LOB fields
// So we do a UNION ALL and then filter the results array with array_unique
2009-12-10 23:22:34 +00:00
$union_unique = ( preg_match ( '/\/\* UNION_UNIQUE \*\/ /' , $sql ) != 0 );
// EXPLAIN syntax in Oracle is EXPLAIN PLAN FOR and it return nothing
// you have to select data from plan table after explain
$explain_id = date ( 'dmYHis' );
$sql = preg_replace ( '/^EXPLAIN /' , 'EXPLAIN PLAN SET STATEMENT_ID = \'' . $explain_id . '\' FOR' , $sql , 1 , $explain_count );
2010-01-05 13:35:19 +00:00
2010-01-17 20:42:54 +00:00
wfSuppressWarnings ();
2010-01-05 13:35:19 +00:00
2009-12-10 23:22:34 +00:00
if ( ( $this -> mLastResult = $stmt = oci_parse ( $this -> mConn , $sql ) ) === false ) {
$e = oci_error ( $this -> mConn );
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], $sql , __FUNCTION__ );
2007-03-30 19:35:24 +00:00
}
2008-04-14 07:45:50 +00:00
2009-12-10 23:22:34 +00:00
if ( oci_execute ( $stmt , $this -> execFlags () ) == false ) {
$e = oci_error ( $stmt );
2009-12-11 18:23:24 +00:00
if ( ! $this -> ignore_DUP_VAL_ON_INDEX || $e [ 'code' ] != '1' ) {
2009-12-10 23:22:34 +00:00
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], $sql , __FUNCTION__ );
2009-12-11 18:23:24 +00:00
}
2007-03-11 04:00:43 +00:00
}
2010-01-17 20:42:54 +00:00
wfRestoreWarnings ();
2009-06-05 11:45:32 +00:00
2009-12-10 23:22:34 +00:00
if ( $explain_count > 0 ) {
return $this -> doQuery ( 'SELECT id, cardinality "ROWS" FROM plan_table WHERE statement_id = \'' . $explain_id . '\'' );
2009-12-11 18:23:24 +00:00
} elseif ( oci_statement_type ( $stmt ) == 'SELECT' ) {
2009-12-10 23:22:34 +00:00
return new ORAResult ( $this , $stmt , $union_unique );
2009-06-05 11:45:32 +00:00
} else {
2009-12-10 23:22:34 +00:00
$this -> mAffectedRows = oci_num_rows ( $stmt );
2007-03-11 04:00:43 +00:00
return true ;
}
}
2009-12-10 23:22:34 +00:00
function queryIgnore ( $sql , $fname = '' ) {
return $this -> query ( $sql , $fname , true );
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
function freeResult ( $res ) {
2009-06-05 11:45:32 +00:00
if ( $res instanceof ORAResult ) {
$res -> free ();
} else {
$res -> result -> free ();
}
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
function fetchObject ( $res ) {
2009-06-05 11:45:32 +00:00
if ( $res instanceof ORAResult ) {
return $res -> numRows ();
} else {
return $res -> result -> fetchObject ();
}
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
function fetchRow ( $res ) {
2009-06-05 11:45:32 +00:00
if ( $res instanceof ORAResult ) {
return $res -> fetchRow ();
} else {
return $res -> result -> fetchRow ();
}
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
function numRows ( $res ) {
2009-06-05 11:45:32 +00:00
if ( $res instanceof ORAResult ) {
return $res -> numRows ();
} else {
return $res -> result -> numRows ();
}
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
function numFields ( $res ) {
2009-06-05 11:45:32 +00:00
if ( $res instanceof ORAResult ) {
return $res -> numFields ();
} else {
return $res -> result -> numFields ();
}
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
function fieldName ( $stmt , $n ) {
return oci_field_name ( $stmt , $n );
2007-03-11 04:00:43 +00:00
}
/**
* This must be called after nextSequenceVal
*/
function insertId () {
return $this -> mInsertId ;
}
2009-12-10 23:22:34 +00:00
function dataSeek ( $res , $row ) {
2009-06-05 11:45:32 +00:00
if ( $res instanceof ORAResult ) {
2009-12-10 23:22:34 +00:00
$res -> seek ( $row );
2009-06-05 11:45:32 +00:00
} else {
2009-12-10 23:22:34 +00:00
$res -> result -> seek ( $row );
2009-06-05 11:45:32 +00:00
}
2007-03-11 04:00:43 +00:00
}
function lastError () {
2009-12-11 18:23:24 +00:00
if ( $this -> mConn === false ) {
2007-03-11 04:00:43 +00:00
$e = oci_error ();
2009-12-11 18:23:24 +00:00
} else {
2009-12-10 23:22:34 +00:00
$e = oci_error ( $this -> mConn );
2009-12-11 18:23:24 +00:00
}
2007-03-11 04:00:43 +00:00
return $e [ 'message' ];
}
function lastErrno () {
2009-12-11 18:23:24 +00:00
if ( $this -> mConn === false ) {
2007-03-11 04:00:43 +00:00
$e = oci_error ();
2009-12-11 18:23:24 +00:00
} else {
2009-12-10 23:22:34 +00:00
$e = oci_error ( $this -> mConn );
2009-12-11 18:23:24 +00:00
}
2007-03-11 04:00:43 +00:00
return $e [ 'code' ];
}
function affectedRows () {
return $this -> mAffectedRows ;
}
/**
* Returns information about an index
* If errors are explicitly ignored , returns NULL on failure
*/
2009-06-05 11:45:32 +00:00
function indexInfo ( $table , $index , $fname = 'DatabaseOracle::indexExists' ) {
2007-03-11 04:00:43 +00:00
return false ;
}
2009-12-11 18:23:24 +00:00
function indexUnique ( $table , $index , $fname = 'DatabaseOracle::indexUnique' ) {
2007-03-11 04:00:43 +00:00
return false ;
}
2009-06-05 11:45:32 +00:00
function insert ( $table , $a , $fname = 'DatabaseOracle::insert' , $options = array () ) {
2009-12-11 18:23:24 +00:00
if ( ! count ( $a ) ) {
2009-06-05 11:45:32 +00:00
return true ;
2009-12-11 18:23:24 +00:00
}
2009-06-05 11:45:32 +00:00
2009-12-11 18:23:24 +00:00
if ( ! is_array ( $options ) ) {
2009-12-10 23:22:34 +00:00
$options = array ( $options );
2009-12-11 18:23:24 +00:00
}
2007-03-11 04:00:43 +00:00
2009-12-11 18:23:24 +00:00
if ( in_array ( 'IGNORE' , $options ) ) {
2009-06-05 11:45:32 +00:00
$this -> ignore_DUP_VAL_ON_INDEX = true ;
2009-12-11 18:23:24 +00:00
}
2007-03-11 04:00:43 +00:00
2009-12-10 23:22:34 +00:00
if ( ! is_array ( reset ( $a ) ) ) {
$a = array ( $a );
2007-03-11 04:00:43 +00:00
}
2009-11-09 14:34:03 +00:00
2009-12-10 23:22:34 +00:00
foreach ( $a as & $row ) {
$this -> insertOneRow ( $table , $row , $fname );
2007-03-11 04:00:43 +00:00
}
$retVal = true ;
2009-12-11 18:23:24 +00:00
if ( in_array ( 'IGNORE' , $options ) ) {
2009-06-05 11:45:32 +00:00
$this -> ignore_DUP_VAL_ON_INDEX = false ;
2009-12-11 18:23:24 +00:00
}
2007-03-11 04:00:43 +00:00
return $retVal ;
}
2009-12-10 23:22:34 +00:00
function insertOneRow ( $table , $row , $fname ) {
2009-06-05 11:45:32 +00:00
global $wgLang ;
2007-03-11 04:00:43 +00:00
// "INSERT INTO tables (a, b, c)"
2009-12-10 23:22:34 +00:00
$sql = " INSERT INTO " . $this -> tableName ( $table ) . " ( " . join ( ',' , array_keys ( $row ) ) . ')' ;
2007-03-11 04:00:43 +00:00
$sql .= " VALUES ( " ;
// for each value, append ":key"
$first = true ;
2009-12-10 23:22:34 +00:00
foreach ( $row as $col => $val ) {
2009-12-11 18:23:24 +00:00
if ( $first ) {
$sql .= $val !== null ? ':' . $col : 'NULL' ;
} else {
$sql .= $val !== null ? ', :' . $col : ', NULL' ;
}
2010-01-05 13:35:19 +00:00
2007-03-11 04:00:43 +00:00
$first = false ;
}
2009-06-05 11:45:32 +00:00
$sql .= ')' ;
2007-03-11 04:00:43 +00:00
2009-12-10 23:22:34 +00:00
$stmt = oci_parse ( $this -> mConn , $sql );
foreach ( $row as $col => & $val ) {
$col_type = $this -> fieldInfo ( $this -> tableName ( $table ), $col ) -> type ();
2009-12-11 18:23:24 +00:00
if ( $val === null ) {
2009-11-04 19:09:11 +00:00
// do nothing ... null was inserted in statement creation
2009-12-10 23:22:34 +00:00
} elseif ( $col_type != 'BLOB' && $col_type != 'CLOB' ) {
2009-12-11 18:23:24 +00:00
if ( is_object ( $val ) ) {
2009-06-05 11:45:32 +00:00
$val = $val -> getData ();
2009-12-11 18:23:24 +00:00
}
if ( preg_match ( '/^timestamp.*/i' , $col_type ) == 1 && strtolower ( $val ) == 'infinity' ) {
2009-06-05 11:45:32 +00:00
$val = '31-12-2030 12:00:00.000000' ;
2009-12-11 18:23:24 +00:00
}
2010-01-05 13:35:19 +00:00
2009-12-10 23:22:34 +00:00
$val = ( $wgLang != null ) ? $wgLang -> checkTitleEncoding ( $val ) : $val ;
2009-12-11 18:23:24 +00:00
if ( oci_bind_by_name ( $stmt , " : $col " , $val ) === false ) {
2009-12-10 23:22:34 +00:00
$this -> reportQueryError ( $this -> lastErrno (), $this -> lastError (), $sql , __METHOD__ );
2009-12-11 18:23:24 +00:00
}
2009-06-05 11:45:32 +00:00
} else {
2009-12-10 23:22:34 +00:00
if ( ( $lob [ $col ] = oci_new_descriptor ( $this -> mConn , OCI_D_LOB ) ) === false ) {
$e = oci_error ( $stmt );
throw new DBUnexpectedError ( $this , " Cannot create LOB descriptor: " . $e [ 'message' ] );
2009-06-05 11:45:32 +00:00
}
2009-12-11 18:23:24 +00:00
2009-12-10 23:22:34 +00:00
if ( $col_type == 'BLOB' ) { // is_object($val)) {
$lob [ $col ] -> writeTemporary ( $val ); // ->getData());
oci_bind_by_name ( $stmt , " : $col " , $lob [ $col ], - 1 , SQLT_BLOB );
2009-06-05 11:45:32 +00:00
} else {
2009-12-10 23:22:34 +00:00
$lob [ $col ] -> writeTemporary ( $val );
oci_bind_by_name ( $stmt , " : $col " , $lob [ $col ], - 1 , OCI_B_CLOB );
2009-06-05 11:45:32 +00:00
}
}
2007-03-28 18:26:28 +00:00
}
2009-11-04 19:09:11 +00:00
2010-01-17 20:42:54 +00:00
wfSuppressWarnings ();
2009-12-10 23:22:34 +00:00
if ( oci_execute ( $stmt , OCI_DEFAULT ) === false ) {
$e = oci_error ( $stmt );
2010-01-05 13:35:19 +00:00
2009-12-11 18:23:24 +00:00
if ( ! $this -> ignore_DUP_VAL_ON_INDEX || $e [ 'code' ] != '1' ) {
2009-12-10 23:22:34 +00:00
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], $sql , __METHOD__ );
2009-12-11 18:23:24 +00:00
} else {
2009-12-10 23:22:34 +00:00
$this -> mAffectedRows = oci_num_rows ( $stmt );
2009-12-11 18:23:24 +00:00
}
} else {
2009-12-10 23:22:34 +00:00
$this -> mAffectedRows = oci_num_rows ( $stmt );
2009-12-11 18:23:24 +00:00
}
2010-01-17 20:42:54 +00:00
wfRestoreWarnings ();
2010-01-05 13:35:19 +00:00
2009-12-10 23:22:34 +00:00
if ( isset ( $lob ) ) {
foreach ( $lob as $lob_i => $lob_v ) {
2009-06-05 11:45:32 +00:00
$lob_v -> free ();
}
2007-03-11 21:44:38 +00:00
}
2010-01-05 13:35:19 +00:00
2009-12-11 18:23:24 +00:00
if ( ! $this -> mTrxLevel ) {
2009-12-10 23:22:34 +00:00
oci_commit ( $this -> mConn );
2009-12-11 18:23:24 +00:00
}
2009-12-10 23:22:34 +00:00
oci_free_statement ( $stmt );
2007-03-11 04:00:43 +00:00
}
2008-04-14 07:45:50 +00:00
2009-06-05 11:45:32 +00:00
function insertSelect ( $destTable , $srcTable , $varMap , $conds , $fname = 'DatabaseOracle::insertSelect' ,
$insertOptions = array (), $selectOptions = array () )
{
$destTable = $this -> tableName ( $destTable );
2009-12-10 23:22:34 +00:00
if ( ! is_array ( $selectOptions ) ) {
2009-06-05 11:45:32 +00:00
$selectOptions = array ( $selectOptions );
}
list ( $startOpts , $useIndex , $tailOpts ) = $this -> makeSelectOptions ( $selectOptions );
2009-12-10 23:22:34 +00:00
if ( is_array ( $srcTable ) ) {
2009-06-05 11:45:32 +00:00
$srcTable = implode ( ',' , array_map ( array ( & $this , 'tableName' ), $srcTable ) );
} else {
$srcTable = $this -> tableName ( $srcTable );
}
2010-01-05 13:35:19 +00:00
2009-12-10 23:22:34 +00:00
if ( ( $sequenceData = $this -> getSequenceData ( $destTable ) ) !== false &&
! isset ( $varMap [ $sequenceData [ 'column' ]] ) )
$varMap [ $sequenceData [ 'column' ]] = 'GET_SEQUENCE_VALUE(\'' . $sequenceData [ 'sequence' ] . '\')' ;
2010-01-05 13:35:19 +00:00
2009-10-28 16:17:16 +00:00
// count-alias subselect fields to avoid abigious definition errors
2009-12-10 23:22:34 +00:00
$i = 0 ;
2009-12-11 18:23:24 +00:00
foreach ( $varMap as $key => & $val ) {
2009-12-10 23:22:34 +00:00
$val = $val . ' field' . ( $i ++ );
2009-12-11 18:23:24 +00:00
}
2010-01-05 13:35:19 +00:00
2009-06-05 11:45:32 +00:00
$sql = " INSERT INTO $destTable ( " . implode ( ',' , array_keys ( $varMap ) ) . ')' .
" SELECT $startOpts " . implode ( ',' , $varMap ) .
" FROM $srcTable $useIndex " ;
if ( $conds != '*' ) {
$sql .= ' WHERE ' . $this -> makeList ( $conds , LIST_AND );
}
$sql .= " $tailOpts " ;
2010-01-05 13:35:19 +00:00
2009-12-11 18:23:24 +00:00
if ( in_array ( 'IGNORE' , $insertOptions ) ) {
2009-06-05 11:45:32 +00:00
$this -> ignore_DUP_VAL_ON_INDEX = true ;
2009-12-11 18:23:24 +00:00
}
2010-01-05 13:35:19 +00:00
2009-06-05 11:45:32 +00:00
$retval = $this -> query ( $sql , $fname );
2010-01-05 13:35:19 +00:00
2009-12-11 18:23:24 +00:00
if ( in_array ( 'IGNORE' , $insertOptions ) ) {
2009-06-05 11:45:32 +00:00
$this -> ignore_DUP_VAL_ON_INDEX = false ;
2009-12-11 18:23:24 +00:00
}
2009-06-05 11:45:32 +00:00
return $retval ;
}
2007-03-11 04:00:43 +00:00
function tableName ( $name ) {
2010-01-17 20:42:54 +00:00
if ( is_array ( $name )) {
foreach ( $name as & $single_name ) {
$single_name = $this -> tableName ( $single_name );
}
return $name ;
}
2009-06-05 11:45:32 +00:00
global $wgSharedDB , $wgSharedPrefix , $wgSharedTables ;
/*
Replace reserved words with better ones
2010-01-05 13:35:19 +00:00
Using uppercase because that ' s the only way Oracle can handle
2009-06-05 11:45:32 +00:00
quoted tablenames
*/
2007-03-11 04:00:43 +00:00
switch ( $name ) {
case 'user' :
2009-12-11 18:23:24 +00:00
$name = 'MWUSER' ;
break ;
2007-03-11 04:00:43 +00:00
case 'text' :
2009-12-11 18:23:24 +00:00
$name = 'PAGECONTENT' ;
break ;
2007-03-11 04:00:43 +00:00
}
2009-06-05 11:45:32 +00:00
/*
The rest of procedure is equal to generic Databse class
except for the quoting style
*/
2009-12-11 18:23:24 +00:00
if ( $name [ 0 ] == '"' && substr ( $name , - 1 , 1 ) == '"' ) {
return $name ;
}
if ( preg_match ( '/(^|\s)(DISTINCT|JOIN|ON|AS)(\s|$)/i' , $name ) !== 0 ) {
return $name ;
}
2009-06-05 11:45:32 +00:00
$dbDetails = array_reverse ( explode ( '.' , $name , 2 ) );
2009-12-11 18:23:24 +00:00
if ( isset ( $dbDetails [ 1 ] ) ) {
@ list ( $table , $database ) = $dbDetails ;
} else {
@ list ( $table ) = $dbDetails ;
}
2009-06-05 11:45:32 +00:00
$prefix = $this -> mTablePrefix ;
2010-01-05 13:35:19 +00:00
2009-12-11 18:23:24 +00:00
if ( isset ( $database ) ) {
$table = ( $table [ 0 ] == '`' ? $table : " ` { $table } ` " );
}
if ( ! isset ( $database ) && isset ( $wgSharedDB ) && $table [ 0 ] != '"'
&& isset ( $wgSharedTables )
&& is_array ( $wgSharedTables )
&& in_array ( $table , $wgSharedTables )
) {
2009-06-05 11:45:32 +00:00
$database = $wgSharedDB ;
$prefix = isset ( $wgSharedPrefix ) ? $wgSharedPrefix : $prefix ;
}
2009-12-11 18:23:24 +00:00
if ( isset ( $database ) ) {
$database = ( $database [ 0 ] == '"' ? $database : " \" { $database } \" " );
}
2009-06-05 11:45:32 +00:00
$table = ( $table [ 0 ] == '"' ? $table : " \" { $prefix } { $table } \" " );
2009-12-11 18:23:24 +00:00
2009-12-10 23:22:34 +00:00
$tableName = ( isset ( $database ) ? " { $database } . { $table } " : " { $table } " );
2009-12-11 18:23:24 +00:00
2009-12-10 23:22:34 +00:00
return strtoupper ( $tableName );
2007-03-11 04:00:43 +00:00
}
/**
* Return the next in a sequence , save the value for retrieval via insertId ()
*/
2009-12-10 23:22:34 +00:00
function nextSequenceValue ( $seqName ) {
$res = $this -> query ( " SELECT $seqName .nextval FROM dual " );
$row = $this -> fetchRow ( $res );
2007-03-11 04:00:43 +00:00
$this -> mInsertId = $row [ 0 ];
2009-12-10 23:22:34 +00:00
$this -> freeResult ( $res );
2007-03-11 04:00:43 +00:00
return $this -> mInsertId ;
}
2009-10-28 19:15:19 +00:00
/**
* Return sequence_name if table has a sequence
*/
2009-12-10 23:22:34 +00:00
function getSequenceData ( $table ) {
2009-12-11 18:23:24 +00:00
if ( $this -> sequenceData == null ) {
2009-12-10 23:22:34 +00:00
$result = $this -> query ( " SELECT lower(us.sequence_name), lower(utc.table_name), lower(utc.column_name) from user_sequences us, user_tab_columns utc where us.sequence_name = utc.table_name||'_'||utc.column_name||'_SEQ' " );
2010-01-05 13:35:19 +00:00
2009-12-11 18:23:24 +00:00
while ( ( $row = $result -> fetchRow () ) !== false ) {
$this -> sequenceData [ $this -> tableName ( $row [ 1 ] )] = array (
'sequence' => $row [ 0 ],
'column' => $row [ 2 ]
);
}
2009-10-28 19:15:19 +00:00
}
2009-12-11 18:23:24 +00:00
2009-12-10 23:22:34 +00:00
return ( isset ( $this -> sequenceData [ $table ] ) ) ? $this -> sequenceData [ $table ] : false ;
2009-10-28 19:15:19 +00:00
}
2010-01-05 13:35:19 +00:00
2007-03-11 04:00:43 +00:00
# REPLACE query wrapper
# Oracle simulates this with a DELETE followed by INSERT
# $row is the row to insert, an associative array
# $uniqueIndexes is an array of indexes. Each element may be either a
# field name or an array of field names
#
# It may be more efficient to leave off unique indexes which are unlikely to collide.
# However if you do this, you run the risk of encountering errors which wouldn't have
# occurred in MySQL
2009-06-05 11:45:32 +00:00
function replace ( $table , $uniqueIndexes , $rows , $fname = 'DatabaseOracle::replace' ) {
2009-12-10 23:22:34 +00:00
$table = $this -> tableName ( $table );
2007-03-11 04:00:43 +00:00
2009-12-10 23:22:34 +00:00
if ( count ( $rows ) == 0 ) {
2007-03-11 04:00:43 +00:00
return ;
}
# Single row case
2009-12-10 23:22:34 +00:00
if ( ! is_array ( reset ( $rows ) ) ) {
$rows = array ( $rows );
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
$sequenceData = $this -> getSequenceData ( $table );
2009-11-04 19:27:22 +00:00
2009-12-10 23:22:34 +00:00
foreach ( $rows as $row ) {
2007-03-11 04:00:43 +00:00
# Delete rows which collide
if ( $uniqueIndexes ) {
2009-11-05 20:04:47 +00:00
$condsDelete = array ();
foreach ( $uniqueIndexes as $index )
$condsDelete [ $index ] = $row [ $index ];
2010-01-08 07:23:43 +00:00
if ( count ( $condsDelete ) > 0 ) {
$this -> delete ( $table , $condsDelete , $fname );
2007-03-11 04:00:43 +00:00
}
}
2009-12-11 18:23:24 +00:00
if ( $sequenceData !== false && ! isset ( $row [ $sequenceData [ 'column' ]] ) ) {
2009-12-10 23:22:34 +00:00
$row [ $sequenceData [ 'column' ]] = $this -> nextSequenceValue ( $sequenceData [ 'sequence' ] );
2009-12-11 18:23:24 +00:00
}
2009-11-04 19:27:22 +00:00
2007-03-11 04:00:43 +00:00
# Now insert the row
2009-06-05 11:45:32 +00:00
$this -> insert ( $table , $row , $fname );
2007-03-11 04:00:43 +00:00
}
}
# DELETE where the condition is a join
2009-06-05 11:45:32 +00:00
function deleteJoin ( $delTable , $joinTable , $delVar , $joinVar , $conds , $fname = " DatabaseOracle::deleteJoin " ) {
2007-03-11 04:00:43 +00:00
if ( ! $conds ) {
2009-12-10 23:22:34 +00:00
throw new DBUnexpectedError ( $this , 'DatabaseOracle::deleteJoin() called with empty $conds' );
2007-03-11 04:00:43 +00:00
}
$delTable = $this -> tableName ( $delTable );
$joinTable = $this -> tableName ( $joinTable );
$sql = " DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable " ;
if ( $conds != '*' ) {
$sql .= 'WHERE ' . $this -> makeList ( $conds , LIST_AND );
}
$sql .= ')' ;
$this -> query ( $sql , $fname );
}
# Returns the size of a text field, or -1 for "unlimited"
function textFieldSize ( $table , $field ) {
$table = $this -> tableName ( $table );
$sql = " SELECT t.typname as ftype,a.atttypmod as size
FROM pg_class c , pg_attribute a , pg_type t
WHERE relname = '$table' AND a . attrelid = c . oid AND
a . atttypid = t . oid and a . attname = '$field' " ;
2009-12-10 23:22:34 +00:00
$res = $this -> query ( $sql );
$row = $this -> fetchObject ( $res );
if ( $row -> ftype == " varchar " ) {
$size = $row -> size - 4 ;
2007-03-11 04:00:43 +00:00
} else {
2009-12-10 23:22:34 +00:00
$size = $row -> size ;
2007-03-11 04:00:43 +00:00
}
$this -> freeResult ( $res );
return $size ;
}
2009-12-10 23:22:34 +00:00
function limitResult ( $sql , $limit , $offset = false ) {
2009-12-11 18:23:24 +00:00
if ( $offset === false ) {
2007-03-11 04:00:43 +00:00
$offset = 0 ;
2009-12-11 18:23:24 +00:00
}
2009-06-05 11:45:32 +00:00
return " SELECT * FROM ( $sql ) WHERE rownum >= (1 + $offset ) AND rownum < (1 + $limit + $offset ) " ;
}
2009-12-10 23:22:34 +00:00
function unionQueries ( $sqls , $all ) {
2009-06-05 11:45:32 +00:00
$glue = ' UNION ALL ' ;
2009-12-10 23:22:34 +00:00
return 'SELECT * ' . ( $all ? '' : '/* UNION_UNIQUE */ ' ) . 'FROM (' . implode ( $glue , $sqls ) . ')' ;
2007-03-11 04:00:43 +00:00
}
function wasDeadlock () {
return $this -> lastErrno () == 'OCI-00060' ;
}
2009-11-06 17:12:18 +00:00
function duplicateTableStructure ( $oldName , $newName , $temporary = false , $fname = 'DatabaseOracle::duplicateTableStructure' ) {
$temporary = $temporary ? 'TRUE' : 'FALSE' ;
2009-12-10 23:22:34 +00:00
return $this -> query ( 'BEGIN DUPLICATE_TABLE(\'' . $oldName . '\', \'' . $newName . '\', ' . $temporary . '); END;' , $fname );
2009-11-06 17:12:18 +00:00
}
2009-12-10 23:22:34 +00:00
function timestamp ( $ts = 0 ) {
return wfTimestamp ( TS_ORACLE , $ts );
2007-03-11 04:00:43 +00:00
}
/**
* Return aggregated value function call
*/
2009-12-10 23:22:34 +00:00
function aggregateValue ( $valuedata , $valuename = 'value' ) {
2007-03-11 04:00:43 +00:00
return $valuedata ;
}
2009-12-10 23:22:34 +00:00
function reportQueryError ( $error , $errno , $sql , $fname , $tempIgnore = false ) {
2008-04-14 07:45:50 +00:00
# Ignore errors during error handling to avoid infinite
2007-03-30 19:35:24 +00:00
# recursion
2009-12-10 23:22:34 +00:00
$ignore = $this -> ignoreErrors ( true );
2007-03-11 04:00:43 +00:00
++ $this -> mErrorCount ;
2009-12-10 23:22:34 +00:00
if ( $ignore || $tempIgnore ) {
wfDebug ( " SQL ERROR (ignored): $error\n " );
2007-03-11 04:00:43 +00:00
$this -> ignoreErrors ( $ignore );
2009-12-11 18:23:24 +00:00
} else {
throw new DBQueryError ( $this , $error , $errno , $sql , $fname );
2007-03-11 04:00:43 +00:00
}
}
/**
* @ return string wikitext of a link to the server software ' s web site
*/
function getSoftwareLink () {
2009-12-11 18:23:24 +00:00
return '[http://www.oracle.com/ Oracle]' ;
2007-03-11 04:00:43 +00:00
}
/**
* @ return string Version information from the database
*/
function getServerVersion () {
2009-12-10 23:22:34 +00:00
return oci_server_version ( $this -> mConn );
2007-03-11 04:00:43 +00:00
}
/**
* Query whether a given table exists ( in the given schema , or the default mw one if not given )
*/
2009-12-10 23:22:34 +00:00
function tableExists ( $table ) {
2009-06-05 11:45:32 +00:00
$SQL = " SELECT 1 FROM user_tables WHERE table_name=' $table ' " ;
2009-12-10 23:22:34 +00:00
$res = $this -> doQuery ( $SQL );
if ( $res ) {
2009-06-05 11:45:32 +00:00
$count = $res -> numRows ();
$res -> free ();
} else {
$count = 0 ;
}
2007-03-11 04:00:43 +00:00
return $count ;
}
/**
* Query whether a given column exists in the mediawiki schema
2009-06-05 11:45:32 +00:00
* based on prebuilt table to simulate MySQL field info and keep query speed minimal
2007-03-11 04:00:43 +00:00
*/
2009-11-04 19:09:11 +00:00
function fieldExists ( $table , $field , $fname = 'DatabaseOracle::fieldExists' ) {
2010-01-17 20:42:54 +00:00
$tableWhere = '' ;
if ( is_array ( $table )) {
$tableWhere = 'IN (' ;
foreach ( $table as & $singleTable ) {
$singleTable = trim ( $singleTable , '"' );
if ( isset ( $this -> mFieldInfoCache [ " $singleTable . $field " ])) {
return $this -> mFieldInfoCache [ " $singleTable . $field " ];
}
$tableWhere .= '\'' . $singleTable . '\',' ;
}
$tableWhere = rtrim ( $tableWhere , ',' ) . ')' ;
} else {
$table = trim ( $table , '"' );
if ( isset ( $this -> mFieldInfoCache [ " $table . $field " ])) {
return $this -> mFieldInfoCache [ " $table . $field " ];
}
$tableWhere = '= upper(\'' . $table . '\')' ;
2009-12-11 18:23:24 +00:00
}
2010-01-17 20:42:54 +00:00
$fieldInfoStmt = oci_parse ( $this -> mConn , 'SELECT * FROM wiki_field_info_full WHERE table_name ' . $tableWhere . ' and column_name = UPPER(\'' . $field . '\')' );
2009-06-05 11:45:32 +00:00
2010-01-17 20:42:54 +00:00
if ( oci_execute ( $fieldInfoStmt , OCI_DEFAULT ) === false ) {
$e = oci_error ( $fieldInfoStmt );
2009-12-10 23:22:34 +00:00
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], 'fieldInfo QUERY' , __METHOD__ );
2009-06-05 11:45:32 +00:00
return false ;
}
2010-01-17 20:42:54 +00:00
$res = new ORAResult ( $this , $fieldInfoStmt );
2010-01-05 13:35:19 +00:00
if ( $res -> numRows () != 0 ) {
2010-01-17 20:42:54 +00:00
$fieldInfoTemp = new ORAField ( $res -> fetchRow () );
$table = $fieldInfoTemp -> tableName ();
$this -> mFieldInfoCache [ " $table . $field " ] = $fieldInfoTemp ;
2010-01-05 13:35:19 +00:00
return true ;
} else {
return false ;
}
2007-03-11 04:00:43 +00:00
}
function fieldInfo ( $table , $field ) {
2010-01-17 20:42:54 +00:00
$tableWhere = '' ;
if ( is_array ( $table )) {
$tableWhere = 'IN (' ;
foreach ( $table as & $singleTable ) {
$singleTable = trim ( $singleTable , '"' );
if ( isset ( $this -> mFieldInfoCache [ " $singleTable . $field " ])) {
return $this -> mFieldInfoCache [ " $singleTable . $field " ];
}
$tableWhere .= '\'' . $singleTable . '\',' ;
}
$tableWhere = rtrim ( $tableWhere , ',' ) . ')' ;
} else {
$table = trim ( $table , '"' );
if ( isset ( $this -> mFieldInfoCache [ " $table . $field " ])) {
return $this -> mFieldInfoCache [ " $table . $field " ];
}
$tableWhere = '= upper(\'' . $table . '\')' ;
2009-12-11 18:23:24 +00:00
}
2010-01-17 20:42:54 +00:00
$fieldInfoStmt = oci_parse ( $this -> mConn , 'SELECT * FROM wiki_field_info_full WHERE table_name ' . $tableWhere . ' and column_name = UPPER(\'' . $field . '\')' );
2009-06-05 11:45:32 +00:00
2010-01-17 20:42:54 +00:00
if ( oci_execute ( $fieldInfoStmt , OCI_DEFAULT ) === false ) {
$e = oci_error ( $fieldInfoStmt );
2009-12-10 23:22:34 +00:00
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], 'fieldInfo QUERY' , __METHOD__ );
2009-06-05 11:45:32 +00:00
return false ;
}
2010-01-17 20:42:54 +00:00
$res = new ORAResult ( $this , $fieldInfoStmt );
$fieldInfoTemp = new ORAField ( $res -> fetchRow () );
$table = $fieldInfoTemp -> tableName ();
$this -> mFieldInfoCache [ " $table . $field " ] = $fieldInfoTemp ;
return $fieldInfoTemp ;
2007-03-11 04:00:43 +00:00
}
function begin ( $fname = '' ) {
$this -> mTrxLevel = 1 ;
}
2009-12-11 18:23:24 +00:00
2007-03-11 04:00:43 +00:00
function immediateCommit ( $fname = '' ) {
return true ;
}
2009-12-11 18:23:24 +00:00
2007-03-11 04:00:43 +00:00
function commit ( $fname = '' ) {
2009-12-10 23:22:34 +00:00
oci_commit ( $this -> mConn );
2007-03-11 04:00:43 +00:00
$this -> mTrxLevel = 0 ;
}
/* Not even sure why this is used in the main codebase... */
2009-12-10 23:22:34 +00:00
function limitResultForUpdate ( $sql , $num ) {
2007-03-11 04:00:43 +00:00
return $sql ;
}
2009-06-08 18:30:27 +00:00
/* defines must comply with ^define\s*([^\s=]*)\s*=\s?'\{\$([^\}]*)\}'; */
function sourceStream ( $fp , $lineCallback = false , $resultCallback = false ) {
2009-12-11 18:23:24 +00:00
$cmd = '' ;
2009-06-08 18:30:27 +00:00
$done = false ;
$dollarquote = false ;
2010-01-05 13:35:19 +00:00
2009-06-08 18:30:27 +00:00
$replacements = array ();
while ( ! feof ( $fp ) ) {
if ( $lineCallback ) {
call_user_func ( $lineCallback );
}
$line = trim ( fgets ( $fp , 1024 ) );
$sl = strlen ( $line ) - 1 ;
2009-12-11 18:23:24 +00:00
if ( $sl < 0 ) {
continue ;
}
if ( '-' == $line { 0 } && '-' == $line { 1 } ) {
continue ;
}
2009-06-08 18:30:27 +00:00
// Allow dollar quoting for function declarations
2009-12-10 23:22:34 +00:00
if ( substr ( $line , 0 , 8 ) == '/*$mw$*/' ) {
if ( $dollarquote ) {
2009-06-08 18:30:27 +00:00
$dollarquote = false ;
$done = true ;
2009-12-11 18:23:24 +00:00
} else {
2009-06-08 18:30:27 +00:00
$dollarquote = true ;
}
2009-12-11 18:23:24 +00:00
} elseif ( ! $dollarquote ) {
2009-12-10 23:22:34 +00:00
if ( ';' == $line { $sl } && ( $sl < 2 || ';' != $line { $sl - 1 } ) ) {
2009-06-08 18:30:27 +00:00
$done = true ;
$line = substr ( $line , 0 , $sl );
}
}
2010-01-06 19:59:42 +00:00
if ( $cmd != '' ) {
2009-12-11 18:23:24 +00:00
$cmd .= ' ' ;
}
2009-06-08 18:30:27 +00:00
$cmd .= " $line\n " ;
if ( $done ) {
2009-12-10 23:22:34 +00:00
$cmd = str_replace ( ';;' , " ; " , $cmd );
if ( strtolower ( substr ( $cmd , 0 , 6 ) ) == 'define' ) {
if ( preg_match ( '/^define\s*([^\s=]*)\s*=\s*\'\{\$([^\}]*)\}\'/' , $cmd , $defines ) ) {
2009-06-08 18:30:27 +00:00
$replacements [ $defines [ 2 ]] = $defines [ 1 ];
}
} else {
2009-12-10 23:22:34 +00:00
foreach ( $replacements as $mwVar => $scVar ) {
$cmd = str_replace ( '&' . $scVar . '.' , '{$' . $mwVar . '}' , $cmd );
2009-06-08 18:30:27 +00:00
}
$cmd = $this -> replaceVars ( $cmd );
$res = $this -> query ( $cmd , __METHOD__ );
if ( $resultCallback ) {
call_user_func ( $resultCallback , $res , $this );
}
2009-12-11 18:23:24 +00:00
2009-06-08 18:30:27 +00:00
if ( false === $res ) {
$err = $this -> lastError ();
return " Query \" { $cmd } \" failed with error code \" $err\ " . \n " ;
}
}
$cmd = '' ;
$done = false ;
}
}
return true ;
}
function setup_database () {
global $wgVersion , $wgDBmwschema , $wgDBts2schema , $wgDBport , $wgDBuser ;
2009-12-11 18:23:24 +00:00
2009-06-08 18:30:27 +00:00
echo " <li>Creating DB objects</li> \n " ;
2009-07-29 23:41:16 +00:00
$res = $this -> sourceFile ( " ../maintenance/ora/tables.sql " );
2009-12-11 18:23:24 +00:00
2009-06-08 18:30:27 +00:00
// Avoid the non-standard "REPLACE INTO" syntax
echo " <li>Populating table interwiki</li> \n " ;
$f = fopen ( " ../maintenance/interwiki.sql " , 'r' );
2009-12-10 23:22:34 +00:00
if ( $f == false ) {
dieout ( " <li>Could not find the interwiki.sql file</li> " );
2009-06-08 18:30:27 +00:00
}
2009-12-11 18:23:24 +00:00
2009-12-10 23:22:34 +00:00
// do it like the postgres :D
2009-06-08 18:30:27 +00:00
$SQL = " INSERT INTO interwiki(iw_prefix,iw_url,iw_local) VALUES " ;
2009-12-11 18:23:24 +00:00
while ( ! feof ( $f ) ) {
2009-12-10 23:22:34 +00:00
$line = fgets ( $f , 1024 );
2009-06-08 18:30:27 +00:00
$matches = array ();
2009-12-10 23:22:34 +00:00
if ( ! preg_match ( '/^\s*(\(.+?),(\d)\)/' , $line , $matches ) ) {
2009-06-08 18:30:27 +00:00
continue ;
}
2009-12-10 23:22:34 +00:00
$this -> query ( " $SQL $matches[1] , $matches[2] ) " );
2009-06-08 18:30:27 +00:00
}
echo " <li>Table interwiki successfully populated</li> \n " ;
}
2009-12-10 23:22:34 +00:00
function strencode ( $s ) {
return str_replace ( " ' " , " '' " , $s );
2007-03-11 04:00:43 +00:00
}
function addQuotes ( $s ) {
2009-06-05 11:45:32 +00:00
global $wgLang ;
2009-12-11 18:23:24 +00:00
if ( isset ( $wgLang -> mLoaded ) && $wgLang -> mLoaded ) {
2009-12-10 23:22:34 +00:00
$s = $wgLang -> checkTitleEncoding ( $s );
2009-12-11 18:23:24 +00:00
}
2009-12-10 23:22:34 +00:00
return " ' " . $this -> strencode ( $s ) . " ' " ;
2007-03-11 04:00:43 +00:00
}
function quote_ident ( $s ) {
return $s ;
}
2009-06-05 11:45:32 +00:00
function selectRow ( $table , $vars , $conds , $fname = 'DatabaseOracle::selectRow' , $options = array (), $join_conds = array () ) {
2009-11-05 20:04:47 +00:00
global $wgLang ;
$conds2 = array ();
2010-01-17 20:42:54 +00:00
$conds = ( $conds != null && ! is_array ( $conds )) ? array ( $conds ) : $conds ;
2009-12-10 23:22:34 +00:00
foreach ( $conds as $col => $val ) {
$col_type = $this -> fieldInfo ( $this -> tableName ( $table ), $col ) -> type ();
2009-12-11 18:23:24 +00:00
if ( $col_type == 'CLOB' ) {
2009-12-10 23:22:34 +00:00
$conds2 [ 'TO_CHAR(' . $col . ')' ] = $wgLang -> checkTitleEncoding ( $val );
2009-12-11 18:23:24 +00:00
} elseif ( $col_type == 'VARCHAR2' && ! mb_check_encoding ( $val ) ) {
2009-12-10 23:22:34 +00:00
$conds2 [ $col ] = $wgLang -> checkTitleEncoding ( $val );
2009-11-06 17:12:18 +00:00
} else {
$conds2 [ $col ] = $val ;
}
2009-11-05 20:04:47 +00:00
}
2009-12-11 18:23:24 +00:00
if ( is_array ( $table ) ) {
foreach ( $table as $tab ) {
2009-12-10 23:22:34 +00:00
$tab = $this -> tableName ( $tab );
2009-12-11 18:23:24 +00:00
}
} else {
2009-12-10 23:22:34 +00:00
$table = $this -> tableName ( $table );
2009-12-11 18:23:24 +00:00
}
2009-11-05 20:04:47 +00:00
2009-12-10 23:22:34 +00:00
return parent :: selectRow ( $table , $vars , $conds2 , $fname , $options , $join_conds );
2009-06-05 11:45:32 +00:00
}
2007-03-11 04:00:43 +00:00
/**
* Returns an optional USE INDEX clause to go after the table , and a
* string to go at the end of the query
*
* @ private
*
2008-11-29 18:50:39 +00:00
* @ param $options Array : an associative array of options to be turned into
2007-03-11 04:00:43 +00:00
* an SQL query , valid keys are listed in the function .
* @ return array
*/
function makeSelectOptions ( $options ) {
2007-03-11 15:49:27 +00:00
$preLimitTail = $postLimitTail = '' ;
2007-03-11 04:00:43 +00:00
$startOpts = '' ;
$noKeyOptions = array ();
foreach ( $options as $key => $option ) {
if ( is_numeric ( $key ) ) {
$noKeyOptions [ $option ] = true ;
}
}
2009-12-11 18:23:24 +00:00
if ( isset ( $options [ 'GROUP BY' ] ) ) {
$preLimitTail .= " GROUP BY { $options [ 'GROUP BY' ] } " ;
}
if ( isset ( $options [ 'ORDER BY' ] ) ) {
$preLimitTail .= " ORDER BY { $options [ 'ORDER BY' ] } " ;
}
2008-04-14 07:45:50 +00:00
2009-12-10 23:22:34 +00:00
# if ( isset( $noKeyOptions['FOR UPDATE'] ) ) $tailOpts .= ' FOR UPDATE';
# if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) $tailOpts .= ' LOCK IN SHARE MODE';
2009-12-11 18:23:24 +00:00
if ( isset ( $noKeyOptions [ 'DISTINCT' ] ) || isset ( $noKeyOptions [ 'DISTINCTROW' ] ) ) {
$startOpts .= 'DISTINCT' ;
}
2007-03-11 04:00:43 +00:00
if ( isset ( $options [ 'USE INDEX' ] ) && ! is_array ( $options [ 'USE INDEX' ] ) ) {
$useIndex = $this -> useIndexClause ( $options [ 'USE INDEX' ] );
} else {
$useIndex = '' ;
}
2008-04-14 07:45:50 +00:00
2007-03-11 15:49:27 +00:00
return array ( $startOpts , $useIndex , $preLimitTail , $postLimitTail );
2007-03-11 04:00:43 +00:00
}
2009-11-03 14:32:34 +00:00
public function delete ( $table , $conds , $fname = 'DatabaseOracle::delete' ) {
2009-11-05 20:04:47 +00:00
global $wgLang ;
2009-10-30 09:44:37 +00:00
2009-12-10 23:22:34 +00:00
if ( $wgLang != null ) {
2009-11-09 14:34:03 +00:00
$conds2 = array ();
2010-01-17 20:42:54 +00:00
$conds = ( $conds != null && ! is_array ( $conds )) ? array ( $conds ) : $conds ;
2009-12-10 23:22:34 +00:00
foreach ( $conds as $col => $val ) {
$col_type = $this -> fieldInfo ( $this -> tableName ( $table ), $col ) -> type ();
2009-12-11 18:23:24 +00:00
if ( $col_type == 'CLOB' ) {
2009-12-10 23:22:34 +00:00
$conds2 [ 'TO_CHAR(' . $col . ')' ] = $wgLang -> checkTitleEncoding ( $val );
2009-12-11 18:23:24 +00:00
} else {
2009-12-10 23:22:34 +00:00
if ( is_array ( $val ) ) {
2009-11-27 13:44:57 +00:00
$conds2 [ $col ] = $val ;
2009-12-11 18:23:24 +00:00
foreach ( $conds2 [ $col ] as & $val2 ) {
2009-12-10 23:22:34 +00:00
$val2 = $wgLang -> checkTitleEncoding ( $val2 );
2009-12-11 18:23:24 +00:00
}
2009-11-27 13:44:57 +00:00
} else {
2009-12-10 23:22:34 +00:00
$conds2 [ $col ] = $wgLang -> checkTitleEncoding ( $val );
2009-11-27 13:44:57 +00:00
}
2009-12-11 18:23:24 +00:00
}
2009-11-09 14:34:03 +00:00
}
2009-12-11 18:23:24 +00:00
2009-11-09 14:34:03 +00:00
return parent :: delete ( $table , $conds2 , $fname );
2009-12-11 18:23:24 +00:00
} else {
return parent :: delete ( $table , $conds , $fname );
}
2009-06-05 11:45:32 +00:00
}
2009-06-13 06:31:38 +00:00
2009-12-10 23:22:34 +00:00
function bitNot ( $field ) {
// expecting bit-fields smaller than 4bytes
return 'BITNOT(' . $bitField . ')' ;
2009-06-13 06:31:38 +00:00
}
2009-12-10 23:22:34 +00:00
function bitAnd ( $fieldLeft , $fieldRight ) {
return 'BITAND(' . $fieldLeft . ', ' . $fieldRight . ')' ;
2009-06-13 06:31:38 +00:00
}
2009-12-10 23:22:34 +00:00
function bitOr ( $fieldLeft , $fieldRight ) {
return 'BITOR(' . $fieldLeft . ', ' . $fieldRight . ')' ;
2009-06-13 06:31:38 +00:00
}
2009-06-05 11:45:32 +00:00
2007-06-04 21:43:02 +00:00
/**
* How lagged is this slave ?
*
* @ return int
*/
public function getLag () {
# Not implemented for Oracle
return 0 ;
}
2007-03-11 04:00:43 +00:00
2009-12-10 23:22:34 +00:00
function setFakeSlaveLag ( $lag ) { }
function setFakeMaster ( $enabled = true ) { }
2008-03-30 09:48:15 +00:00
function getDBname () {
return $this -> mDBname ;
}
function getServer () {
return $this -> mServer ;
}
2010-01-05 13:35:19 +00:00
2009-06-08 18:30:27 +00:00
public function replaceVars ( $ins ) {
2009-12-10 23:22:34 +00:00
$varnames = array ( 'wgDBprefix' );
if ( $this -> mFlags & DBO_SYSDBA ) {
2009-06-08 18:30:27 +00:00
$varnames [] = 'wgDBOracleDefTS' ;
$varnames [] = 'wgDBOracleTempTS' ;
}
// Ordinary variables
foreach ( $varnames as $var ) {
2009-12-10 23:22:34 +00:00
if ( isset ( $GLOBALS [ $var ] ) ) {
2009-06-08 18:30:27 +00:00
$val = addslashes ( $GLOBALS [ $var ] ); // FIXME: safety check?
$ins = str_replace ( '{$' . $var . '}' , $val , $ins );
$ins = str_replace ( '/*$' . $var . '*/`' , '`' . $val , $ins );
$ins = str_replace ( '/*$' . $var . '*/' , $val , $ins );
}
}
2009-12-10 23:22:34 +00:00
return parent :: replaceVars ( $ins );
2009-06-08 18:30:27 +00:00
}
2008-08-18 15:22:00 +00:00
public function getSearchEngine () {
2009-12-11 18:23:24 +00:00
return 'SearchOracle' ;
2008-08-18 15:22:00 +00:00
}
2007-03-11 04:00:43 +00:00
} // end DatabaseOracle class