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
|
|
|
|
2019-06-13 12:46:03 +00:00
|
|
|
use Wikimedia\AtEase\AtEase;
|
2019-04-09 23:31:34 +00:00
|
|
|
use Wikimedia\Timestamp\ConvertibleTimestamp;
|
2017-02-07 04:49:57 +00:00
|
|
|
use Wikimedia\Rdbms\Database;
|
2018-08-14 23:44:41 +00:00
|
|
|
use Wikimedia\Rdbms\DatabaseDomain;
|
2017-02-07 17:36:12 +00:00
|
|
|
use Wikimedia\Rdbms\Blob;
|
2017-02-19 05:03:13 +00:00
|
|
|
use Wikimedia\Rdbms\ResultWrapper;
|
2019-06-03 17:39:57 +00:00
|
|
|
use Wikimedia\Rdbms\IResultWrapper;
|
2017-02-24 16:17:16 +00:00
|
|
|
use Wikimedia\Rdbms\DBUnexpectedError;
|
2018-08-14 23:44:41 +00:00
|
|
|
use Wikimedia\Rdbms\DBExpectedError;
|
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
|
|
|
|
2019-04-11 04:54:50 +00:00
|
|
|
/** @var string[] Map of (reserved table name => alternate table name) */
|
|
|
|
|
private $keywordTableMap = [];
|
2019-04-09 23:31:34 +00:00
|
|
|
|
2019-04-11 04:54:50 +00:00
|
|
|
/**
|
|
|
|
|
* @see Database::__construct()
|
|
|
|
|
* @param array $params Additional parameters include:
|
|
|
|
|
* - keywordTableMap : Map of reserved table names to alternative table names to use
|
|
|
|
|
*/
|
2019-07-06 19:36:54 +00:00
|
|
|
public function __construct( array $params ) {
|
2019-04-11 04:54:50 +00:00
|
|
|
$this->keywordTableMap = $params['keywordTableMap'] ?? [];
|
|
|
|
|
$params['tablePrefix'] = strtoupper( $params['tablePrefix'] );
|
|
|
|
|
parent::__construct( $params );
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-28 12:44:19 +00:00
|
|
|
function __destruct() {
|
2019-06-13 12:46:03 +00:00
|
|
|
if ( $this->conn ) {
|
|
|
|
|
AtEase::suppressWarnings();
|
2011-04-28 12:44:19 +00:00
|
|
|
$this->close();
|
2019-06-13 12:46:03 +00:00
|
|
|
AtEase::restoreWarnings();
|
2011-04-28 12:44:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-08 00:31:24 +00:00
|
|
|
function getType() {
|
|
|
|
|
return 'oracle';
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-02 18:03:10 +00:00
|
|
|
function implicitOrderby() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2018-08-14 23:44:41 +00:00
|
|
|
protected function open( $server, $user, $password, $dbName, $schema, $tablePrefix ) {
|
2007-03-11 04:00:43 +00:00
|
|
|
if ( !function_exists( 'oci_connect' ) ) {
|
2019-07-11 02:35:46 +00:00
|
|
|
throw $this->newExceptionAfterConnectError(
|
2013-11-20 10:13:51 +00:00
|
|
|
"Oracle functions missing, have you compiled PHP with the --with-oci8 option?\n " .
|
2019-07-11 02:35:46 +00:00
|
|
|
"(Note: if you recently installed PHP, you may need to restart your webserver\n " .
|
|
|
|
|
"and database)"
|
|
|
|
|
);
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-11 02:35:46 +00:00
|
|
|
$this->close();
|
|
|
|
|
|
2019-07-06 19:36:54 +00:00
|
|
|
if ( $schema !== null ) {
|
2019-07-11 02:35:46 +00:00
|
|
|
// This uses the *database* aspect of $domain for schema, not the domain schema
|
|
|
|
|
throw $this->newExceptionAfterConnectError(
|
|
|
|
|
"Got schema '$schema'; not supported. " .
|
|
|
|
|
"The database component '$dbName' is actually interpreted as the Oracle schema."
|
2019-07-06 19:36:54 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-13 06:58:57 +00:00
|
|
|
$this->user = $user;
|
|
|
|
|
$this->password = $password;
|
2019-07-11 02:35:46 +00:00
|
|
|
if ( strlen( $server ) ) {
|
|
|
|
|
// Transparent Network Substrate (TNS) endpoint
|
|
|
|
|
$this->server = $server;
|
|
|
|
|
// Database name, defaulting to the user name
|
|
|
|
|
$realDatabase = strlen( $dbName ) ? $dbName : $user;
|
|
|
|
|
} else {
|
|
|
|
|
// Backward compatibility; $server used to be null and $dbName was the TNS
|
2018-02-13 06:58:57 +00:00
|
|
|
$this->server = $dbName;
|
2018-08-14 23:44:41 +00:00
|
|
|
$realDatabase = $user;
|
2010-10-18 16:09:18 +00:00
|
|
|
}
|
2019-03-20 16:24:35 +00:00
|
|
|
$session_mode = ( $this->flags & DBO_SYSDBA ) ? OCI_SYSDBA : OCI_DEFAULT;
|
2013-05-24 14:05:20 +00:00
|
|
|
|
2019-07-11 02:35:46 +00:00
|
|
|
$this->installErrorHandler();
|
|
|
|
|
try {
|
|
|
|
|
$this->conn = $this->getFlag( DBO_PERSISTENT )
|
|
|
|
|
? oci_pconnect(
|
|
|
|
|
$this->user,
|
|
|
|
|
$this->password,
|
|
|
|
|
$this->server,
|
|
|
|
|
$this->defaultCharset,
|
|
|
|
|
$session_mode
|
|
|
|
|
)
|
|
|
|
|
: oci_new_connect(
|
|
|
|
|
$this->user,
|
|
|
|
|
$this->password,
|
|
|
|
|
$this->server,
|
|
|
|
|
$this->defaultCharset,
|
|
|
|
|
$session_mode
|
|
|
|
|
);
|
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
|
$this->restoreErrorHandler();
|
|
|
|
|
throw $this->newExceptionAfterConnectError( $e->getMessage() );
|
2009-12-11 18:23:24 +00:00
|
|
|
}
|
2019-07-11 02:35:46 +00:00
|
|
|
$error = $this->restoreErrorHandler();
|
2007-03-11 04:00:43 +00:00
|
|
|
|
2018-02-13 06:58:57 +00:00
|
|
|
if ( !$this->conn ) {
|
2019-07-11 02:35:46 +00:00
|
|
|
throw $this->newExceptionAfterConnectError( $error ?: $this->lastError() );
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-11 02:35:46 +00:00
|
|
|
try {
|
|
|
|
|
if ( $this->user != $realDatabase ) {
|
|
|
|
|
// Change current schema for the entire session
|
|
|
|
|
$this->selectDomain( new DatabaseDomain(
|
|
|
|
|
$realDatabase,
|
|
|
|
|
$this->currentDomain->getSchema(),
|
|
|
|
|
$this->currentDomain->getTablePrefix()
|
|
|
|
|
) );
|
|
|
|
|
} else {
|
|
|
|
|
$this->currentDomain = new DatabaseDomain( $realDatabase, null, $tablePrefix );
|
|
|
|
|
}
|
|
|
|
|
$set = [
|
|
|
|
|
'NLS_TIMESTAMP_FORMAT' => 'DD-MM-YYYY HH24:MI:SS.FF6',
|
|
|
|
|
'NLS_TIMESTAMP_TZ_FORMAT' => 'DD-MM-YYYY HH24:MI:SS.FF6',
|
|
|
|
|
'NLS_NUMERIC_CHARACTERS' => '.,'
|
|
|
|
|
];
|
|
|
|
|
foreach ( $set as $var => $val ) {
|
|
|
|
|
$this->query(
|
|
|
|
|
"ALTER SESSION SET {$var}=" . $this->addQuotes( $val ),
|
|
|
|
|
__METHOD__,
|
|
|
|
|
self::QUERY_IGNORE_DBO_TRX | self::QUERY_NO_RETRY
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
|
throw $this->newExceptionAfterConnectError( $e->getMessage() );
|
|
|
|
|
}
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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() {
|
2018-02-13 06:58:57 +00:00
|
|
|
return oci_close( $this->conn );
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function execFlags() {
|
2019-06-13 15:25:40 +00:00
|
|
|
return $this->trxLevel() ? OCI_NO_AUTO_COMMIT : OCI_COMMIT_ON_SUCCESS;
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-01 02:21:49 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $sql
|
|
|
|
|
* @return bool|mixed|ORAResult
|
|
|
|
|
*/
|
2011-06-20 12:09:22 +00:00
|
|
|
protected function doQuery( $sql ) {
|
2019-04-09 23:31:34 +00:00
|
|
|
if ( !mb_check_encoding( (string)$sql, 'UTF-8' ) ) {
|
|
|
|
|
throw new DBUnexpectedError( $this, "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
|
|
|
|
2018-02-13 06:58:57 +00:00
|
|
|
$this->mLastResult = $stmt = oci_parse( $this->conn, $sql );
|
2015-11-18 18:32:05 +00:00
|
|
|
if ( $stmt === false ) {
|
2018-02-13 06:58:57 +00:00
|
|
|
$e = oci_error( $this->conn );
|
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
|
2019-06-03 17:39:57 +00:00
|
|
|
* @param IResultWrapper|ORAResult $res
|
2013-12-27 01:54:51 +00:00
|
|
|
*/
|
2009-12-10 23:22:34 +00:00
|
|
|
function freeResult( $res ) {
|
2019-06-20 22:17:22 +00:00
|
|
|
ResultWrapper::unwrap( $res )->free();
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-27 01:54:51 +00:00
|
|
|
/**
|
2019-06-03 17:39:57 +00:00
|
|
|
* @param IResultWrapper|ORAResult $res
|
|
|
|
|
* @return stdClass|bool
|
2013-12-27 01:54:51 +00:00
|
|
|
*/
|
2009-12-10 23:22:34 +00:00
|
|
|
function fetchObject( $res ) {
|
2019-06-20 22:17:22 +00:00
|
|
|
return ResultWrapper::unwrap( $res )->fetchObject();
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-01 00:08:44 +00:00
|
|
|
/**
|
2019-06-03 17:39:57 +00:00
|
|
|
* @param IResultWrapper|ORAResult $res
|
|
|
|
|
* @return stdClass|bool
|
2016-07-01 00:08:44 +00:00
|
|
|
*/
|
2009-12-10 23:22:34 +00:00
|
|
|
function fetchRow( $res ) {
|
2019-06-20 22:17:22 +00:00
|
|
|
return ResultWrapper::unwrap( $res )->fetchRow();
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-01 00:08:44 +00:00
|
|
|
/**
|
2019-06-03 17:39:57 +00:00
|
|
|
* @param IResultWrapper|ORAResult $res
|
2016-07-01 00:08:44 +00:00
|
|
|
* @return int
|
|
|
|
|
*/
|
2009-12-10 23:22:34 +00:00
|
|
|
function numRows( $res ) {
|
2019-06-20 22:17:22 +00:00
|
|
|
return ResultWrapper::unwrap( $res )->numRows();
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-01 00:08:44 +00:00
|
|
|
/**
|
2019-06-03 17:39:57 +00:00
|
|
|
* @param IResultWrapper|ORAResult $res
|
2016-07-01 00:08:44 +00:00
|
|
|
* @return int
|
|
|
|
|
*/
|
2009-12-10 23:22:34 +00:00
|
|
|
function numFields( $res ) {
|
2019-06-20 22:17:22 +00:00
|
|
|
return ResultWrapper::unwrap( $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 {
|
2019-06-20 22:17:22 +00:00
|
|
|
ResultWrapper::unwrap( $res )->seek( $row );
|
2009-06-05 11:45:32 +00:00
|
|
|
}
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function lastError() {
|
2018-02-13 06:58:57 +00:00
|
|
|
if ( $this->conn === false ) {
|
2007-03-11 04:00:43 +00:00
|
|
|
$e = oci_error();
|
2009-12-11 18:23:24 +00:00
|
|
|
} else {
|
2018-02-13 06:58:57 +00:00
|
|
|
$e = oci_error( $this->conn );
|
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() {
|
2018-02-13 06:58:57 +00:00
|
|
|
if ( $this->conn === false ) {
|
2007-03-11 04:00:43 +00:00
|
|
|
$e = oci_error();
|
2009-12-11 18:23:24 +00:00
|
|
|
} else {
|
2018-02-13 06:58:57 +00:00
|
|
|
$e = oci_error( $this->conn );
|
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
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2018-10-26 20:17:34 +00:00
|
|
|
return true;
|
2007-03-11 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
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 ) {
|
2019-04-09 23:31:34 +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 ) {
|
|
|
|
|
$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
|
|
|
|
2018-02-13 06:58:57 +00:00
|
|
|
$this->mLastResult = $stmt = oci_parse( $this->conn, $sql );
|
2015-11-18 18:32:05 +00:00
|
|
|
if ( $stmt === false ) {
|
2018-02-13 06:58:57 +00:00
|
|
|
$e = oci_error( $this->conn );
|
2019-04-15 15:05:31 +00:00
|
|
|
$this->reportQueryError( $e['message'], $e['code'], $sql, $fname );
|
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
|
2019-04-09 23:31:34 +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
|
|
|
|
2019-04-09 23:31:34 +00:00
|
|
|
$val = $this->getVerifiedUTF8( $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 );
|
2019-04-15 15:05:31 +00:00
|
|
|
$this->reportQueryError( $e['message'], $e['code'], $sql, $fname );
|
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 */
|
2018-02-13 06:58:57 +00:00
|
|
|
$lob[$col] = oci_new_descriptor( $this->conn, OCI_D_LOB );
|
2015-11-18 18:32:05 +00:00
|
|
|
if ( $lob[$col] === false ) {
|
2009-12-10 23:22:34 +00:00
|
|
|
$e = oci_error( $stmt );
|
2019-04-09 23:31:34 +00:00
|
|
|
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' ) {
|
2019-04-15 15:05:31 +00:00
|
|
|
$this->reportQueryError( $e['message'], $e['code'], $sql, $fname );
|
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
|
|
|
|
2019-06-13 15:25:40 +00:00
|
|
|
if ( !$this->trxLevel() ) {
|
2018-02-13 06:58:57 +00:00
|
|
|
oci_commit( $this->conn );
|
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']] )
|
|
|
|
|
) {
|
2019-04-09 23:31: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 ) {
|
2019-03-07 09:55:31 +00:00
|
|
|
$val .= ' field' . $i;
|
|
|
|
|
$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
|
|
|
|
|
);
|
|
|
|
|
|
2019-04-09 23:31:34 +00:00
|
|
|
$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
|
|
|
|
2018-10-26 20:17:34 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
2019-03-13 03:09:21 +00:00
|
|
|
public function upsert( $table, array $rows, $uniqueIndexes, array $set,
|
2014-02-04 18:35:10 +00:00
|
|
|
$fname = __METHOD__
|
|
|
|
|
) {
|
2019-01-09 16:24:36 +00:00
|
|
|
if ( $rows === [] ) {
|
2014-02-04 18:35:10 +00:00
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 04:54:50 +00:00
|
|
|
public function tableName( $name, $format = 'quoted' ) {
|
|
|
|
|
// Replace reserved words with better ones
|
|
|
|
|
$name = $this->remappedTableName( $name );
|
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
|
|
|
}
|
|
|
|
|
|
2019-04-11 04:54:50 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @return string Value of $name or remapped name if $name is a reserved keyword
|
|
|
|
|
*/
|
|
|
|
|
public function remappedTableName( $name ) {
|
|
|
|
|
return $this->keywordTableMap[$name] ?? $name;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2019-04-10 01:46:47 +00:00
|
|
|
* @return string[]|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 ) {
|
2019-04-11 04:54:50 +00:00
|
|
|
$dbname = $this->currentDomain->getDatabase();
|
|
|
|
|
$prefix = $this->currentDomain->getTablePrefix();
|
|
|
|
|
// See https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions040.htm
|
|
|
|
|
$decodeArgs = [ 'atc.table_name' ]; // the switch
|
|
|
|
|
foreach ( $this->keywordTableMap as $reserved => $alternative ) {
|
|
|
|
|
$search = strtoupper( $prefix . $alternative ); // case
|
|
|
|
|
$replace = strtoupper( $prefix . $reserved ); // result
|
|
|
|
|
$decodeArgs[] = $this->addQuotes( $search );
|
|
|
|
|
$decodeArgs[] = $this->addQuotes( $replace );
|
|
|
|
|
}
|
|
|
|
|
$decodeArgs[] = [ 'atc.table_name' ]; // default
|
|
|
|
|
$decodeArgs = implode( ', ', $decodeArgs );
|
|
|
|
|
|
|
|
|
|
$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({$decodeArgs}) || '_' ||
|
|
|
|
|
atc.column_name || '_SEQ' = '{$prefix}' || asq.sequence_name
|
|
|
|
|
AND asq.sequence_owner = upper('{$dbname}')
|
|
|
|
|
AND atc.owner = upper('{$dbname}')"
|
|
|
|
|
);
|
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
|
|
|
|
2018-06-11 17:23:15 +00:00
|
|
|
return $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 );
|
|
|
|
|
}
|
|
|
|
|
|
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';
|
2019-04-11 04:54:50 +00:00
|
|
|
$tablePrefix = $this->currentDomain->getTablePrefix();
|
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
|
|
|
|
2019-04-11 04:54:50 +00:00
|
|
|
$tabName = substr( $newName, strlen( $tablePrefix ) );
|
2011-06-02 22:23:05 +00:00
|
|
|
$oldPrefix = substr( $oldName, 0, strlen( $oldName ) - strlen( $tabName ) );
|
2019-04-11 04:54:50 +00:00
|
|
|
$newPrefix = strtoupper( $tablePrefix );
|
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
|
|
|
|
2018-08-14 23:44:41 +00:00
|
|
|
$owner = strtoupper( $this->getDBname() );
|
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" );
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 23:31:34 +00:00
|
|
|
public function timestamp( $ts = 0 ) {
|
|
|
|
|
$t = new ConvertibleTimestamp( $ts );
|
|
|
|
|
// Let errors bubble up to avoid putting garbage in the DB
|
|
|
|
|
return $t->getTimestamp( TS_ORACLE );
|
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 ) {
|
2018-02-13 06:58:57 +00:00
|
|
|
return oci_server_version( $this->conn );
|
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 );
|
2018-08-14 23:44:41 +00:00
|
|
|
$owner = strtoupper( $this->getDBname() );
|
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 ) ) );
|
2018-08-14 23:44:41 +00:00
|
|
|
$owner = $this->addQuotes( strtoupper( $this->getDBname() ) );
|
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(
|
2018-02-13 06:58:57 +00:00
|
|
|
$this->conn,
|
2013-11-20 10:13:51 +00:00
|
|
|
'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 ) ) {
|
2019-04-09 23:31:34 +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__ ) {
|
2019-06-13 15:25:40 +00:00
|
|
|
$this->query( '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__ ) {
|
2019-06-13 15:25:40 +00:00
|
|
|
if ( $this->trxLevel() ) {
|
2018-02-13 06:58:57 +00:00
|
|
|
$ret = oci_commit( $this->conn );
|
2011-06-07 05:09:32 +00:00
|
|
|
if ( !$ret ) {
|
|
|
|
|
throw new DBUnexpectedError( $this, $this->lastError() );
|
|
|
|
|
}
|
2019-06-13 15:25:40 +00:00
|
|
|
$this->query( '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__ ) {
|
2019-06-13 15:25:40 +00:00
|
|
|
if ( $this->trxLevel() ) {
|
2018-02-13 06:58:57 +00:00
|
|
|
oci_rollback( $this->conn );
|
2019-06-13 15:25:40 +00:00
|
|
|
$ignoreErrors = true;
|
|
|
|
|
$this->query( 'SET CONSTRAINTS ALL IMMEDIATE', $fname, $ignoreErrors );
|
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 ) {
|
2019-03-24 23:14:49 +00:00
|
|
|
$lineCallback();
|
2009-06-08 18:30:27 +00:00
|
|
|
}
|
|
|
|
|
$line = trim( fgets( $fp, 1024 ) );
|
|
|
|
|
$sl = strlen( $line ) - 1;
|
|
|
|
|
|
2009-12-11 18:23:24 +00:00
|
|
|
if ( $sl < 0 ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-06-30 09:43:00 +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 ) {
|
2018-06-30 09:43:00 +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 ) {
|
2019-03-24 23:14:49 +00:00
|
|
|
$inputCallback( $cmd );
|
2012-02-02 15:12:28 +00:00
|
|
|
}
|
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
|
|
|
|
2018-06-30 09:43:00 +00:00
|
|
|
if ( $res === false ) {
|
2009-06-08 18:30:27 +00:00
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-14 23:44:41 +00:00
|
|
|
protected function doSelectDomain( DatabaseDomain $domain ) {
|
|
|
|
|
if ( $domain->getSchema() !== null ) {
|
|
|
|
|
// We use the *database* aspect of $domain for schema, not the domain schema
|
2019-07-06 19:36:54 +00:00
|
|
|
throw new DBExpectedError(
|
|
|
|
|
$this,
|
|
|
|
|
__CLASS__ . ": domain '{$domain->getId()}' has a schema component; " .
|
|
|
|
|
"the database component is actually interpreted as the Oracle schema."
|
|
|
|
|
);
|
2018-08-14 23:44:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$database = $domain->getDatabase();
|
|
|
|
|
if ( $database === null || $database === $this->user ) {
|
|
|
|
|
// Backward compatibility
|
|
|
|
|
$this->currentDomain = $domain;
|
|
|
|
|
|
2011-01-27 08:25:48 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-14 23:44:41 +00:00
|
|
|
|
|
|
|
|
// https://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj32268.html
|
|
|
|
|
$encDatabase = $this->addIdentifierQuotes( strtoupper( $database ) );
|
|
|
|
|
$sql = "ALTER SESSION SET CURRENT_SCHEMA=$encDatabase";
|
2018-02-13 06:58:57 +00:00
|
|
|
$stmt = oci_parse( $this->conn, $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();
|
2018-08-14 23:44:41 +00:00
|
|
|
if ( $success ) {
|
|
|
|
|
// Update that domain fields on success (no exception thrown)
|
|
|
|
|
$this->currentDomain = $domain;
|
|
|
|
|
} else {
|
2010-10-18 16:09:18 +00:00
|
|
|
$e = oci_error( $stmt );
|
2018-08-14 23:44:41 +00:00
|
|
|
$this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
|
2010-10-18 16:09:18 +00:00
|
|
|
}
|
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 ) {
|
2019-04-09 23:31:34 +00:00
|
|
|
return "'" . $this->strencode( $this->getVerifiedUTF8( $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 ) {
|
|
|
|
|
$col_info = $this->fieldInfoMulti( $table, $col );
|
|
|
|
|
$col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
|
|
|
|
|
if ( $col_type == 'CLOB' ) {
|
|
|
|
|
$col = 'TO_CHAR(' . $col . ')';
|
2019-04-09 23:31:34 +00:00
|
|
|
$val = $this->getVerifiedUTF8( $val );
|
2012-11-16 12:52:55 +00:00
|
|
|
} elseif ( $col_type == 'VARCHAR2' ) {
|
2019-04-09 23:31:34 +00:00
|
|
|
$val = $this->getVerifiedUTF8( $val );
|
2011-06-01 11:38:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
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__ ) {
|
2017-09-12 17:12:29 +00:00
|
|
|
global $wgActorTableSchemaMigrationStage;
|
|
|
|
|
|
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
|
2017-09-12 17:12:29 +00:00
|
|
|
// @todo: Normalize the schema to match MySQL, no special FKs and such
|
2011-09-02 10:42:08 +00:00
|
|
|
$table = $this->tableName( $table );
|
2018-09-18 18:21:20 +00:00
|
|
|
if ( $table == $this->tableName( 'user' ) &&
|
|
|
|
|
( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_OLD )
|
|
|
|
|
) {
|
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 = [] ) {
|
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 );
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-13 06:58:57 +00:00
|
|
|
$this->mLastResult = $stmt = oci_parse( $this->conn, $sql );
|
2015-11-18 18:32:05 +00:00
|
|
|
if ( $stmt === false ) {
|
2018-02-13 06:58:57 +00:00
|
|
|
$e = oci_error( $this->conn );
|
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;
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 23:31:34 +00:00
|
|
|
if (
|
|
|
|
|
preg_match( '/^timestamp.*/i', $col_type ) == 1 &&
|
|
|
|
|
strtolower( $val ) == 'infinity'
|
|
|
|
|
) {
|
2010-10-25 10:56:07 +00:00
|
|
|
$val = '31-12-2030 12:00:00.000000';
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 23:31:34 +00:00
|
|
|
$val = $this->getVerifiedUTF8( $val );
|
2010-10-25 10:56:07 +00:00
|
|
|
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 */
|
2018-02-13 06:58:57 +00:00
|
|
|
$lob[$col] = oci_new_descriptor( $this->conn, OCI_D_LOB );
|
2015-11-18 18:32:05 +00:00
|
|
|
if ( $lob[$col] === false ) {
|
2010-10-25 10:56:07 +00:00
|
|
|
$e = oci_error( $stmt );
|
2019-04-09 23:31:34 +00:00
|
|
|
throw new DBUnexpectedError(
|
|
|
|
|
$this,
|
|
|
|
|
"Cannot create LOB descriptor: " . $e['message']
|
|
|
|
|
);
|
2010-10-25 10:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 15:25:40 +00:00
|
|
|
if ( !$this->trxLevel() ) {
|
2018-02-13 06:58:57 +00:00
|
|
|
oci_commit( $this->conn );
|
2010-10-25 10:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2018-03-04 13:23:39 +00:00
|
|
|
public function buildSubstring( $input, $startPosition, $length = null ) {
|
|
|
|
|
$this->assertBuildSubstringParams( $startPosition, $length );
|
|
|
|
|
$params = [ $input, $startPosition ];
|
|
|
|
|
if ( $length !== null ) {
|
|
|
|
|
$params[] = $length;
|
|
|
|
|
}
|
|
|
|
|
return 'SUBSTR(' . implode( ',', $params ) . ')';
|
|
|
|
|
}
|
|
|
|
|
|
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';
|
|
|
|
|
}
|
2019-04-09 23:31:34 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $s
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getVerifiedUTF8( $s ) {
|
|
|
|
|
if ( mb_check_encoding( (string)$s, 'UTF-8' ) ) {
|
|
|
|
|
return $s; // valid
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new DBUnexpectedError( $this, "Non BLOB/CLOB field must be UTF-8." );
|
|
|
|
|
}
|
2013-12-27 01:54:51 +00:00
|
|
|
}
|