39 $array_hashes =
array();
41 foreach ( $array_in
as $item ) {
42 $hash = md5( serialize( $item ) );
43 if ( !isset( $array_hashes[
$hash] ) ) {
60 $this->nrows = oci_fetch_all( $stmt, $this->rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW | OCI_NUM );
61 if ( $this->nrows ===
false ) {
62 $e = oci_error( $stmt );
63 $db->reportQueryError(
$e[
'message'],
$e[
'code'],
'', __METHOD__ );
71 $this->nrows = count( $this->rows );
74 if ( $this->nrows > 0 ) {
75 foreach ( $this->rows[0]
as $k => $v ) {
76 $this->columns[$k] = strtolower( oci_field_name( $stmt, $k + 1 ) );
81 oci_free_statement( $stmt );
88 public function seek( $row ) {
89 $this->cursor = min( $row, $this->nrows );
97 return count( $this->columns );
101 if ( $this->cursor >= $this->nrows ) {
104 $row = $this->rows[$this->cursor++];
105 $ret =
new stdClass();
106 foreach ( $row
as $k => $v ) {
107 $lc = $this->columns[$k];
115 if ( $this->cursor >= $this->nrows ) {
119 $row = $this->rows[$this->cursor++];
121 foreach ( $row
as $k => $v ) {
122 $lc = $this->columns[$k];
140 $this->
name = $info[
'column_name'];
141 $this->tablename = $info[
'table_name'];
142 $this->
default = $info[
'data_default'];
143 $this->max_length = $info[
'data_length'];
144 $this->nullable = $info[
'not_null'];
145 $this->is_pk = isset( $info[
'prim'] ) && $info[
'prim'] == 1 ? 1 : 0;
146 $this->is_unique = isset( $info[
'uniq'] ) && $info[
'uniq'] == 1 ? 1 : 0;
147 $this->is_multiple = isset( $info[
'nonuniq'] ) && $info[
'nonuniq'] == 1 ? 1 : 0;
149 $this->
type = $info[
'data_type'];
213 if ( !is_array( $p ) ) {
214 wfDeprecated( __METHOD__ .
" method called without parameter array.",
"1.22" );
215 $args = func_get_args();
217 'host' => isset(
$args[0] ) ?
$args[0] :
false,
218 'user' => isset(
$args[1] ) ?
$args[1] :
false,
219 'password' => isset(
$args[2] ) ?
$args[2] :
false,
220 'dbname' => isset(
$args[3] ) ?
$args[3] :
false,
222 'tablePrefix' => isset(
$args[5] ) ?
$args[5] :
'get from global',
223 'schema' =>
'get from global',
224 'foreign' => isset(
$args[6] ) ?
$args[6] :
false
227 if ( $p[
'tablePrefix'] ==
'get from global' ) {
228 $p[
'tablePrefix'] = $wgDBprefix;
230 $p[
'tablePrefix'] = strtoupper( $p[
'tablePrefix'] );
231 parent::__construct( $p );
236 if ( $this->mOpened ) {
286 if ( !function_exists(
'oci_connect' ) ) {
289 "Oracle functions missing, have you compiled PHP with the --with-oci8 option?\n " .
290 "(Note: if you recently installed PHP, you may need to restart your webserver\n " .
295 $this->mUser =
$user;
302 $this->mServer = $dbName;
303 $this->mDBname =
$user;
305 $this->mServer = $server;
307 $this->mDBname =
$user;
309 $this->mDBname = $dbName;
313 if ( !strlen(
$user ) ) { #
e.g. the
class is being loaded
317 if ( $wgDBOracleDRCP ) {
321 $session_mode = $this->mFlags &
DBO_SYSDBA ? OCI_SYSDBA : OCI_DEFAULT;
325 $this->mConn = oci_pconnect(
329 $this->defaultCharset,
333 $this->mConn = oci_new_connect(
337 $this->defaultCharset,
341 $this->mConn = oci_connect(
345 $this->defaultCharset,
351 if ( $this->mUser != $this->mDBname ) {
356 if ( !$this->mConn ) {
360 $this->mOpened =
true;
362 # removed putenv calls because they interfere with the system globaly
363 $this->
doQuery(
'ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'' );
364 $this->
doQuery(
'ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'' );
365 $this->
doQuery(
'ALTER SESSION SET NLS_NUMERIC_CHARACTERS=\'.,\'' );
376 return oci_close( $this->mConn );
380 return $this->mTrxLevel ? OCI_NO_AUTO_COMMIT : OCI_COMMIT_ON_SUCCESS;
383 protected function doQuery( $sql ) {
386 throw new MWException(
"SQL encoding is invalid\n$sql" );
392 $sql = preg_replace(
'/ as /i',
' ', $sql );
397 $union_unique = ( preg_match(
'/\/\* UNION_UNIQUE \*\/ /', $sql ) != 0 );
404 'EXPLAIN PLAN SET STATEMENT_ID = \'' . $explain_id .
'\' FOR
',
410 wfSuppressWarnings();
412 if ( ( $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ) ) === false ) {
413 $e = oci_error( $this->mConn );
414 $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
419 if ( !oci_execute( $stmt, $this->execFlags() ) ) {
420 $e = oci_error( $stmt );
421 if ( !$this->ignoreDupValOnIndex || $e['code'] != '1
' ) {
422 $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
430 if ( $explain_count > 0 ) {
431 return $this->doQuery( 'SELECT
id, cardinality
"ROWS" FROM plan_table
' .
432 'WHERE statement_id = \
'' . $explain_id .
'\'' );
433 } elseif ( oci_statement_type( $stmt ) ==
'SELECT' ) {
434 return new ORAResult( $this, $stmt, $union_unique );
436 $this->mAffectedRows = oci_num_rows( $stmt );
442 function queryIgnore( $sql,
$fname =
'' ) {
450 function freeResult(
$res ) {
462 function fetchObject(
$res ) {
467 return $res->fetchObject();
470 function fetchRow(
$res ) {
475 return $res->fetchRow();
478 function numRows(
$res ) {
483 return $res->numRows();
486 function numFields(
$res ) {
491 return $res->numFields();
494 function fieldName( $stmt,
$n ) {
495 return oci_field_name( $stmt,
$n );
502 function insertId() {
503 return $this->mInsertId;
510 function dataSeek(
$res, $row ) {
514 $res->result->seek( $row );
518 function lastError() {
519 if ( $this->mConn ===
false ) {
522 $e = oci_error( $this->mConn );
525 return $e[
'message'];
528 function lastErrno() {
529 if ( $this->mConn ===
false ) {
532 $e = oci_error( $this->mConn );
538 function affectedRows() {
539 return $this->mAffectedRows;
550 function indexInfo( $table, $index,
$fname = __METHOD__ ) {
554 function indexUnique( $table, $index,
$fname = __METHOD__ ) {
559 if ( !count( $a ) ) {
567 if ( in_array(
'IGNORE',
$options ) ) {
568 $this->ignoreDupValOnIndex =
true;
571 if ( !is_array( reset( $a ) ) ) {
575 foreach ( $a
as &$row ) {
576 $this->insertOneRow( $table, $row,
$fname );
581 $this->ignoreDupValOnIndex =
false;
587 private function fieldBindStatement( $table, $col, &$val, $includeCol =
false ) {
588 $col_info = $this->fieldInfoMulti( $table, $col );
589 $col_type = $col_info !=
false ? $col_info->type() :
'CONSTANT';
592 if ( is_numeric( $col ) ) {
597 } elseif ( $includeCol ) {
601 if ( $val ==
'' && $val !== 0 && $col_type !=
'BLOB' && $col_type !=
'CLOB' ) {
605 if ( $val ===
'NULL' ) {
609 if ( $val ===
null ) {
610 if ( $col_info !=
false && $col_info->isNullable() == 0 && $col_info->defaultValue() != null ) {
629 private function insertOneRow( $table, $row,
$fname ) {
634 $sql =
"INSERT INTO " . $table .
" (" . join(
',', array_keys( $row ) ) .
')';
639 foreach ( $row
as $col => &$val ) {
645 if ( $this->isQuotedIdentifier( $val ) ) {
646 $sql .= $this->removeIdentifierQuotes( $val );
649 $sql .= $this->fieldBindStatement( $table, $col, $val );
654 if ( ( $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ) ) ===
false ) {
655 $e = oci_error( $this->mConn );
656 $this->reportQueryError(
$e[
'message'],
$e[
'code'], $sql, __METHOD__ );
660 foreach ( $row
as $col => &$val ) {
661 $col_info = $this->fieldInfoMulti( $table, $col );
662 $col_type = $col_info !=
false ? $col_info->type() :
'CONSTANT';
664 if ( $val ===
null ) {
666 } elseif ( $col_type !=
'BLOB' && $col_type !=
'CLOB' ) {
667 if ( is_object( $val ) ) {
668 $val = $val->fetch();
672 if ( preg_match(
'/^timestamp.*/i', $col_type ) == 1 && strtolower( $val ) ==
'infinity' ) {
673 $val = $this->getInfinity();
677 if ( oci_bind_by_name( $stmt,
":$col", $val, -1, SQLT_CHR ) ===
false ) {
678 $e = oci_error( $stmt );
679 $this->reportQueryError(
$e[
'message'],
$e[
'code'], $sql, __METHOD__ );
685 if ( ( $lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB ) ) ===
false ) {
686 $e = oci_error( $stmt );
690 if ( is_object( $val ) ) {
691 $val = $val->fetch();
694 if ( $col_type ==
'BLOB' ) {
695 $lob[$col]->writeTemporary( $val, OCI_TEMP_BLOB );
696 oci_bind_by_name( $stmt,
":$col", $lob[$col], -1, OCI_B_BLOB );
698 $lob[$col]->writeTemporary( $val, OCI_TEMP_CLOB );
699 oci_bind_by_name( $stmt,
":$col", $lob[$col], -1, OCI_B_CLOB );
706 if ( oci_execute( $stmt, $this->execFlags() ) ===
false ) {
707 $e = oci_error( $stmt );
708 if ( !$this->ignoreDupValOnIndex ||
$e[
'code'] !=
'1' ) {
709 $this->reportQueryError(
$e[
'message'],
$e[
'code'], $sql, __METHOD__ );
713 $this->mAffectedRows = oci_num_rows( $stmt );
716 $this->mAffectedRows = oci_num_rows( $stmt );
721 if ( isset( $lob ) ) {
722 foreach ( $lob
as $lob_v ) {
727 if ( !$this->mTrxLevel ) {
728 oci_commit( $this->mConn );
731 return oci_free_statement( $stmt );
734 function insertSelect( $destTable, $srcTable, $varMap, $conds,
$fname = __METHOD__,
735 $insertOptions =
array(), $selectOptions =
array()
737 $destTable = $this->
tableName( $destTable );
738 if ( !is_array( $selectOptions ) ) {
739 $selectOptions =
array( $selectOptions );
741 list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $selectOptions );
742 if ( is_array( $srcTable ) ) {
743 $srcTable = implode(
',', array_map(
array( &$this,
'tableName' ), $srcTable ) );
745 $srcTable = $this->
tableName( $srcTable );
748 if ( ( $sequenceData = $this->getSequenceData( $destTable ) ) !==
false &&
749 !isset( $varMap[$sequenceData[
'column']] )
751 $varMap[$sequenceData[
'column']] =
'GET_SEQUENCE_VALUE(\'' . $sequenceData[
'sequence'] .
'\')
';
754 // count-alias subselect fields to avoid abigious definition errors
756 foreach ( $varMap as &$val ) {
757 $val = $val . ' field
' . ( $i++ );
760 $sql = "INSERT INTO $destTable (" . implode( ',
', array_keys( $varMap ) ) . ')
' .
761 " SELECT $startOpts " . implode( ',
', $varMap ) .
762 " FROM $srcTable $useIndex ";
763 if ( $conds != '*
' ) {
764 $sql .= ' WHERE
' . $this->makeList( $conds, LIST_AND );
766 $sql .= " $tailOpts";
768 if ( in_array( 'IGNORE
', $insertOptions ) ) {
769 $this->ignoreDupValOnIndex = true;
772 $retval = $this->query( $sql, $fname );
774 if ( in_array( 'IGNORE
', $insertOptions ) ) {
775 $this->ignoreDupValOnIndex = false;
781 public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
784 if ( !count( $rows ) ) {
785 return true; // nothing to do
788 if ( !is_array( reset( $rows ) ) ) {
789 $rows = array( $rows );
792 $sequenceData = $this->getSequenceData( $table );
793 if ( $sequenceData !== false ) {
794 // add sequence column to each list of columns, when not set
795 foreach ( $rows as &$row ) {
796 if ( !isset( $row[$sequenceData['column
']] ) ) {
797 $row[$sequenceData['column
']] =
798 $this->addIdentifierQuotes( 'GET_SEQUENCE_VALUE(\
'' .
799 $sequenceData[
'sequence'] .
'\')
' );
804 return parent::upsert( $table, $rows, $uniqueIndexes, $set, $fname );
807 function tableName( $name, $format = 'quoted
' ) {
809 Replace reserved words with better ones
810 Using uppercase because that's the
only way Oracle can handle
825 function tableNameInternal(
$name ) {
828 return preg_replace(
'/.*\.(.*)/',
'$1',
$name );
837 function nextSequenceValue( $seqName ) {
838 $res = $this->
query(
"SELECT $seqName.nextval FROM dual" );
839 $row = $this->fetchRow(
$res );
840 $this->mInsertId = $row[0];
842 return $this->mInsertId;
851 private function getSequenceData( $table ) {
852 if ( $this->sequenceData ==
null ) {
853 $result = $this->doQuery(
"SELECT lower(asq.sequence_name),
854 lower(atc.table_name),
855 lower(atc.column_name)
856 FROM all_sequences asq, all_tab_columns atc
859 '{$this->mTablePrefix}MWUSER',
860 '{$this->mTablePrefix}USER',
863 atc.column_name || '_SEQ' = '{$this->mTablePrefix}' || asq.sequence_name
864 AND asq.sequence_owner = upper('{$this->mDBname}')
865 AND atc.owner = upper('{$this->mDBname}')" );
867 while ( ( $row =
$result->fetchRow() ) !==
false ) {
868 $this->sequenceData[$row[1]] =
array(
869 'sequence' => $row[0],
874 $table = strtolower( $this->removeIdentifierQuotes( $this->
tableName( $table ) ) );
876 return ( isset( $this->sequenceData[$table] ) ) ? $this->sequenceData[$table] :
false;
886 function textFieldSize( $table, $field ) {
887 $fieldInfoData = $this->fieldInfo( $table, $field );
889 return $fieldInfoData->maxLength();
892 function limitResult( $sql,
$limit, $offset =
false ) {
893 if ( $offset ===
false ) {
897 return "SELECT * FROM ($sql) WHERE rownum >= (1 + $offset) AND rownum < (1 + $limit + $offset)";
900 function encodeBlob( $b ) {
901 return new Blob( $b );
904 function decodeBlob( $b ) {
912 function unionQueries( $sqls, $all ) {
913 $glue =
' UNION ALL ';
915 return 'SELECT * ' . ( $all ?
'' :
'/* UNION_UNIQUE */ ' ) .
916 'FROM (' . implode( $glue, $sqls ) .
')';
919 function wasDeadlock() {
920 return $this->lastErrno() ==
'OCI-00060';
923 function duplicateTableStructure( $oldName, $newName, $temporary =
false,
926 $temporary = $temporary ?
'TRUE' :
'FALSE';
928 $newName = strtoupper( $newName );
929 $oldName = strtoupper( $oldName );
931 $tabName = substr( $newName, strlen( $this->mTablePrefix ) );
932 $oldPrefix = substr( $oldName, 0, strlen( $oldName ) - strlen( $tabName ) );
933 $newPrefix = strtoupper( $this->mTablePrefix );
935 return $this->doQuery(
"BEGIN DUPLICATE_TABLE( '$tabName', " .
936 "'$oldPrefix', '$newPrefix', $temporary ); END;" );
939 function listTables( $prefix =
null,
$fname = __METHOD__ ) {
941 if ( !empty( $prefix ) ) {
942 $listWhere =
' AND table_name LIKE \'' . strtoupper( $prefix ) .
'%\'';
945 $owner = strtoupper( $this->mDBname );
946 $result = $this->doQuery(
"SELECT table_name FROM all_tables " .
947 "WHERE owner='$owner' AND table_name NOT LIKE '%!_IDX\$_' ESCAPE '!' $listWhere" );
951 $endArray[] = strtoupper( $prefix .
'MWUSER' );
952 $endArray[] = strtoupper( $prefix .
'PAGE' );
953 $endArray[] = strtoupper( $prefix .
'IMAGE' );
954 $fixedOrderTabs = $endArray;
955 while ( ( $row =
$result->fetchRow() ) !==
false ) {
956 if ( !in_array( $row[
'table_name'], $fixedOrderTabs ) ) {
957 $endArray[] = $row[
'table_name'];
964 public function dropTable( $tableName, $fName = __METHOD__ ) {
965 $tableName = $this->
tableName( $tableName );
966 if ( !$this->tableExists( $tableName ) ) {
970 return $this->doQuery(
"DROP TABLE $tableName CASCADE CONSTRAINTS PURGE" );
973 function timestamp( $ts = 0 ) {
984 public function aggregateValue( $valuedata, $valuename =
'value' ) {
988 function reportQueryError(
$error, $errno, $sql,
$fname, $tempIgnore =
false ) {
989 # Ignore errors during error handling to avoid infinite
991 $ignore = $this->ignoreErrors(
true );
992 ++$this->mErrorCount;
994 if (
$ignore || $tempIgnore ) {
995 wfDebug(
"SQL ERROR (ignored): $error\n" );
996 $this->ignoreErrors(
$ignore );
1005 public function getSoftwareLink() {
1006 return '[{{int:version-db-oracle-url}} Oracle]';
1012 function getServerVersion() {
1014 $rset = $this->doQuery(
1015 'SELECT version FROM product_component_version ' .
1016 'WHERE UPPER(product) LIKE \'ORACLE DATABASE%\''
1018 if ( !( $row = $rset->fetchRow() ) ) {
1019 return oci_server_version( $this->mConn );
1022 return $row[
'version'];
1032 function indexExists( $table, $index,
$fname = __METHOD__ ) {
1034 $table = strtoupper( $this->removeIdentifierQuotes( $table ) );
1035 $index = strtoupper( $index );
1036 $owner = strtoupper( $this->mDBname );
1037 $sql =
"SELECT 1 FROM all_indexes WHERE owner='$owner' AND index_name='{$table}_{$index}'";
1038 $res = $this->doQuery( $sql );
1055 function tableExists( $table,
$fname = __METHOD__ ) {
1057 $table = $this->addQuotes( strtoupper( $this->removeIdentifierQuotes( $table ) ) );
1058 $owner = $this->addQuotes( strtoupper( $this->mDBname ) );
1059 $sql =
"SELECT 1 FROM all_tables WHERE owner=$owner AND table_name=$table";
1060 $res = $this->doQuery( $sql );
1061 if (
$res &&
$res->numRows() > 0 ) {
1082 private function fieldInfoMulti( $table, $field ) {
1083 $field = strtoupper( $field );
1084 if ( is_array( $table ) ) {
1085 $table = array_map(
array( &$this,
'tableNameInternal' ), $table );
1086 $tableWhere =
'IN (';
1087 foreach ( $table
as &$singleTable ) {
1088 $singleTable = $this->removeIdentifierQuotes( $singleTable );
1089 if ( isset( $this->mFieldInfoCache[
"$singleTable.$field"] ) ) {
1090 return $this->mFieldInfoCache[
"$singleTable.$field"];
1092 $tableWhere .=
'\'' . $singleTable .
'\',
';
1094 $tableWhere = rtrim( $tableWhere, ',
' ) . ')
';
1096 $table = $this->removeIdentifierQuotes( $this->tableNameInternal( $table ) );
1097 if ( isset( $this->mFieldInfoCache["$table.$field"] ) ) {
1098 return $this->mFieldInfoCache["$table.$field"];
1100 $tableWhere = '= \
'' . $table .
'\'';
1103 $fieldInfoStmt = oci_parse(
1105 'SELECT * FROM wiki_field_info_full WHERE table_name ' .
1106 $tableWhere .
' and column_name = \'' . $field .
'\''
1108 if ( oci_execute( $fieldInfoStmt, $this->execFlags() ) ===
false ) {
1109 $e = oci_error( $fieldInfoStmt );
1110 $this->reportQueryError(
$e[
'message'],
$e[
'code'],
'fieldInfo QUERY', __METHOD__ );
1115 if (
$res->numRows() == 0 ) {
1116 if ( is_array( $table ) ) {
1117 foreach ( $table
as &$singleTable ) {
1118 $this->mFieldInfoCache[
"$singleTable.$field"] =
false;
1121 $this->mFieldInfoCache[
"$table.$field"] =
false;
1123 $fieldInfoTemp =
null;
1127 $this->mFieldInfoCache[
"$table.$field"] = $fieldInfoTemp;
1131 return $fieldInfoTemp;
1140 function fieldInfo( $table, $field ) {
1141 if ( is_array( $table ) ) {
1142 throw new DBUnexpectedError( $this,
'DatabaseOracle::fieldInfo called with table array!' );
1145 return $this->fieldInfoMulti( $table, $field );
1148 protected function doBegin(
$fname = __METHOD__ ) {
1149 $this->mTrxLevel = 1;
1150 $this->doQuery(
'SET CONSTRAINTS ALL DEFERRED' );
1153 protected function doCommit(
$fname = __METHOD__ ) {
1154 if ( $this->mTrxLevel ) {
1155 $ret = oci_commit( $this->mConn );
1159 $this->mTrxLevel = 0;
1160 $this->doQuery(
'SET CONSTRAINTS ALL IMMEDIATE' );
1164 protected function doRollback(
$fname = __METHOD__ ) {
1165 if ( $this->mTrxLevel ) {
1166 oci_rollback( $this->mConn );
1167 $this->mTrxLevel = 0;
1168 $this->doQuery(
'SET CONSTRAINTS ALL IMMEDIATE' );
1182 function sourceStream( $fp, $lineCallback =
false, $resultCallback =
false,
1183 $fname = __METHOD__, $inputCallback =
false ) {
1186 $dollarquote =
false;
1188 $replacements =
array();
1190 while ( !feof( $fp ) ) {
1191 if ( $lineCallback ) {
1192 call_user_func( $lineCallback );
1194 $line = trim( fgets( $fp, 1024 ) );
1195 $sl = strlen(
$line ) - 1;
1205 if ( substr(
$line, 0, 8 ) ==
'/*$mw$*/' ) {
1206 if ( $dollarquote ) {
1207 $dollarquote =
false;
1208 $line = str_replace(
'/*$mw$*/',
'',
$line );
1211 $dollarquote =
true;
1213 } elseif ( !$dollarquote ) {
1214 if (
';' ==
$line[$sl] && ( $sl < 2 ||
';' !=
$line[$sl - 1] ) ) {
1226 $cmd = str_replace(
';;',
";", $cmd );
1227 if ( strtolower( substr( $cmd, 0, 6 ) ) ==
'define' ) {
1228 if ( preg_match(
'/^define\s*([^\s=]*)\s*=\s*\'\{\$([^\}]*)\}\'/', $cmd, $defines ) ) {
1229 $replacements[$defines[2]] = $defines[1];
1232 foreach ( $replacements
as $mwVar => $scVar ) {
1233 $cmd = str_replace(
'&' . $scVar .
'.',
'`{$' . $mwVar .
'}`', $cmd );
1236 $cmd = $this->replaceVars( $cmd );
1237 if ( $inputCallback ) {
1238 call_user_func( $inputCallback, $cmd );
1240 $res = $this->doQuery( $cmd );
1241 if ( $resultCallback ) {
1242 call_user_func( $resultCallback,
$res, $this );
1245 if (
false ===
$res ) {
1246 $err = $this->lastError();
1248 return "Query \"{$cmd}\" failed with error code \"$err\".\n";
1260 function selectDB( $db ) {
1261 $this->mDBname = $db;
1262 if ( $db ==
null || $db == $this->mUser ) {
1265 $sql =
'ALTER SESSION SET CURRENT_SCHEMA=' . strtoupper( $db );
1266 $stmt = oci_parse( $this->mConn, $sql );
1271 $e = oci_error( $stmt );
1272 if (
$e[
'code'] !=
'1435' ) {
1273 $this->reportQueryError(
$e[
'message'],
$e[
'code'], $sql, __METHOD__ );
1282 function strencode(
$s ) {
1283 return str_replace(
"'",
"''",
$s );
1286 function addQuotes(
$s ) {
1292 return "'" . $this->strencode(
$s ) .
"'";
1295 public function addIdentifierQuotes(
$s ) {
1303 public function removeIdentifierQuotes(
$s ) {
1304 return strpos(
$s,
'/*Q*/' ) ===
false ?
$s : substr(
$s, 5 );
1307 public function isQuotedIdentifier(
$s ) {
1308 return strpos(
$s,
'/*Q*/' ) !==
false;
1311 private function wrapFieldForWhere( $table, &$col, &$val ) {
1314 $col_info = $this->fieldInfoMulti( $table, $col );
1315 $col_type = $col_info !=
false ? $col_info->type() :
'CONSTANT';
1316 if ( $col_type ==
'CLOB' ) {
1317 $col =
'TO_CHAR(' . $col .
')';
1319 } elseif ( $col_type ==
'VARCHAR2' ) {
1324 private function wrapConditionsForWhere( $table, $conds, $parentCol =
null ) {
1326 foreach ( $conds
as $col => $val ) {
1327 if ( is_array( $val ) ) {
1328 $conds2[$col] = $this->wrapConditionsForWhere( $table, $val, $col );
1330 if ( is_numeric( $col ) && $parentCol !=
null ) {
1331 $this->wrapFieldForWhere( $table, $parentCol, $val );
1333 $this->wrapFieldForWhere( $table, $col, $val );
1335 $conds2[$col] = $val;
1342 function selectRow( $table,
$vars, $conds,
$fname = __METHOD__,
1345 if ( is_array( $conds ) ) {
1346 $conds = $this->wrapConditionsForWhere( $table, $conds );
1360 function makeSelectOptions(
$options ) {
1361 $preLimitTail = $postLimitTail =
'';
1364 $noKeyOptions =
array();
1366 if ( is_numeric( $key ) ) {
1367 $noKeyOptions[$option] =
true;
1371 $preLimitTail .= $this->makeGroupByWithHaving(
$options );
1373 $preLimitTail .= $this->makeOrderBy(
$options );
1375 if ( isset( $noKeyOptions[
'FOR UPDATE'] ) ) {
1376 $postLimitTail .=
' FOR UPDATE';
1379 if ( isset( $noKeyOptions[
'DISTINCT'] ) || isset( $noKeyOptions[
'DISTINCTROW'] ) ) {
1380 $startOpts .=
'DISTINCT';
1383 if ( isset(
$options[
'USE INDEX'] ) && !is_array(
$options[
'USE INDEX'] ) ) {
1384 $useIndex = $this->useIndexClause(
$options[
'USE INDEX'] );
1389 return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail );
1392 public function delete( $table, $conds,
$fname = __METHOD__ ) {
1393 if ( is_array( $conds ) ) {
1394 $conds = $this->wrapConditionsForWhere( $table, $conds );
1399 if ( $table == $this->
tableName(
'user' ) ) {
1400 $this->update(
'archive',
array(
'ar_user' => 0 ),
1401 array(
'ar_user' => $conds[
'user_id'] ),
$fname );
1402 $this->update(
'ipblocks',
array(
'ipb_user' => 0 ),
1403 array(
'ipb_user' => $conds[
'user_id'] ),
$fname );
1404 $this->update(
'image',
array(
'img_user' => 0 ),
1405 array(
'img_user' => $conds[
'user_id'] ),
$fname );
1406 $this->update(
'oldimage',
array(
'oi_user' => 0 ),
1407 array(
'oi_user' => $conds[
'user_id'] ),
$fname );
1408 $this->update(
'filearchive',
array(
'fa_deleted_user' => 0 ),
1409 array(
'fa_deleted_user' => $conds[
'user_id'] ),
$fname );
1410 $this->update(
'filearchive',
array(
'fa_user' => 0 ),
1411 array(
'fa_user' => $conds[
'user_id'] ),
$fname );
1412 $this->update(
'uploadstash',
array(
'us_user' => 0 ),
1413 array(
'us_user' => $conds[
'user_id'] ),
$fname );
1414 $this->update(
'recentchanges',
array(
'rc_user' => 0 ),
1415 array(
'rc_user' => $conds[
'user_id'] ),
$fname );
1416 $this->update(
'logging',
array(
'log_user' => 0 ),
1417 array(
'log_user' => $conds[
'user_id'] ),
$fname );
1418 } elseif ( $table == $this->
tableName(
'image' ) ) {
1419 $this->update(
'oldimage',
array(
'oi_name' => 0 ),
1420 array(
'oi_name' => $conds[
'img_name'] ),
$fname );
1423 return parent::delete( $table, $conds,
$fname );
1439 $opts = $this->makeUpdateOptions(
$options );
1440 $sql =
"UPDATE $opts $table SET ";
1443 foreach ( $values
as $col => &$val ) {
1444 $sqlSet = $this->fieldBindStatement( $table, $col, $val,
true );
1447 $sqlSet =
', ' . $sqlSet;
1454 if ( $conds !==
array() && $conds !==
'*' ) {
1455 $conds = $this->wrapConditionsForWhere( $table, $conds );
1456 $sql .=
' WHERE ' . $this->makeList( $conds,
LIST_AND );
1459 if ( ( $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ) ) ===
false ) {
1460 $e = oci_error( $this->mConn );
1461 $this->reportQueryError(
$e[
'message'],
$e[
'code'], $sql, __METHOD__ );
1465 foreach ( $values
as $col => &$val ) {
1466 $col_info = $this->fieldInfoMulti( $table, $col );
1467 $col_type = $col_info !=
false ? $col_info->type() :
'CONSTANT';
1469 if ( $val ===
null ) {
1471 } elseif ( $col_type !=
'BLOB' && $col_type !=
'CLOB' ) {
1472 if ( is_object( $val ) ) {
1473 $val = $val->getData();
1476 if ( preg_match(
'/^timestamp.*/i', $col_type ) == 1 && strtolower( $val ) ==
'infinity' ) {
1477 $val =
'31-12-2030 12:00:00.000000';
1481 if ( oci_bind_by_name( $stmt,
":$col", $val ) ===
false ) {
1482 $e = oci_error( $stmt );
1483 $this->reportQueryError(
$e[
'message'],
$e[
'code'], $sql, __METHOD__ );
1489 if ( ( $lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB ) ) ===
false ) {
1490 $e = oci_error( $stmt );
1494 if ( $col_type ==
'BLOB' ) {
1495 $lob[$col]->writeTemporary( $val );
1496 oci_bind_by_name( $stmt,
":$col", $lob[$col], -1, SQLT_BLOB );
1498 $lob[$col]->writeTemporary( $val );
1499 oci_bind_by_name( $stmt,
":$col", $lob[$col], -1, OCI_B_CLOB );
1506 if ( oci_execute( $stmt, $this->execFlags() ) ===
false ) {
1507 $e = oci_error( $stmt );
1508 if ( !$this->ignoreDupValOnIndex ||
$e[
'code'] !=
'1' ) {
1509 $this->reportQueryError(
$e[
'message'],
$e[
'code'], $sql, __METHOD__ );
1513 $this->mAffectedRows = oci_num_rows( $stmt );
1516 $this->mAffectedRows = oci_num_rows( $stmt );
1521 if ( isset( $lob ) ) {
1522 foreach ( $lob
as $lob_v ) {
1527 if ( !$this->mTrxLevel ) {
1528 oci_commit( $this->mConn );
1531 return oci_free_statement( $stmt );
1534 function bitNot( $field ) {
1536 return 'BITNOT(' . $field .
')';
1539 function bitAnd( $fieldLeft, $fieldRight ) {
1540 return 'BITAND(' . $fieldLeft .
', ' . $fieldRight .
')';
1543 function bitOr( $fieldLeft, $fieldRight ) {
1544 return 'BITOR(' . $fieldLeft .
', ' . $fieldRight .
')';
1547 function getDBname() {
1548 return $this->mDBname;
1551 function getServer() {
1552 return $this->mServer;
1555 public function buildGroupConcatField(
1556 $delim, $table, $field, $conds =
'', $join_conds =
array()
1558 $fld =
"LISTAGG($field," . $this->addQuotes( $delim ) .
") WITHIN GROUP (ORDER BY $field)";
1560 return '(' . $this->selectSQLText( $table, $fld, $conds,
null,
array(), $join_conds ) .
')';
1563 public function getSearchEngine() {
1564 return 'SearchOracle';
1567 public function getInfinity() {
1568 return '31-12-2030 12:00:00.000000';