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
|
|
|
*/
|
2017-02-07 04:49:57 +00:00
|
|
|
|
|
|
|
|
use Wikimedia\Rdbms\Database;
|
2017-02-07 17:36:12 +00:00
|
|
|
use Wikimedia\Rdbms\Blob;
|
2017-02-19 05:03:13 +00:00
|
|
|
use Wikimedia\Rdbms\ResultWrapper;
|
2017-02-24 16:17:16 +00:00
|
|
|
use Wikimedia\Rdbms\DBConnectionError;
|
|
|
|
|
use Wikimedia\Rdbms\DBUnexpectedError;
|
2007-03-11 04:00:43 +00:00
|
|
|
|
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
|
|
|
*/
|
2016-12-02 19:18:27 +00:00
|
|
|
class DatabaseOracle extends Database {
|
2013-12-27 00:29:37 +00:00
|
|
|
/** @var resource */
|
|
|
|
|
protected $mLastResult = null;
|
2007-03-11 04:00:43 +00:00
|
|
|
|
2013-12-27 00:29:37 +00:00
|
|
|
/** @var int The number of rows affected as an integer */
|
|
|
|
|
protected $mAffectedRows;
|
2009-06-05 11:45:32 +00:00
|
|
|
|
2013-12-27 00:29:37 +00:00
|
|
|
/** @var bool */
|
|
|
|
|
private $ignoreDupValOnIndex = false;
|
|
|
|
|
|
|
|
|
|
/** @var bool|array */
|
|
|
|
|
private $sequenceData = null;
|
|
|
|
|
|
|
|
|
|
/** @var string Character set for Oracle database */
|
|
|
|
|
private $defaultCharset = 'AL32UTF8';
|
|
|
|
|
|
|
|
|
|
/** @var array */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mFieldInfoCache = [];
|
2010-01-05 13:35:19 +00:00
|
|
|
|
2015-02-20 22:10:26 +00:00
|
|
|
function __construct( array $p ) {
|
2011-04-12 20:56:35 +00:00
|
|
|
global $wgDBprefix;
|
2013-10-18 20:05:08 +00:00
|
|
|
|
|
|
|
|
if ( $p['tablePrefix'] == 'get from global' ) {
|
|
|
|
|
$p['tablePrefix'] = $wgDBprefix;
|
|
|
|
|
}
|
|
|
|
|
$p['tablePrefix'] = strtoupper( $p['tablePrefix'] );
|
|
|
|
|
parent::__construct( $p );
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'DatabaseOraclePostInit', [ $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 ) {
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\suppressWarnings();
|
2011-04-28 12:44:19 +00:00
|
|
|
$this->close();
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\restoreWarnings();
|
2011-04-28 12:44:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-08 00:31:24 +00:00
|
|
|
function getType() {
|
|
|
|
|
return 'oracle';
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-11 04:00:43 +00:00
|
|
|
function implicitGroupby() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2007-09-02 18:03:10 +00:00
|
|
|
function implicitOrderby() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2007-03-11 04:00:43 +00:00
|
|
|
/**
|
|
|
|
|
* 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
|
2016-09-15 02:04:21 +00:00
|
|
|
* @return resource|null
|
2007-03-11 04:00:43 +00:00
|
|
|
*/
|
|
|
|
|
function open( $server, $user, $password, $dbName ) {
|
2013-05-24 14:05:20 +00:00
|
|
|
global $wgDBOracleDRCP;
|
2007-03-11 04:00:43 +00:00
|
|
|
if ( !function_exists( 'oci_connect' ) ) {
|
2013-11-20 10:13:51 +00:00
|
|
|
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\n " .
|
|
|
|
|
"and database)\n" );
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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
|
2013-12-27 16:59:39 +00:00
|
|
|
return null;
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 14:05:20 +00:00
|
|
|
if ( $wgDBOracleDRCP ) {
|
|
|
|
|
$this->setFlag( DBO_PERSISTENT );
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-08 18:30:27 +00:00
|
|
|
$session_mode = $this->mFlags & DBO_SYSDBA ? OCI_SYSDBA : OCI_DEFAULT;
|
2013-05-24 14:05:20 +00:00
|
|
|
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\suppressWarnings();
|
2013-05-24 14:05:20 +00:00
|
|
|
if ( $this->mFlags & DBO_PERSISTENT ) {
|
2013-11-20 10:13:51 +00:00
|
|
|
$this->mConn = oci_pconnect(
|
|
|
|
|
$this->mUser,
|
|
|
|
|
$this->mPassword,
|
|
|
|
|
$this->mServer,
|
|
|
|
|
$this->defaultCharset,
|
|
|
|
|
$session_mode
|
|
|
|
|
);
|
2013-08-24 15:06:25 +00:00
|
|
|
} elseif ( $this->mFlags & DBO_DEFAULT ) {
|
2013-11-20 10:13:51 +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 {
|
2013-11-20 10:13:51 +00:00
|
|
|
$this->mConn = oci_connect(
|
|
|
|
|
$this->mUser,
|
|
|
|
|
$this->mPassword,
|
|
|
|
|
$this->mServer,
|
|
|
|
|
$this->defaultCharset,
|
|
|
|
|
$session_mode
|
|
|
|
|
);
|
2010-10-18 16:09:18 +00:00
|
|
|
}
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\restoreWarnings();
|
2010-10-18 16:09:18 +00:00
|
|
|
|
|
|
|
|
if ( $this->mUser != $this->mDBname ) {
|
2015-09-11 13:44:59 +00:00
|
|
|
// change current schema in session
|
2010-10-18 16:09:18 +00:00
|
|
|
$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=\'.,\'' );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
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 ) ) {
|
2016-09-14 02:38:19 +00:00
|
|
|
throw new InvalidArgumentException( "SQL encoding is invalid\n$sql" );
|
2010-02-20 19:22:27 +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
|
2013-04-20 20:28:52 +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
|
2013-07-06 19:59:35 +00:00
|
|
|
$explain_id = MWTimestamp::getLocalInstance()->format( 'dmYHis' );
|
2009-12-10 23:22:34 +00:00
|
|
|
|
2013-11-20 10:13:51 +00:00
|
|
|
$sql = preg_replace(
|
|
|
|
|
'/^EXPLAIN /',
|
|
|
|
|
'EXPLAIN PLAN SET STATEMENT_ID = \'' . $explain_id . '\' FOR',
|
|
|
|
|
$sql,
|
|
|
|
|
1,
|
|
|
|
|
$explain_count
|
|
|
|
|
);
|
2010-01-05 13:35:19 +00:00
|
|
|
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\suppressWarnings();
|
2010-01-05 13:35:19 +00:00
|
|
|
|
2015-11-18 18:32:05 +00:00
|
|
|
$this->mLastResult = $stmt = oci_parse( $this->mConn, $sql );
|
|
|
|
|
if ( $stmt === false ) {
|
2009-12-10 23:22:34 +00:00
|
|
|
$e = oci_error( $this->mConn );
|
2010-10-02 08:04:58 +00:00
|
|
|
$this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
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 );
|
2013-12-27 00:29:37 +00:00
|
|
|
if ( !$this->ignoreDupValOnIndex || $e['code'] != '1' ) {
|
2010-10-02 08:04:58 +00:00
|
|
|
$this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
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
|
|
|
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\restoreWarnings();
|
2009-06-05 11:45:32 +00:00
|
|
|
|
2009-12-10 23:22:34 +00:00
|
|
|
if ( $explain_count > 0 ) {
|
2013-11-20 10:13:51 +00:00
|
|
|
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 );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2013-12-27 01:54:51 +00:00
|
|
|
/**
|
|
|
|
|
* Frees resources associated with the LOB descriptor
|
2016-07-01 00:08:44 +00:00
|
|
|
* @param ResultWrapper|ORAResult $res
|
2013-12-27 01:54:51 +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
|
|
|
}
|
|
|
|
|
|
2013-12-27 01:54:51 +00:00
|
|
|
/**
|
2016-07-01 00:08:44 +00:00
|
|
|
* @param ResultWrapper|ORAResult $res
|
2013-12-27 01:54:51 +00:00
|
|
|
* @return mixed
|
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
2016-07-01 00:08:44 +00:00
|
|
|
/**
|
|
|
|
|
* @param ResultWrapper|ORAResult $res
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
2016-07-01 00:08:44 +00:00
|
|
|
/**
|
|
|
|
|
* @param ResultWrapper|ORAResult $res
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
2016-07-01 00:08:44 +00:00
|
|
|
/**
|
|
|
|
|
* @param ResultWrapper|ORAResult $res
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function insertId() {
|
2017-08-31 00:27:51 +00:00
|
|
|
$res = $this->query( "SELECT lastval_pkg.getLastval FROM dual" );
|
|
|
|
|
$row = $this->fetchRow( $res );
|
|
|
|
|
return is_null( $row[0] ) ? null : (int)$row[0];
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-27 01:54:51 +00:00
|
|
|
/**
|
|
|
|
|
* @param mixed $res
|
|
|
|
|
* @param int $row
|
|
|
|
|
*/
|
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
|
|
|
}
|
2013-11-20 06:58:22 +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
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2007-03-11 04:00:43 +00:00
|
|
|
return $e['code'];
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-28 14:10:39 +00:00
|
|
|
protected function fetchAffectedRowCount() {
|
2007-03-11 04:00:43 +00:00
|
|
|
return $this->mAffectedRows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns information about an index
|
|
|
|
|
* If errors are explicitly ignored, returns NULL on failure
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param string $table
|
|
|
|
|
* @param string $index
|
|
|
|
|
* @param string $fname
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool
|
2007-03-11 04:00:43 +00:00
|
|
|
*/
|
2013-05-06 13:20:40 +00:00
|
|
|
function indexInfo( $table, $index, $fname = __METHOD__ ) {
|
2007-03-11 04:00:43 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 13:20:40 +00:00
|
|
|
function indexUnique( $table, $index, $fname = __METHOD__ ) {
|
2007-03-11 04:00:43 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
function insert( $table, $a, $fname = __METHOD__, $options = [] ) {
|
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 ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$options = [ $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 ) ) {
|
2013-12-27 00:29:37 +00:00
|
|
|
$this->ignoreDupValOnIndex = 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 ) ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$a = [ $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 ) ) {
|
2013-12-27 00:29:37 +00:00
|
|
|
$this->ignoreDupValOnIndex = 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;
|
2013-11-20 06:58:22 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-27 01:54:51 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $table
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param array $row
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param string $fname
|
|
|
|
|
* @return bool
|
|
|
|
|
* @throws DBUnexpectedError
|
|
|
|
|
*/
|
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)"
|
2016-03-08 08:13:12 +00:00
|
|
|
$sql = "INSERT INTO " . $table . " (" . implode( ',', 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
|
|
|
}
|
2014-02-04 18:35:10 +00:00
|
|
|
if ( $this->isQuotedIdentifier( $val ) ) {
|
|
|
|
|
$sql .= $this->removeIdentifierQuotes( $val );
|
|
|
|
|
unset( $row[$col] );
|
|
|
|
|
} else {
|
|
|
|
|
$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
|
|
|
|
2015-11-18 18:32:05 +00:00
|
|
|
$this->mLastResult = $stmt = oci_parse( $this->mConn, $sql );
|
|
|
|
|
if ( $stmt === false ) {
|
2010-10-25 10:56:07 +00:00
|
|
|
$e = oci_error( $this->mConn );
|
|
|
|
|
$this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2010-10-25 10:56:07 +00:00
|
|
|
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__ );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
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 {
|
2013-12-27 01:54:51 +00:00
|
|
|
/** @var OCI_Lob[] $lob */
|
2015-11-18 18:32:05 +00:00
|
|
|
$lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB );
|
|
|
|
|
if ( $lob[$col] === false ) {
|
2009-12-10 23:22:34 +00:00
|
|
|
$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 );
|
2013-11-20 06:58:22 +00:00
|
|
|
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 );
|
2013-11-20 06:58:22 +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
|
|
|
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\suppressWarnings();
|
2010-01-17 20:42:54 +00:00
|
|
|
|
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 );
|
2013-12-27 00:29:37 +00:00
|
|
|
if ( !$this->ignoreDupValOnIndex || $e['code'] != '1' ) {
|
2009-12-10 23:22:34 +00:00
|
|
|
$this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
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
|
|
|
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\restoreWarnings();
|
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
|
|
|
}
|
|
|
|
|
|
2014-01-06 18:32:50 +00:00
|
|
|
return oci_free_statement( $stmt );
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2016-08-27 17:10:46 +00:00
|
|
|
function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
|
2017-06-09 16:58:09 +00:00
|
|
|
$insertOptions = [], $selectOptions = [], $selectJoinConds = []
|
2013-11-20 06:58:22 +00:00
|
|
|
) {
|
2009-06-05 11:45:32 +00:00
|
|
|
$destTable = $this->tableName( $destTable );
|
2010-01-05 13:35:19 +00:00
|
|
|
|
2015-11-18 18:32:05 +00:00
|
|
|
$sequenceData = $this->getSequenceData( $destTable );
|
|
|
|
|
if ( $sequenceData !== false &&
|
2013-11-20 06:58:22 +00:00
|
|
|
!isset( $varMap[$sequenceData['column']] )
|
|
|
|
|
) {
|
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
|
|
|
|
2017-06-09 16:58:09 +00:00
|
|
|
$selectSql = $this->selectSQLText(
|
|
|
|
|
$srcTable,
|
|
|
|
|
array_values( $varMap ),
|
|
|
|
|
$conds,
|
|
|
|
|
$fname,
|
|
|
|
|
$selectOptions,
|
|
|
|
|
$selectJoinConds
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ') ' . $selectSql;
|
2010-01-05 13:35:19 +00:00
|
|
|
|
2009-12-11 18:23:24 +00:00
|
|
|
if ( in_array( 'IGNORE', $insertOptions ) ) {
|
2013-12-27 00:29:37 +00:00
|
|
|
$this->ignoreDupValOnIndex = 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 ) ) {
|
2013-12-27 00:29:37 +00:00
|
|
|
$this->ignoreDupValOnIndex = false;
|
2009-12-11 18:23:24 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-05 11:45:32 +00:00
|
|
|
return $retval;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 18:35:10 +00:00
|
|
|
public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
|
|
|
|
|
$fname = __METHOD__
|
|
|
|
|
) {
|
|
|
|
|
if ( !count( $rows ) ) {
|
|
|
|
|
return true; // nothing to do
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !is_array( reset( $rows ) ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$rows = [ $rows ];
|
2014-02-04 18:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sequenceData = $this->getSequenceData( $table );
|
|
|
|
|
if ( $sequenceData !== false ) {
|
|
|
|
|
// add sequence column to each list of columns, when not set
|
|
|
|
|
foreach ( $rows as &$row ) {
|
|
|
|
|
if ( !isset( $row[$sequenceData['column']] ) ) {
|
2014-03-12 17:25:15 +00:00
|
|
|
$row[$sequenceData['column']] =
|
|
|
|
|
$this->addIdentifierQuotes( 'GET_SEQUENCE_VALUE(\'' .
|
|
|
|
|
$sequenceData['sequence'] . '\')' );
|
2014-02-04 18:35:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent::upsert( $table, $rows, $uniqueIndexes, $set, $fname );
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
2013-04-26 14:42:31 +00:00
|
|
|
switch ( $name ) {
|
2007-03-11 04:00:43 +00:00
|
|
|
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
|
|
|
|
2013-05-26 14:49:28 +00:00
|
|
|
return strtoupper( parent::tableName( $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 );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2013-04-27 12:02:08 +00:00
|
|
|
return preg_replace( '/.*\.(.*)/', '$1', $name );
|
2011-05-04 10:43:34 +00:00
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2009-10-28 19:15:19 +00:00
|
|
|
/**
|
|
|
|
|
* Return sequence_name if table has a sequence
|
2013-12-27 00:29:37 +00:00
|
|
|
*
|
|
|
|
|
* @param string $table
|
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),
|
2013-11-20 10:13:51 +00:00
|
|
|
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
|
|
|
|
|
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 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->sequenceData[$row[1]] = [
|
2009-12-11 18:23:24 +00:00
|
|
|
'sequence' => $row[0],
|
|
|
|
|
'column' => $row[2]
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2009-12-11 18:23:24 +00:00
|
|
|
}
|
2009-10-28 19:15:19 +00:00
|
|
|
}
|
2011-06-07 05:09:32 +00:00
|
|
|
$table = strtolower( $this->removeIdentifierQuotes( $this->tableName( $table ) ) );
|
2013-11-20 06:58:22 +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
|
|
|
|
2013-12-27 01:54:51 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the size of a text field, or -1 for "unlimited"
|
|
|
|
|
*
|
|
|
|
|
* @param string $table
|
|
|
|
|
* @param string $field
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2007-03-11 04:00:43 +00:00
|
|
|
function textFieldSize( $table, $field ) {
|
2011-02-18 22:58:02 +00:00
|
|
|
$fieldInfoData = $this->fieldInfo( $table, $field );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
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
|
|
|
}
|
2013-11-20 06:58:22 +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();
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2010-11-09 08:56:15 +00:00
|
|
|
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-11-20 06:58:22 +00:00
|
|
|
|
2013-11-20 10:13:51 +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';
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-20 10:13:51 +00:00
|
|
|
function duplicateTableStructure( $oldName, $newName, $temporary = false,
|
|
|
|
|
$fname = __METHOD__
|
|
|
|
|
) {
|
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
|
|
|
|
2013-11-20 10:13:51 +00:00
|
|
|
return $this->doQuery( "BEGIN DUPLICATE_TABLE( '$tabName', " .
|
|
|
|
|
"'$oldPrefix', '$newPrefix', $temporary ); END;" );
|
2009-11-06 17:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-06 13:20:40 +00:00
|
|
|
function listTables( $prefix = null, $fname = __METHOD__ ) {
|
2011-01-10 19:22:27 +00:00
|
|
|
$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 );
|
2013-11-20 10:13:51 +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
|
2016-02-17 09:09:32 +00:00
|
|
|
$endArray = [];
|
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-04-20 20:28:52 +00:00
|
|
|
if ( !in_array( $row['table_name'], $fixedOrderTabs ) ) {
|
2011-01-10 19:22:27 +00:00
|
|
|
$endArray[] = $row['table_name'];
|
2013-04-20 20:28:52 +00:00
|
|
|
}
|
2011-01-10 19:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $endArray;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 13:20:40 +00:00
|
|
|
public function dropTable( $tableName, $fName = __METHOD__ ) {
|
2013-02-03 18:47:42 +00:00
|
|
|
$tableName = $this->tableName( $tableName );
|
2013-04-20 20:28:52 +00:00
|
|
|
if ( !$this->tableExists( $tableName ) ) {
|
2011-01-10 19:22:27 +00:00
|
|
|
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
|
2013-12-27 01:54:51 +00:00
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param array $valuedata
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param string $valuename
|
|
|
|
|
* @return mixed
|
2007-03-11 04:00:43 +00:00
|
|
|
*/
|
2012-07-16 17:56:00 +00:00
|
|
|
public function aggregateValue( $valuedata, $valuename = 'value' ) {
|
2007-03-11 04:00:43 +00:00
|
|
|
return $valuedata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-07-24 17:42:45 +00:00
|
|
|
* @return string Wikitext of a link to the server software's web site
|
2007-03-11 04:00:43 +00:00
|
|
|
*/
|
2013-05-15 04:13:02 +00:00
|
|
|
public function getSoftwareLink() {
|
2014-01-09 01:50:21 +00:00
|
|
|
return '[{{int:version-db-oracle-url}} Oracle]';
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string Version information from the database
|
|
|
|
|
*/
|
|
|
|
|
function getServerVersion() {
|
2015-09-11 13:44:59 +00:00
|
|
|
// better version number, fallback on driver
|
2013-11-20 10:13:51 +00:00
|
|
|
$rset = $this->doQuery(
|
|
|
|
|
'SELECT version FROM product_component_version ' .
|
|
|
|
|
'WHERE UPPER(product) LIKE \'ORACLE DATABASE%\''
|
|
|
|
|
);
|
2015-11-18 18:32:05 +00:00
|
|
|
$row = $rset->fetchRow();
|
|
|
|
|
if ( !$row ) {
|
2010-10-19 06:25:12 +00:00
|
|
|
return oci_server_version( $this->mConn );
|
2011-06-17 16:03:52 +00:00
|
|
|
}
|
2013-11-20 06:58:22 +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
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param string $table
|
|
|
|
|
* @param string $index
|
|
|
|
|
* @param string $fname
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool
|
2011-06-01 08:27:51 +00:00
|
|
|
*/
|
2013-05-06 13:20:40 +00:00
|
|
|
function indexExists( $table, $index, $fname = __METHOD__ ) {
|
2011-06-01 08:27:51 +00:00
|
|
|
$table = $this->tableName( $table );
|
|
|
|
|
$table = strtoupper( $this->removeIdentifierQuotes( $table ) );
|
|
|
|
|
$index = strtoupper( $index );
|
|
|
|
|
$owner = strtoupper( $this->mDBname );
|
2014-03-15 11:32:44 +00:00
|
|
|
$sql = "SELECT 1 FROM all_indexes WHERE owner='$owner' AND index_name='{$table}_{$index}'";
|
|
|
|
|
$res = $this->doQuery( $sql );
|
2011-06-01 08:27:51 +00:00
|
|
|
if ( $res ) {
|
|
|
|
|
$count = $res->numRows();
|
|
|
|
|
$res->free();
|
|
|
|
|
} else {
|
|
|
|
|
$count = 0;
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2011-06-01 08:27:51 +00:00
|
|
|
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)
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param string $table
|
|
|
|
|
* @param string $fname
|
2013-05-26 14:49:28 +00:00
|
|
|
* @return bool
|
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 ) );
|
2014-03-15 11:32:44 +00:00
|
|
|
$sql = "SELECT 1 FROM all_tables WHERE owner=$owner AND table_name=$table";
|
|
|
|
|
$res = $this->doQuery( $sql );
|
2013-05-26 14:49:28 +00:00
|
|
|
if ( $res && $res->numRows() > 0 ) {
|
|
|
|
|
$exists = true;
|
2009-06-05 11:45:32 +00:00
|
|
|
} else {
|
2013-05-26 14:49:28 +00:00
|
|
|
$exists = false;
|
2009-06-05 11:45:32 +00:00
|
|
|
}
|
2013-05-26 14:49:28 +00:00
|
|
|
|
|
|
|
|
$res->free();
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2013-05-26 14:49:28 +00:00
|
|
|
return $exists;
|
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
|
|
|
|
|
*
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param array|string $table
|
|
|
|
|
* @param string $field
|
2016-12-08 05:04:53 +00:00
|
|
|
* @return ORAField|ORAResult|false
|
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 ) ) {
|
2017-02-01 04:01:54 +00:00
|
|
|
$table = array_map( [ $this, 'tableNameInternal' ], $table );
|
2010-01-17 20:42:54 +00:00
|
|
|
$tableWhere = 'IN (';
|
2013-04-20 20:28:52 +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"];
|
|
|
|
|
}
|
2013-04-13 11:36:24 +00:00
|
|
|
$tableWhere = '= \'' . $table . '\'';
|
2009-12-11 18:23:24 +00:00
|
|
|
}
|
2009-06-05 11:45:32 +00:00
|
|
|
|
2013-11-20 10:13:51 +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__ );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
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 ) ) {
|
2013-04-20 20:28:52 +00:00
|
|
|
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();
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2010-10-25 10:56:07 +00:00
|
|
|
return $fieldInfoTemp;
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-30 17:41:19 +00:00
|
|
|
/**
|
|
|
|
|
* @throws DBUnexpectedError
|
2014-04-05 19:54:24 +00:00
|
|
|
* @param string $table
|
|
|
|
|
* @param string $field
|
2010-12-30 17:41:19 +00:00
|
|
|
* @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-11-20 06:58:22 +00:00
|
|
|
|
2013-02-03 18:47:42 +00:00
|
|
|
return $this->fieldInfoMulti( $table, $field );
|
2010-01-28 14:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-06 13:20:40 +00:00
|
|
|
protected function doBegin( $fname = __METHOD__ ) {
|
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
|
|
|
|
2013-05-06 13:20:40 +00:00
|
|
|
protected function doCommit( $fname = __METHOD__ ) {
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 13:20:40 +00:00
|
|
|
protected function doRollback( $fname = __METHOD__ ) {
|
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
|
|
|
}
|
|
|
|
|
|
2017-02-12 02:12:42 +00:00
|
|
|
function sourceStream(
|
|
|
|
|
$fp,
|
|
|
|
|
callable $lineCallback = null,
|
|
|
|
|
callable $resultCallback = null,
|
|
|
|
|
$fname = __METHOD__, callable $inputCallback = null
|
|
|
|
|
) {
|
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
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$replacements = [];
|
2017-02-12 02:12:42 +00:00
|
|
|
// Defines must comply with ^define\s*([^\s=]*)\s*=\s?'\{\$([^\}]*)\}';
|
2013-11-20 06:58:22 +00:00
|
|
|
while ( !feof( $fp ) ) {
|
2009-06-08 18:30:27 +00:00
|
|
|
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;
|
|
|
|
|
}
|
2013-11-23 18:22:03 +00:00
|
|
|
if ( '-' == $line[0] && '-' == $line[1] ) {
|
2009-12-11 18:23:24 +00:00
|
|
|
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 ) {
|
2013-11-23 18:22:03 +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();
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2009-06-08 18:30:27 +00:00
|
|
|
return "Query \"{$cmd}\" failed with error code \"$err\".\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cmd = '';
|
|
|
|
|
$done = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2009-06-08 18:30:27 +00:00
|
|
|
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 );
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\suppressWarnings();
|
2011-01-27 08:25:48 +00:00
|
|
|
$success = oci_execute( $stmt );
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\restoreWarnings();
|
2011-01-27 08:25:48 +00:00
|
|
|
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__ );
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2010-10-18 16:09:18 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2010-10-18 16:09:18 +00:00
|
|
|
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
|
|
|
}
|
2013-11-20 06:58:22 +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
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
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 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$conds2 = [];
|
2011-06-01 11:38:25 +00:00
|
|
|
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
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2011-06-01 11:38:25 +00:00
|
|
|
return $conds2;
|
|
|
|
|
}
|
2011-01-10 19:22:27 +00:00
|
|
|
|
2013-11-20 10:13:51 +00:00
|
|
|
function selectRow( $table, $vars, $conds, $fname = __METHOD__,
|
2016-02-17 09:09:32 +00:00
|
|
|
$options = [], $join_conds = []
|
2013-11-20 10:13:51 +00:00
|
|
|
) {
|
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
|
|
|
}
|
2013-11-20 06:58:22 +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
|
|
|
|
|
*
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param array $options An associative array of options to be turned into
|
|
|
|
|
* an SQL query, valid keys are listed in the function.
|
2007-03-11 04:00:43 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
function makeSelectOptions( $options ) {
|
2007-03-11 15:49:27 +00:00
|
|
|
$preLimitTail = $postLimitTail = '';
|
2007-03-11 04:00:43 +00:00
|
|
|
$startOpts = '';
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$noKeyOptions = [];
|
2007-03-11 04:00:43 +00:00
|
|
|
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
|
|
|
|
2013-11-20 06:58:22 +00:00
|
|
|
if ( isset( $options['USE INDEX'] ) && !is_array( $options['USE INDEX'] ) ) {
|
2007-03-11 04:00:43 +00:00
|
|
|
$useIndex = $this->useIndexClause( $options['USE INDEX'] );
|
|
|
|
|
} else {
|
|
|
|
|
$useIndex = '';
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2016-07-04 10:56:40 +00:00
|
|
|
if ( isset( $options['IGNORE INDEX'] ) && !is_array( $options['IGNORE INDEX'] ) ) {
|
|
|
|
|
$ignoreIndex = $this->ignoreIndexClause( $options['IGNORE INDEX'] );
|
|
|
|
|
} else {
|
|
|
|
|
$ignoreIndex = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [ $startOpts, $useIndex, $preLimitTail, $postLimitTail, $ignoreIndex ];
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
2013-02-03 18:47:42 +00:00
|
|
|
|
2013-05-06 13:20:40 +00:00
|
|
|
public function delete( $table, $conds, $fname = __METHOD__ ) {
|
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' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->update( 'archive', [ 'ar_user' => 0 ],
|
|
|
|
|
[ 'ar_user' => $conds['user_id'] ], $fname );
|
|
|
|
|
$this->update( 'ipblocks', [ 'ipb_user' => 0 ],
|
|
|
|
|
[ 'ipb_user' => $conds['user_id'] ], $fname );
|
|
|
|
|
$this->update( 'image', [ 'img_user' => 0 ],
|
|
|
|
|
[ 'img_user' => $conds['user_id'] ], $fname );
|
|
|
|
|
$this->update( 'oldimage', [ 'oi_user' => 0 ],
|
|
|
|
|
[ 'oi_user' => $conds['user_id'] ], $fname );
|
|
|
|
|
$this->update( 'filearchive', [ 'fa_deleted_user' => 0 ],
|
|
|
|
|
[ 'fa_deleted_user' => $conds['user_id'] ], $fname );
|
|
|
|
|
$this->update( 'filearchive', [ 'fa_user' => 0 ],
|
|
|
|
|
[ 'fa_user' => $conds['user_id'] ], $fname );
|
|
|
|
|
$this->update( 'uploadstash', [ 'us_user' => 0 ],
|
|
|
|
|
[ 'us_user' => $conds['user_id'] ], $fname );
|
|
|
|
|
$this->update( 'recentchanges', [ 'rc_user' => 0 ],
|
|
|
|
|
[ 'rc_user' => $conds['user_id'] ], $fname );
|
|
|
|
|
$this->update( 'logging', [ 'log_user' => 0 ],
|
|
|
|
|
[ 'log_user' => $conds['user_id'] ], $fname );
|
2013-02-03 18:47:42 +00:00
|
|
|
} elseif ( $table == $this->tableName( 'image' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->update( 'oldimage', [ 'oi_name' => 0 ],
|
|
|
|
|
[ 'oi_name' => $conds['img_name'] ], $fname );
|
2011-09-02 10:42:08 +00:00
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
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
|
|
|
|
2013-12-27 01:54:51 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $table
|
|
|
|
|
* @param array $values
|
|
|
|
|
* @param array $conds
|
|
|
|
|
* @param string $fname
|
|
|
|
|
* @param array $options
|
|
|
|
|
* @return bool
|
|
|
|
|
* @throws DBUnexpectedError
|
|
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
function update( $table, $values, $conds, $fname = __METHOD__, $options = [] ) {
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( $conds !== [] && $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 );
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-18 18:32:05 +00:00
|
|
|
$this->mLastResult = $stmt = oci_parse( $this->mConn, $sql );
|
|
|
|
|
if ( $stmt === false ) {
|
2010-10-25 10:56:07 +00:00
|
|
|
$e = oci_error( $this->mConn );
|
|
|
|
|
$this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2010-10-25 10:56:07 +00:00
|
|
|
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__ );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2010-10-25 10:56:07 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2013-12-27 00:29:37 +00:00
|
|
|
/** @var OCI_Lob[] $lob */
|
2015-11-18 18:32:05 +00:00
|
|
|
$lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB );
|
|
|
|
|
if ( $lob[$col] === false ) {
|
2010-10-25 10:56:07 +00:00
|
|
|
$e = oci_error( $stmt );
|
|
|
|
|
throw new DBUnexpectedError( $this, "Cannot create LOB descriptor: " . $e['message'] );
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-15 05:52:24 +00:00
|
|
|
if ( is_object( $val ) ) {
|
|
|
|
|
$val = $val->getData();
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-17 16:03:52 +00:00
|
|
|
if ( $col_type == 'BLOB' ) {
|
|
|
|
|
$lob[$col]->writeTemporary( $val );
|
2013-11-20 06:58:22 +00:00
|
|
|
oci_bind_by_name( $stmt, ":$col", $lob[$col], -1, SQLT_BLOB );
|
2010-10-25 10:56:07 +00:00
|
|
|
} else {
|
|
|
|
|
$lob[$col]->writeTemporary( $val );
|
2013-11-20 06:58:22 +00:00
|
|
|
oci_bind_by_name( $stmt, ":$col", $lob[$col], -1, OCI_B_CLOB );
|
2010-10-25 10:56:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\suppressWarnings();
|
2010-10-25 10:56:07 +00:00
|
|
|
|
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 );
|
2013-12-27 00:29:37 +00:00
|
|
|
if ( !$this->ignoreDupValOnIndex || $e['code'] != '1' ) {
|
2010-10-25 10:56:07 +00:00
|
|
|
$this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2010-10-25 10:56:07 +00:00
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
$this->mAffectedRows = oci_num_rows( $stmt );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->mAffectedRows = oci_num_rows( $stmt );
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\restoreWarnings();
|
2010-10-25 10:56:07 +00:00
|
|
|
|
|
|
|
|
if ( isset( $lob ) ) {
|
|
|
|
|
foreach ( $lob as $lob_v ) {
|
|
|
|
|
$lob_v->free();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$this->mTrxLevel ) {
|
|
|
|
|
oci_commit( $this->mConn );
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 18:32:50 +00:00
|
|
|
return oci_free_statement( $stmt );
|
2010-10-25 10:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2013-11-15 07:23:36 +00:00
|
|
|
public function buildGroupConcatField(
|
2016-02-17 09:09:32 +00:00
|
|
|
$delim, $table, $field, $conds = '', $join_conds = []
|
2013-11-15 07:23:36 +00:00
|
|
|
) {
|
|
|
|
|
$fld = "LISTAGG($field," . $this->addQuotes( $delim ) . ") WITHIN GROUP (ORDER BY $field)";
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')';
|
2013-11-15 07:23:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-25 20:24:42 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $field Field or column to cast
|
|
|
|
|
* @return string
|
|
|
|
|
* @since 1.28
|
|
|
|
|
*/
|
|
|
|
|
public function buildStringCast( $field ) {
|
|
|
|
|
return 'CAST ( ' . $field . ' AS VARCHAR2 )';
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 07:41:12 +00:00
|
|
|
public function getInfinity() {
|
|
|
|
|
return '31-12-2030 12:00:00.000000';
|
|
|
|
|
}
|
2013-12-27 01:54:51 +00:00
|
|
|
}
|