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
/**
2010-08-01 21:13:44 +00:00
* This is the Oracle database abstraction layer .
*
2012-04-26 08:47:10 +00:00
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License along
* with this program ; if not , write to the Free Software Foundation , Inc . ,
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
* http :// www . gnu . org / copyleft / gpl . html
*
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
* @ file
2010-08-01 21:13:44 +00:00
* @ ingroup Database
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
*/
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
2013-02-03 18:47:42 +00:00
* 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 $nrows ;
2011-06-17 16:03:52 +00:00
2010-11-18 13:17:16 +00:00
private $columns = array ();
2007-03-11 04:00:43 +00:00
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 ();
2010-10-14 20:53:04 +00:00
foreach ( $array_in as $item ) {
2009-12-10 23:22:34 +00:00
$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
2011-05-26 19:21:50 +00:00
/**
* @ param $db DatabaseBase
* @ param $stmt
* @ param bool $unique
*/
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 );
2010-10-02 08:04:58 +00:00
$db -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], '' , __METHOD__ );
2010-10-25 10:56:07 +00:00
$this -> free ();
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
}
2013-02-03 18:47:42 +00:00
if ( $this -> nrows > 0 ) {
2010-11-18 13:17:16 +00:00
foreach ( $this -> rows [ 0 ] as $k => $v ) {
$this -> columns [ $k ] = strtolower ( oci_field_name ( $stmt , $k + 1 ) );
}
}
2007-03-11 04:00:43 +00:00
$this -> cursor = 0 ;
2010-11-18 13:17:16 +00:00
oci_free_statement ( $stmt );
2007-03-11 04:00:43 +00:00
}
2009-06-05 11:45:32 +00:00
public function free () {
2013-02-03 18:47:42 +00:00
unset ( $this -> db );
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 () {
2013-02-03 18:47:42 +00:00
return count ( $this -> columns );
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 ) {
2010-11-18 13:17:16 +00:00
$lc = $this -> columns [ $k ];
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 ) {
2010-11-18 13:17:16 +00:00
$lc = $this -> columns [ $k ];
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
*/
2010-11-21 19:56:51 +00:00
class ORAField implements Field {
2009-06-05 11:45:32 +00:00
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 ;
}
2010-11-21 19:56:51 +00:00
function isNullable () {
2009-06-05 11:45:32 +00:00
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 ;
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 ,
2010-10-25 12:06:37 +00:00
$flags = 0 , $tablePrefix = 'get from global' )
2007-03-11 04:00:43 +00:00
{
2011-04-12 20:56:35 +00:00
global $wgDBprefix ;
$tablePrefix = $tablePrefix == 'get from global' ? strtoupper ( $wgDBprefix ) : strtoupper ( $tablePrefix );
2010-10-25 12:06:37 +00:00
parent :: __construct ( $server , $user , $password , $dbName , $flags , $tablePrefix );
2011-01-24 18:36:09 +00:00
wfRunHooks ( 'DatabaseOraclePostInit' , array ( $this ) );
2007-03-11 04:00:43 +00:00
}
2011-04-28 12:44:19 +00:00
function __destruct () {
2013-03-24 10:01:51 +00:00
if ( $this -> mOpened ) {
2011-04-28 12:44:19 +00:00
wfSuppressWarnings ();
$this -> close ();
wfRestoreWarnings ();
}
}
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 ;
}
/**
* Usually aborts on failure
2012-10-07 23:35:26 +00:00
* @ param string $server
* @ param string $user
* @ param string $password
* @ param string $dbName
* @ throws DBConnectionError
2012-02-09 21:33:27 +00:00
* @ return DatabaseBase | null
2007-03-11 04:00:43 +00:00
*/
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 -> mUser = $user ;
$this -> mPassword = $password ;
2010-10-18 16:09:18 +00:00
// changed internal variables functions
// mServer now holds the TNS endpoint
// mDBname is schema name if different from username
2010-10-19 06:25:12 +00:00
if ( ! $server ) {
2010-10-18 16:09:18 +00:00
// backward compatibillity (server used to be null and TNS was supplied in dbname)
$this -> mServer = $dbName ;
$this -> mDBname = $user ;
} else {
$this -> mServer = $server ;
2010-10-19 06:25:12 +00:00
if ( ! $dbName ) {
2010-10-18 16:09:18 +00:00
$this -> mDBname = $user ;
2011-06-17 16:03:52 +00:00
} else {
2010-10-18 16:09:18 +00:00
$this -> mDBname = $dbName ;
}
}
2007-03-11 04:00:43 +00:00
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 ;
2011-03-01 13:58:50 +00:00
wfSuppressWarnings ();
2009-12-11 18:23:24 +00:00
if ( $this -> mFlags & DBO_DEFAULT ) {
2011-03-01 13:58:50 +00:00
$this -> mConn = oci_new_connect ( $this -> mUser , $this -> mPassword , $this -> mServer , $this -> defaultCharset , $session_mode );
2009-12-11 18:23:24 +00:00
} else {
2011-03-01 13:58:50 +00:00
$this -> mConn = oci_connect ( $this -> mUser , $this -> mPassword , $this -> mServer , $this -> defaultCharset , $session_mode );
2010-10-18 16:09:18 +00:00
}
2011-03-01 13:58:50 +00:00
wfRestoreWarnings ();
2010-10-18 16:09:18 +00:00
if ( $this -> mUser != $this -> mDBname ) {
//change current schema in session
$this -> selectDB ( $this -> mDBname );
2009-12-11 18:23:24 +00:00
}
2007-03-11 04:00:43 +00:00
2010-06-09 11:44:05 +00:00
if ( ! $this -> mConn ) {
2010-10-25 16:49:59 +00:00
throw new DBConnectionError ( $this , $this -> lastError () );
2007-03-11 04:00:43 +00:00
}
$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\'' );
2011-06-07 05:09:32 +00:00
$this -> doQuery ( 'ALTER SESSION SET NLS_NUMERIC_CHARACTERS=\'.,\'' );
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
2012-02-09 21:33:27 +00:00
* @ return bool
2007-03-11 04:00:43 +00:00
*/
2012-02-28 14:42:08 +00:00
protected function closeConnection () {
return oci_close ( $this -> mConn );
2007-03-11 04:00:43 +00:00
}
function execFlags () {
2011-06-07 05:09:32 +00:00
return $this -> mTrxLevel ? OCI_NO_AUTO_COMMIT : OCI_COMMIT_ON_SUCCESS ;
2007-03-11 04:00:43 +00:00
}
2011-06-20 12:09:22 +00:00
protected function doQuery ( $sql ) {
2009-12-10 23:22:34 +00:00
wfDebug ( " SQL: [ $sql ] \n " );
2012-11-16 12:52:55 +00:00
if ( ! StringUtils :: isUtf8 ( $sql ) ) {
2010-02-20 19:22:27 +00:00
throw new MWException ( " SQL encoding is invalid \n $sql " );
}
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
2011-01-06 19:25:47 +00:00
if ( ! $this -> getFlag ( DBO_DDLMODE ) ) {
2009-12-10 23:22:34 +00:00
$sql = preg_replace ( '/ as /i' , ' ' , $sql );
2009-12-11 18:23:24 +00:00
}
2011-01-06 19:25:47 +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 );
2010-10-02 08:04:58 +00:00
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], $sql , __METHOD__ );
2010-05-03 14:16:46 +00:00
return false ;
2007-03-30 19:35:24 +00:00
}
2008-04-14 07:45:50 +00:00
2010-06-09 11:44:05 +00:00
if ( ! oci_execute ( $stmt , $this -> execFlags () ) ) {
2009-12-10 23:22:34 +00:00
$e = oci_error ( $stmt );
2009-12-11 18:23:24 +00:00
if ( ! $this -> ignore_DUP_VAL_ON_INDEX || $e [ 'code' ] != '1' ) {
2010-10-02 08:04:58 +00:00
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], $sql , __METHOD__ );
2010-05-03 14:16:46 +00:00
return false ;
2009-12-11 18:23:24 +00:00
}
2007-03-11 04:00:43 +00:00
}
2010-09-05 18:00:33 +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 ) {
2010-11-18 13:17:16 +00:00
if ( $res instanceof ResultWrapper ) {
$res = $res -> result ;
2009-06-05 11:45:32 +00:00
}
2011-06-17 16:03:52 +00:00
2010-11-18 13:17:16 +00:00
$res -> free ();
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
function fetchObject ( $res ) {
2010-11-18 13:17:16 +00:00
if ( $res instanceof ResultWrapper ) {
$res = $res -> result ;
2009-06-05 11:45:32 +00:00
}
2011-06-17 16:03:52 +00:00
2010-11-18 13:17:16 +00:00
return $res -> fetchObject ();
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
function fetchRow ( $res ) {
2010-11-18 13:17:16 +00:00
if ( $res instanceof ResultWrapper ) {
$res = $res -> result ;
2009-06-05 11:45:32 +00:00
}
2010-11-18 13:17:16 +00:00
return $res -> fetchRow ();
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
function numRows ( $res ) {
2010-11-18 13:17:16 +00:00
if ( $res instanceof ResultWrapper ) {
$res = $res -> result ;
2009-06-05 11:45:32 +00:00
}
2010-11-18 13:17:16 +00:00
return $res -> numRows ();
2007-03-11 04:00:43 +00:00
}
2009-12-10 23:22:34 +00:00
function numFields ( $res ) {
2010-11-18 13:17:16 +00:00
if ( $res instanceof ResultWrapper ) {
$res = $res -> result ;
2009-06-05 11:45:32 +00:00
}
2010-11-18 13:17:16 +00:00
return $res -> 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
2012-02-09 21:33:27 +00:00
* @ return null
2007-03-11 04:00:43 +00:00
*/
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
2012-02-09 21:33:27 +00:00
* @ return bool
2007-03-11 04:00:43 +00:00
*/
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 ;
}
2013-03-18 19:44:43 +00:00
private function fieldBindStatement ( $table , $col , & $val , $includeCol = false ) {
2010-10-25 10:56:07 +00:00
$col_info = $this -> fieldInfoMulti ( $table , $col );
$col_type = $col_info != false ? $col_info -> type () : 'CONSTANT' ;
2011-04-15 10:48:02 +00:00
2010-10-25 10:56:07 +00:00
$bind = '' ;
if ( is_numeric ( $col ) ) {
$bind = $val ;
$val = null ;
2011-06-17 16:03:52 +00:00
return $bind ;
} elseif ( $includeCol ) {
2010-10-25 10:56:07 +00:00
$bind = " $col = " ;
}
2011-06-17 16:03:52 +00:00
2010-10-25 10:56:07 +00:00
if ( $val == '' && $val !== 0 && $col_type != 'BLOB' && $col_type != 'CLOB' ) {
$val = null ;
}
2011-07-08 12:28:59 +00:00
if ( $val === 'NULL' ) {
$val = null ;
}
2010-10-25 10:56:07 +00:00
if ( $val === null ) {
2011-01-10 19:22:27 +00:00
if ( $col_info != false && $col_info -> isNullable () == 0 && $col_info -> defaultValue () != null ) {
2010-10-25 10:56:07 +00:00
$bind .= 'DEFAULT' ;
} else {
$bind .= 'NULL' ;
}
} else {
$bind .= ':' . $col ;
}
2011-06-17 16:03:52 +00:00
2010-10-25 10:56:07 +00:00
return $bind ;
}
2010-01-28 14:58:45 +00:00
private function insertOneRow ( $table , $row , $fname ) {
2010-07-22 04:00:39 +00:00
global $wgContLang ;
2009-06-05 11:45:32 +00:00
2010-01-28 14:58:45 +00:00
$table = $this -> tableName ( $table );
2007-03-11 04:00:43 +00:00
// "INSERT INTO tables (a, b, c)"
2010-01-28 14:58:45 +00:00
$sql = " INSERT INTO " . $table . " ( " . join ( ',' , array_keys ( $row ) ) . ')' ;
2007-03-11 04:00:43 +00:00
$sql .= " VALUES ( " ;
// for each value, append ":key"
$first = true ;
2010-10-25 10:56:07 +00:00
foreach ( $row as $col => & $val ) {
if ( ! $first ) {
$sql .= ', ' ;
2009-12-11 18:23:24 +00:00
} else {
2010-10-25 10:56:07 +00:00
$first = false ;
2009-12-11 18:23:24 +00:00
}
2011-06-17 16:03:52 +00:00
2010-10-25 10:56:07 +00:00
$sql .= $this -> fieldBindStatement ( $table , $col , $val );
2007-03-11 04:00:43 +00:00
}
2009-06-05 11:45:32 +00:00
$sql .= ')' ;
2007-03-11 04:00:43 +00:00
2010-10-25 10:56:07 +00:00
if ( ( $this -> mLastResult = $stmt = oci_parse ( $this -> mConn , $sql ) ) === false ) {
$e = oci_error ( $this -> mConn );
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], $sql , __METHOD__ );
return false ;
}
2009-12-10 23:22:34 +00:00
foreach ( $row as $col => & $val ) {
2010-01-28 14:58:45 +00:00
$col_info = $this -> fieldInfoMulti ( $table , $col );
2010-01-20 16:19:08 +00:00
$col_type = $col_info != false ? $col_info -> type () : 'CONSTANT' ;
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 ) ) {
2010-11-09 08:56:15 +00:00
$val = $val -> fetch ();
2009-12-11 18:23:24 +00:00
}
2011-11-10 07:41:12 +00:00
// backward compatibility
2009-12-11 18:23:24 +00:00
if ( preg_match ( '/^timestamp.*/i' , $col_type ) == 1 && strtolower ( $val ) == 'infinity' ) {
2011-11-10 07:41:12 +00:00
$val = $this -> getInfinity ();
2009-12-11 18:23:24 +00:00
}
2010-01-05 13:35:19 +00:00
2010-07-22 04:00:39 +00:00
$val = ( $wgContLang != null ) ? $wgContLang -> checkTitleEncoding ( $val ) : $val ;
2011-06-07 05:09:32 +00:00
if ( oci_bind_by_name ( $stmt , " : $col " , $val , - 1 , SQLT_CHR ) === false ) {
2010-10-25 10:56:07 +00:00
$e = oci_error ( $stmt );
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], $sql , __METHOD__ );
2010-05-03 14:16:46 +00:00
return false ;
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
2010-11-09 08:56:15 +00:00
if ( is_object ( $val ) ) {
$val = $val -> fetch ();
}
2010-10-25 10:56:07 +00:00
if ( $col_type == 'BLOB' ) {
2010-11-09 08:56:15 +00:00
$lob [ $col ] -> writeTemporary ( $val , OCI_TEMP_BLOB );
oci_bind_by_name ( $stmt , " : $col " , $lob [ $col ], - 1 , OCI_B_BLOB );
2009-06-05 11:45:32 +00:00
} else {
2010-11-09 08:56:15 +00:00
$lob [ $col ] -> writeTemporary ( $val , OCI_TEMP_CLOB );
2009-12-10 23:22:34 +00:00
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 ();
2011-04-22 11:31:18 +00:00
if ( oci_execute ( $stmt , $this -> execFlags () ) === false ) {
2009-12-10 23:22:34 +00:00
$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 , __METHOD__ );
2010-05-03 14:16:46 +00:00
return false ;
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 ) ) {
2010-10-14 20:53:04 +00:00
foreach ( $lob as $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 ) ) {
2013-02-03 18:47:42 +00:00
$srcTable = implode ( ',' , array_map ( array ( & $this , 'tableName' ), $srcTable ) );
2009-06-05 11:45:32 +00:00
} 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' ]] ) )
2010-09-05 18:35:34 +00:00
{
2009-12-10 23:22:34 +00:00
$varMap [ $sequenceData [ 'column' ]] = 'GET_SEQUENCE_VALUE(\'' . $sequenceData [ 'sequence' ] . '\')' ;
2010-09-05 18:35:34 +00:00
}
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 ;
2010-10-14 20:53:04 +00:00
foreach ( $varMap as & $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 ;
}
2011-09-06 20:51:10 +00:00
function tableName ( $name , $format = 'quoted' ) {
2009-06-05 11:45:32 +00:00
/*
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
2011-09-06 20:51:10 +00:00
return parent :: tableName ( strtoupper ( $name ), $format );
2007-03-11 04:00:43 +00:00
}
2011-05-04 10:43:34 +00:00
function tableNameInternal ( $name ) {
$name = $this -> tableName ( $name );
return preg_replace ( '/.*\.(.*)/' , '$1' , $name );
}
2007-03-11 04:00:43 +00:00
/**
* Return the next in a sequence , save the value for retrieval via insertId ()
2012-02-09 21:33:27 +00:00
* @ return null
2007-03-11 04:00:43 +00:00
*/
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 ];
return $this -> mInsertId ;
}
2009-10-28 19:15:19 +00:00
/**
* Return sequence_name if table has a sequence
2012-02-09 21:33:27 +00:00
* @ return bool
2009-10-28 19:15:19 +00:00
*/
2010-01-28 14:58:45 +00:00
private function getSequenceData ( $table ) {
2009-12-11 18:23:24 +00:00
if ( $this -> sequenceData == null ) {
2011-06-07 05:09:32 +00:00
$result = $this -> doQuery ( " SELECT lower(asq.sequence_name),
lower ( atc . table_name ),
lower ( atc . column_name )
FROM all_sequences asq , all_tab_columns atc
WHERE decode ( atc . table_name , '{$this->mTablePrefix}MWUSER' , '{$this->mTablePrefix}USER' , atc . table_name ) || '_' ||
atc . column_name || '_SEQ' = '{$this->mTablePrefix}' || asq . sequence_name
2011-09-02 10:42:08 +00:00
AND asq . sequence_owner = upper ( '{$this->mDBname}' )
AND atc . owner = upper ( '{$this->mDBname}' ) " );
2010-01-05 13:35:19 +00:00
2009-12-11 18:23:24 +00:00
while ( ( $row = $result -> fetchRow () ) !== false ) {
2011-09-02 10:42:08 +00:00
$this -> sequenceData [ $row [ 1 ]] = array (
2009-12-11 18:23:24 +00:00
'sequence' => $row [ 0 ],
'column' => $row [ 2 ]
);
}
2009-10-28 19:15:19 +00:00
}
2011-06-07 05:09:32 +00:00
$table = strtolower ( $this -> removeIdentifierQuotes ( $this -> tableName ( $table ) ) );
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
# Returns the size of a text field, or -1 for "unlimited"
function textFieldSize ( $table , $field ) {
2011-02-18 22:58:02 +00:00
$fieldInfoData = $this -> fieldInfo ( $table , $field );
2011-03-01 13:50:52 +00:00
return $fieldInfoData -> maxLength ();
2007-03-11 04:00:43 +00:00
}
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 ) " ;
}
2010-11-09 08:56:15 +00:00
function encodeBlob ( $b ) {
return new Blob ( $b );
}
function decodeBlob ( $b ) {
if ( $b instanceof Blob ) {
$b = $b -> fetch ();
}
return $b ;
}
2009-12-10 23:22:34 +00:00
function unionQueries ( $sqls , $all ) {
2009-06-05 11:45:32 +00:00
$glue = ' UNION ALL ' ;
2013-02-09 21:44:24 +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' ) {
2011-11-10 13:29:32 +00:00
$temporary = $temporary ? 'TRUE' : 'FALSE' ;
2010-09-05 18:00:33 +00:00
2011-04-12 18:54:51 +00:00
$newName = strtoupper ( $newName );
$oldName = strtoupper ( $oldName );
2010-09-05 18:00:33 +00:00
2011-06-07 05:09:32 +00:00
$tabName = substr ( $newName , strlen ( $this -> mTablePrefix ) );
2011-06-02 22:23:05 +00:00
$oldPrefix = substr ( $oldName , 0 , strlen ( $oldName ) - strlen ( $tabName ) );
2011-06-07 05:09:32 +00:00
$newPrefix = strtoupper ( $this -> mTablePrefix );
2010-09-05 18:00:33 +00:00
2011-06-02 22:23:05 +00:00
return $this -> doQuery ( " BEGIN DUPLICATE_TABLE( ' $tabName ', ' $oldPrefix ', ' $newPrefix ', $temporary ); END; " );
2009-11-06 17:12:18 +00:00
}
2011-01-10 19:22:27 +00:00
function listTables ( $prefix = null , $fname = 'DatabaseOracle::listTables' ) {
$listWhere = '' ;
2013-02-03 18:47:42 +00:00
if ( ! empty ( $prefix ) ) {
$listWhere = ' AND table_name LIKE \'' . strtoupper ( $prefix ) . '%\'' ;
2011-01-10 19:22:27 +00:00
}
2011-06-17 16:03:52 +00:00
2011-06-01 08:41:44 +00:00
$owner = strtoupper ( $this -> mDBname );
2011-06-02 22:23:05 +00:00
$result = $this -> doQuery ( " SELECT table_name FROM all_tables WHERE owner=' $owner ' AND table_name NOT LIKE '%!_IDX \$ _' ESCAPE '!' $listWhere " );
2011-01-10 19:22:27 +00:00
// dirty code ... i know
$endArray = array ();
2013-02-03 18:47:42 +00:00
$endArray [] = strtoupper ( $prefix . 'MWUSER' );
$endArray [] = strtoupper ( $prefix . 'PAGE' );
$endArray [] = strtoupper ( $prefix . 'IMAGE' );
2011-01-10 19:22:27 +00:00
$fixedOrderTabs = $endArray ;
2013-03-24 10:01:51 +00:00
while ( ( $row = $result -> fetchRow () ) !== false ) {
2013-02-03 18:47:42 +00:00
if ( ! in_array ( $row [ 'table_name' ], $fixedOrderTabs ) )
2011-01-10 19:22:27 +00:00
$endArray [] = $row [ 'table_name' ];
}
return $endArray ;
}
public function dropTable ( $tableName , $fName = 'DatabaseOracle::dropTable' ) {
2013-02-03 18:47:42 +00:00
$tableName = $this -> tableName ( $tableName );
2011-01-10 19:22:27 +00:00
if ( ! $this -> tableExists ( $tableName ) ) {
return false ;
}
2011-06-17 16:03:52 +00:00
2011-01-10 19:22:27 +00:00
return $this -> doQuery ( " DROP TABLE $tableName CASCADE CONSTRAINTS PURGE " );
}
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
*/
2012-07-16 17:56:00 +00:00
public 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
*/
2010-08-22 20:55:07 +00:00
public static 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 () {
2010-10-19 06:25:12 +00:00
//better version number, fallback on driver
$rset = $this -> doQuery ( 'SELECT version FROM product_component_version WHERE UPPER(product) LIKE \'ORACLE DATABASE%\'' );
2013-02-03 18:47:42 +00:00
if ( ! ( $row = $rset -> fetchRow () ) ) {
2010-10-19 06:25:12 +00:00
return oci_server_version ( $this -> mConn );
2011-06-17 16:03:52 +00:00
}
2010-10-19 06:25:12 +00:00
return $row [ 'version' ];
2007-03-11 04:00:43 +00:00
}
2011-06-01 08:27:51 +00:00
/**
* Query whether a given index exists
2012-02-09 21:33:27 +00:00
* @ return bool
2011-06-01 08:27:51 +00:00
*/
function indexExists ( $table , $index , $fname = 'DatabaseOracle::indexExists' ) {
$table = $this -> tableName ( $table );
$table = strtoupper ( $this -> removeIdentifierQuotes ( $table ) );
$index = strtoupper ( $index );
$owner = strtoupper ( $this -> mDBname );
$SQL = " SELECT 1 FROM all_indexes WHERE owner=' $owner ' AND index_name=' { $table } _ { $index } ' " ;
$res = $this -> doQuery ( $SQL );
if ( $res ) {
$count = $res -> numRows ();
$res -> free ();
} else {
$count = 0 ;
}
return $count != 0 ;
}
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 )
2012-02-09 21:33:27 +00:00
* @ return int
2007-03-11 04:00:43 +00:00
*/
2011-11-10 20:39:23 +00:00
function tableExists ( $table , $fname = __METHOD__ ) {
2011-06-01 08:27:51 +00:00
$table = $this -> tableName ( $table );
2011-06-09 08:43:53 +00:00
$table = $this -> addQuotes ( strtoupper ( $this -> removeIdentifierQuotes ( $table ) ) );
$owner = $this -> addQuotes ( strtoupper ( $this -> mDBname ) );
$SQL = " SELECT 1 FROM all_tables WHERE owner= $owner AND 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 ;
}
2011-06-07 05:09:32 +00:00
return $count ;
2007-03-11 04:00:43 +00:00
}
/**
2010-01-28 14:58:45 +00:00
* Function translates mysql_fetch_field () functionality on ORACLE .
* Caching is present for reducing query time .
* For internal calls . Use fieldInfo for normal usage .
* Returns false if the field doesn ' t exist
*
2010-07-04 14:41:26 +00:00
* @ param $table Array
* @ param $field String
2011-05-29 14:01:47 +00:00
* @ return ORAField | ORAResult
2007-03-11 04:00:43 +00:00
*/
2010-01-28 14:58:45 +00:00
private function fieldInfoMulti ( $table , $field ) {
2010-09-05 18:35:34 +00:00
$field = strtoupper ( $field );
if ( is_array ( $table ) ) {
2011-05-04 10:43:34 +00:00
$table = array_map ( array ( & $this , 'tableNameInternal' ), $table );
2010-01-17 20:42:54 +00:00
$tableWhere = 'IN (' ;
2010-09-05 18:35:34 +00:00
foreach ( $table as & $singleTable ) {
2013-02-03 18:47:42 +00:00
$singleTable = $this -> removeIdentifierQuotes ( $singleTable );
2010-09-05 18:35:34 +00:00
if ( isset ( $this -> mFieldInfoCache [ " $singleTable . $field " ] ) ) {
2010-01-17 20:42:54 +00:00
return $this -> mFieldInfoCache [ " $singleTable . $field " ];
}
2010-09-05 18:35:34 +00:00
$tableWhere .= '\'' . $singleTable . '\',' ;
2010-01-17 20:42:54 +00:00
}
2010-09-05 18:35:34 +00:00
$tableWhere = rtrim ( $tableWhere , ',' ) . ')' ;
2010-01-17 20:42:54 +00:00
} else {
2013-02-03 18:47:42 +00:00
$table = $this -> removeIdentifierQuotes ( $this -> tableNameInternal ( $table ) );
2010-09-05 18:35:34 +00:00
if ( isset ( $this -> mFieldInfoCache [ " $table . $field " ] ) ) {
2010-01-17 20:42:54 +00:00
return $this -> mFieldInfoCache [ " $table . $field " ];
}
2010-01-20 16:19:08 +00:00
$tableWhere = '= \'' . $table . '\'' ;
2009-12-11 18:23:24 +00:00
}
2009-06-05 11:45:32 +00:00
2013-02-03 18:47:42 +00:00
$fieldInfoStmt = oci_parse ( $this -> mConn , 'SELECT * FROM wiki_field_info_full WHERE table_name ' . $tableWhere . ' and column_name = \'' . $field . '\'' );
2011-04-22 11:31:18 +00:00
if ( oci_execute ( $fieldInfoStmt , $this -> execFlags () ) === false ) {
2010-01-17 20:42:54 +00:00
$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-09-05 18:35:34 +00:00
if ( $res -> numRows () == 0 ) {
if ( is_array ( $table ) ) {
foreach ( $table as & $singleTable ) {
2010-01-20 16:19:08 +00:00
$this -> mFieldInfoCache [ " $singleTable . $field " ] = false ;
2010-01-17 20:42:54 +00:00
}
2010-01-20 16:19:08 +00:00
} else {
$this -> mFieldInfoCache [ " $table . $field " ] = false ;
2010-01-17 20:42:54 +00:00
}
2010-10-25 10:56:07 +00:00
$fieldInfoTemp = null ;
2010-01-17 20:42:54 +00:00
} else {
2010-01-20 16:19:08 +00:00
$fieldInfoTemp = new ORAField ( $res -> fetchRow () );
$table = $fieldInfoTemp -> tableName ();
$this -> mFieldInfoCache [ " $table . $field " ] = $fieldInfoTemp ;
2009-06-05 11:45:32 +00:00
}
2010-10-25 10:56:07 +00:00
$res -> free ();
return $fieldInfoTemp ;
2007-03-11 04:00:43 +00:00
}
2010-12-30 17:41:19 +00:00
/**
* @ throws DBUnexpectedError
* @ param $table
* @ param $field
* @ return ORAField
*/
2010-01-28 14:58:45 +00:00
function fieldInfo ( $table , $field ) {
if ( is_array ( $table ) ) {
2010-11-23 11:21:00 +00:00
throw new DBUnexpectedError ( $this , 'DatabaseOracle::fieldInfo called with table array!' );
2010-01-28 14:58:45 +00:00
}
2013-02-03 18:47:42 +00:00
return $this -> fieldInfoMulti ( $table , $field );
2010-01-28 14:58:45 +00:00
}
2012-08-29 19:32:47 +00:00
protected function doBegin ( $fname = 'DatabaseOracle::begin' ) {
2007-03-11 04:00:43 +00:00
$this -> mTrxLevel = 1 ;
2011-06-07 05:09:32 +00:00
$this -> doQuery ( 'SET CONSTRAINTS ALL DEFERRED' );
2007-03-11 04:00:43 +00:00
}
2009-12-11 18:23:24 +00:00
2012-08-29 19:32:47 +00:00
protected function doCommit ( $fname = 'DatabaseOracle::commit' ) {
2011-04-22 11:31:18 +00:00
if ( $this -> mTrxLevel ) {
2011-06-07 05:09:32 +00:00
$ret = oci_commit ( $this -> mConn );
if ( ! $ret ) {
throw new DBUnexpectedError ( $this , $this -> lastError () );
}
2011-04-22 11:31:18 +00:00
$this -> mTrxLevel = 0 ;
2011-06-07 05:09:32 +00:00
$this -> doQuery ( 'SET CONSTRAINTS ALL IMMEDIATE' );
2011-04-22 11:31:18 +00:00
}
}
2012-08-29 19:32:47 +00:00
protected function doRollback ( $fname = 'DatabaseOracle::rollback' ) {
2011-04-22 11:31:18 +00:00
if ( $this -> mTrxLevel ) {
oci_rollback ( $this -> mConn );
$this -> mTrxLevel = 0 ;
2011-06-07 05:09:32 +00:00
$this -> doQuery ( 'SET CONSTRAINTS ALL IMMEDIATE' );
2011-04-22 11:31:18 +00:00
}
2007-03-11 04:00:43 +00:00
}
2009-06-08 18:30:27 +00:00
/* defines must comply with ^define\s*([^\s=]*)\s*=\s?'\{\$([^\}]*)\}'; */
2012-02-02 15:12:28 +00:00
function sourceStream ( $fp , $lineCallback = false , $resultCallback = false ,
$fname = 'DatabaseOracle::sourceStream' , $inputCallback = 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 ;
2010-10-27 14:52:18 +00:00
$line = str_replace ( '/*$mw$*/' , '' , $line ); // remove dollarquotes
2009-06-08 18:30:27 +00:00
$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 ) {
2011-01-10 19:22:27 +00:00
$cmd = str_replace ( '&' . $scVar . '.' , '`{$' . $mwVar . '}`' , $cmd );
2009-06-08 18:30:27 +00:00
}
$cmd = $this -> replaceVars ( $cmd );
2012-02-02 15:12:28 +00:00
if ( $inputCallback ) {
call_user_func ( $inputCallback , $cmd );
}
2010-10-25 10:56:07 +00:00
$res = $this -> doQuery ( $cmd );
2009-06-08 18:30:27 +00:00
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 ;
}
2010-10-18 16:09:18 +00:00
function selectDB ( $db ) {
2011-01-27 08:25:48 +00:00
$this -> mDBname = $db ;
if ( $db == null || $db == $this -> mUser ) {
return true ;
}
2013-02-03 18:47:42 +00:00
$sql = 'ALTER SESSION SET CURRENT_SCHEMA=' . strtoupper ( $db );
2010-10-19 06:25:12 +00:00
$stmt = oci_parse ( $this -> mConn , $sql );
2011-01-27 08:25:48 +00:00
wfSuppressWarnings ();
$success = oci_execute ( $stmt );
wfRestoreWarnings ();
if ( ! $success ) {
2010-10-18 16:09:18 +00:00
$e = oci_error ( $stmt );
if ( $e [ 'code' ] != '1435' ) {
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], $sql , __METHOD__ );
}
return false ;
}
return true ;
}
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 ) {
2010-07-22 04:00:39 +00:00
global $wgContLang ;
if ( isset ( $wgContLang -> mLoaded ) && $wgContLang -> mLoaded ) {
$s = $wgContLang -> 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
}
2011-01-10 19:22:27 +00:00
public function addIdentifierQuotes ( $s ) {
2011-04-15 10:48:02 +00:00
if ( ! $this -> getFlag ( DBO_DDLMODE ) ) {
$s = '/*Q*/' . $s ;
2011-01-10 19:22:27 +00:00
}
return $s ;
}
2011-04-15 10:48:02 +00:00
public function removeIdentifierQuotes ( $s ) {
2013-02-09 20:10:44 +00:00
return strpos ( $s , '/*Q*/' ) === false ? $s : substr ( $s , 5 );
2011-04-15 10:48:02 +00:00
}
public function isQuotedIdentifier ( $s ) {
2013-02-09 20:10:44 +00:00
return strpos ( $s , '/*Q*/' ) !== false ;
2011-04-15 10:48:02 +00:00
}
2011-06-01 11:38:25 +00:00
private function wrapFieldForWhere ( $table , & $col , & $val ) {
2010-07-22 04:00:39 +00:00
global $wgContLang ;
2011-06-17 16:03:52 +00:00
2011-06-01 11:38:25 +00:00
$col_info = $this -> fieldInfoMulti ( $table , $col );
$col_type = $col_info != false ? $col_info -> type () : 'CONSTANT' ;
if ( $col_type == 'CLOB' ) {
$col = 'TO_CHAR(' . $col . ')' ;
$val = $wgContLang -> checkTitleEncoding ( $val );
2012-11-16 12:52:55 +00:00
} elseif ( $col_type == 'VARCHAR2' ) {
2011-06-01 11:38:25 +00:00
$val = $wgContLang -> checkTitleEncoding ( $val );
}
}
2009-11-05 20:04:47 +00:00
2013-03-18 19:44:43 +00:00
private function wrapConditionsForWhere ( $table , $conds , $parentCol = null ) {
2011-06-01 11:38:25 +00:00
$conds2 = array ();
foreach ( $conds as $col => $val ) {
if ( is_array ( $val ) ) {
2013-03-24 10:01:51 +00:00
$conds2 [ $col ] = $this -> wrapConditionsForWhere ( $table , $val , $col );
2011-06-01 11:38:25 +00:00
} else {
if ( is_numeric ( $col ) && $parentCol != null ) {
2013-03-24 10:01:51 +00:00
$this -> wrapFieldForWhere ( $table , $parentCol , $val );
2011-01-10 19:22:27 +00:00
} else {
2013-03-24 10:01:51 +00:00
$this -> wrapFieldForWhere ( $table , $col , $val );
2011-01-10 19:22:27 +00:00
}
2011-06-01 11:38:25 +00:00
$conds2 [ $col ] = $val ;
2009-11-06 17:12:18 +00:00
}
2011-06-01 11:38:25 +00:00
}
return $conds2 ;
}
2011-01-10 19:22:27 +00:00
2011-06-01 11:38:25 +00:00
function selectRow ( $table , $vars , $conds , $fname = 'DatabaseOracle::selectRow' , $options = array (), $join_conds = array () ) {
2013-02-03 18:47:42 +00:00
if ( is_array ( $conds ) ) {
2011-06-01 11:38:25 +00:00
$conds = $this -> wrapConditionsForWhere ( $table , $conds );
2009-11-05 20:04:47 +00:00
}
2011-06-01 11:38:25 +00:00
return parent :: selectRow ( $table , $vars , $conds , $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
*
2013-03-11 17:15:01 +00:00
* @ param array $options 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 ;
}
}
2013-01-26 09:43:20 +00:00
$preLimitTail .= $this -> makeGroupByWithHaving ( $options );
2012-12-31 14:12:11 +00:00
2013-01-26 09:43:20 +00:00
$preLimitTail .= $this -> makeOrderBy ( $options );
2012-12-31 14:12:11 +00:00
if ( isset ( $noKeyOptions [ 'FOR UPDATE' ] ) ) {
$postLimitTail .= ' FOR UPDATE' ;
2009-12-11 18:23:24 +00:00
}
2008-04-14 07:45:50 +00:00
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
}
2013-02-03 18:47:42 +00:00
2009-11-03 14:32:34 +00:00
public function delete ( $table , $conds , $fname = 'DatabaseOracle::delete' ) {
2013-02-03 18:47:42 +00:00
if ( is_array ( $conds ) ) {
2011-06-01 11:38:25 +00:00
$conds = $this -> wrapConditionsForWhere ( $table , $conds );
2009-12-11 18:23:24 +00:00
}
2011-09-02 10:42:08 +00:00
// a hack for deleting pages, users and images (which have non-nullable FKs)
// all deletions on these tables have transactions so final failure rollbacks these updates
$table = $this -> tableName ( $table );
2013-02-03 18:47:42 +00:00
if ( $table == $this -> tableName ( 'user' ) ) {
2011-09-02 10:42:08 +00:00
$this -> update ( 'archive' , array ( 'ar_user' => 0 ), array ( 'ar_user' => $conds [ 'user_id' ] ), $fname );
$this -> update ( 'ipblocks' , array ( 'ipb_user' => 0 ), array ( 'ipb_user' => $conds [ 'user_id' ] ), $fname );
$this -> update ( 'image' , array ( 'img_user' => 0 ), array ( 'img_user' => $conds [ 'user_id' ] ), $fname );
$this -> update ( 'oldimage' , array ( 'oi_user' => 0 ), array ( 'oi_user' => $conds [ 'user_id' ] ), $fname );
$this -> update ( 'filearchive' , array ( 'fa_deleted_user' => 0 ), array ( 'fa_deleted_user' => $conds [ 'user_id' ] ), $fname );
$this -> update ( 'filearchive' , array ( 'fa_user' => 0 ), array ( 'fa_user' => $conds [ 'user_id' ] ), $fname );
$this -> update ( 'uploadstash' , array ( 'us_user' => 0 ), array ( 'us_user' => $conds [ 'user_id' ] ), $fname );
$this -> update ( 'recentchanges' , array ( 'rc_user' => 0 ), array ( 'rc_user' => $conds [ 'user_id' ] ), $fname );
$this -> update ( 'logging' , array ( 'log_user' => 0 ), array ( 'log_user' => $conds [ 'user_id' ] ), $fname );
2013-02-03 18:47:42 +00:00
} elseif ( $table == $this -> tableName ( 'image' ) ) {
2011-09-02 10:42:08 +00:00
$this -> update ( 'oldimage' , array ( 'oi_name' => 0 ), array ( 'oi_name' => $conds [ 'img_name' ] ), $fname );
}
2011-06-01 11:38:25 +00:00
return parent :: delete ( $table , $conds , $fname );
2009-06-05 11:45:32 +00:00
}
2009-06-13 06:31:38 +00:00
2010-10-25 10:56:07 +00:00
function update ( $table , $values , $conds , $fname = 'DatabaseOracle::update' , $options = array () ) {
2010-10-25 16:49:59 +00:00
global $wgContLang ;
2011-06-17 16:03:52 +00:00
2011-12-02 00:29:46 +00:00
$table = $this -> tableName ( $table );
2010-10-25 10:56:07 +00:00
$opts = $this -> makeUpdateOptions ( $options );
$sql = " UPDATE $opts $table SET " ;
2011-06-17 16:03:52 +00:00
2010-10-25 10:56:07 +00:00
$first = true ;
foreach ( $values as $col => & $val ) {
$sqlSet = $this -> fieldBindStatement ( $table , $col , $val , true );
2011-06-17 16:03:52 +00:00
2010-10-25 10:56:07 +00:00
if ( ! $first ) {
$sqlSet = ', ' . $sqlSet ;
} else {
$first = false ;
}
$sql .= $sqlSet ;
}
2011-08-25 17:47:33 +00:00
if ( $conds !== array () && $conds !== '*' ) {
2011-06-01 11:38:25 +00:00
$conds = $this -> wrapConditionsForWhere ( $table , $conds );
2010-10-25 10:56:07 +00:00
$sql .= ' WHERE ' . $this -> makeList ( $conds , LIST_AND );
}
if ( ( $this -> mLastResult = $stmt = oci_parse ( $this -> mConn , $sql ) ) === false ) {
$e = oci_error ( $this -> mConn );
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], $sql , __METHOD__ );
return false ;
}
foreach ( $values as $col => & $val ) {
$col_info = $this -> fieldInfoMulti ( $table , $col );
$col_type = $col_info != false ? $col_info -> type () : 'CONSTANT' ;
if ( $val === null ) {
// do nothing ... null was inserted in statement creation
} elseif ( $col_type != 'BLOB' && $col_type != 'CLOB' ) {
if ( is_object ( $val ) ) {
$val = $val -> getData ();
}
if ( preg_match ( '/^timestamp.*/i' , $col_type ) == 1 && strtolower ( $val ) == 'infinity' ) {
$val = '31-12-2030 12:00:00.000000' ;
}
$val = ( $wgContLang != null ) ? $wgContLang -> checkTitleEncoding ( $val ) : $val ;
if ( oci_bind_by_name ( $stmt , " : $col " , $val ) === false ) {
$e = oci_error ( $stmt );
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], $sql , __METHOD__ );
return false ;
}
} else {
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' ] );
}
2011-06-17 16:03:52 +00:00
if ( $col_type == 'BLOB' ) {
$lob [ $col ] -> writeTemporary ( $val );
2010-10-25 10:56:07 +00:00
oci_bind_by_name ( $stmt , " : $col " , $lob [ $col ], - 1 , SQLT_BLOB );
} else {
$lob [ $col ] -> writeTemporary ( $val );
oci_bind_by_name ( $stmt , " : $col " , $lob [ $col ], - 1 , OCI_B_CLOB );
}
}
}
wfSuppressWarnings ();
2011-04-22 11:31:18 +00:00
if ( oci_execute ( $stmt , $this -> execFlags () ) === false ) {
2010-10-25 10:56:07 +00:00
$e = oci_error ( $stmt );
if ( ! $this -> ignore_DUP_VAL_ON_INDEX || $e [ 'code' ] != '1' ) {
$this -> reportQueryError ( $e [ 'message' ], $e [ 'code' ], $sql , __METHOD__ );
return false ;
} else {
$this -> mAffectedRows = oci_num_rows ( $stmt );
}
} else {
$this -> mAffectedRows = oci_num_rows ( $stmt );
}
wfRestoreWarnings ();
if ( isset ( $lob ) ) {
foreach ( $lob as $lob_v ) {
$lob_v -> free ();
}
}
if ( ! $this -> mTrxLevel ) {
oci_commit ( $this -> mConn );
}
oci_free_statement ( $stmt );
}
2009-12-10 23:22:34 +00:00
function bitNot ( $field ) {
// expecting bit-fields smaller than 4bytes
2010-08-18 10:09:03 +00:00
return 'BITNOT(' . $field . ')' ;
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
2011-08-25 17:48:55 +00:00
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
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
}
2011-11-10 20:39:23 +00:00
2011-11-10 07:41:12 +00:00
public function getInfinity () {
return '31-12-2030 12:00:00.000000' ;
}
2011-11-10 20:39:23 +00:00
2007-03-11 04:00:43 +00:00
} // end DatabaseOracle class