Merge "LoginSignupSpecialPage: Reduce hackiness of "You are already logged in" warning"
[lhc/web/wiklou.git] / includes / db / DatabaseOracle.php
1 <?php
2 /**
3 * This is the Oracle database abstraction layer.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Database
22 */
23
24 /**
25 * The oci8 extension is fairly weak and doesn't support oci_num_rows, among
26 * other things. We use a wrapper class to handle that and other
27 * Oracle-specific bits, like converting column names back to lowercase.
28 * @ingroup Database
29 */
30 class ORAResult {
31 private $rows;
32 private $cursor;
33 private $nrows;
34
35 private $columns = [];
36
37 private function array_unique_md( $array_in ) {
38 $array_out = [];
39 $array_hashes = [];
40
41 foreach ( $array_in as $item ) {
42 $hash = md5( serialize( $item ) );
43 if ( !isset( $array_hashes[$hash] ) ) {
44 $array_hashes[$hash] = $hash;
45 $array_out[] = $item;
46 }
47 }
48
49 return $array_out;
50 }
51
52 /**
53 * @param IDatabase $db
54 * @param resource $stmt A valid OCI statement identifier
55 * @param bool $unique
56 */
57 function __construct( &$db, $stmt, $unique = false ) {
58 $this->db =& $db;
59
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__ );
64 $this->free();
65
66 return;
67 }
68
69 if ( $unique ) {
70 $this->rows = $this->array_unique_md( $this->rows );
71 $this->nrows = count( $this->rows );
72 }
73
74 if ( $this->nrows > 0 ) {
75 foreach ( $this->rows[0] as $k => $v ) {
76 $this->columns[$k] = strtolower( oci_field_name( $stmt, $k + 1 ) );
77 }
78 }
79
80 $this->cursor = 0;
81 oci_free_statement( $stmt );
82 }
83
84 public function free() {
85 unset( $this->db );
86 }
87
88 public function seek( $row ) {
89 $this->cursor = min( $row, $this->nrows );
90 }
91
92 public function numRows() {
93 return $this->nrows;
94 }
95
96 public function numFields() {
97 return count( $this->columns );
98 }
99
100 public function fetchObject() {
101 if ( $this->cursor >= $this->nrows ) {
102 return false;
103 }
104 $row = $this->rows[$this->cursor++];
105 $ret = new stdClass();
106 foreach ( $row as $k => $v ) {
107 $lc = $this->columns[$k];
108 $ret->$lc = $v;
109 }
110
111 return $ret;
112 }
113
114 public function fetchRow() {
115 if ( $this->cursor >= $this->nrows ) {
116 return false;
117 }
118
119 $row = $this->rows[$this->cursor++];
120 $ret = [];
121 foreach ( $row as $k => $v ) {
122 $lc = $this->columns[$k];
123 $ret[$lc] = $v;
124 $ret[$k] = $v;
125 }
126
127 return $ret;
128 }
129 }
130
131 /**
132 * @ingroup Database
133 */
134 class DatabaseOracle extends DatabaseBase {
135 /** @var resource */
136 protected $mLastResult = null;
137
138 /** @var int The number of rows affected as an integer */
139 protected $mAffectedRows;
140
141 /** @var int */
142 private $mInsertId = null;
143
144 /** @var bool */
145 private $ignoreDupValOnIndex = false;
146
147 /** @var bool|array */
148 private $sequenceData = null;
149
150 /** @var string Character set for Oracle database */
151 private $defaultCharset = 'AL32UTF8';
152
153 /** @var array */
154 private $mFieldInfoCache = [];
155
156 function __construct( array $p ) {
157 global $wgDBprefix;
158
159 if ( $p['tablePrefix'] == 'get from global' ) {
160 $p['tablePrefix'] = $wgDBprefix;
161 }
162 $p['tablePrefix'] = strtoupper( $p['tablePrefix'] );
163 parent::__construct( $p );
164 Hooks::run( 'DatabaseOraclePostInit', [ $this ] );
165 }
166
167 function __destruct() {
168 if ( $this->mOpened ) {
169 MediaWiki\suppressWarnings();
170 $this->close();
171 MediaWiki\restoreWarnings();
172 }
173 }
174
175 function getType() {
176 return 'oracle';
177 }
178
179 function cascadingDeletes() {
180 return true;
181 }
182
183 function cleanupTriggers() {
184 return true;
185 }
186
187 function strictIPs() {
188 return true;
189 }
190
191 function realTimestamps() {
192 return true;
193 }
194
195 function implicitGroupby() {
196 return false;
197 }
198
199 function implicitOrderby() {
200 return false;
201 }
202
203 function searchableIPs() {
204 return true;
205 }
206
207 /**
208 * Usually aborts on failure
209 * @param string $server
210 * @param string $user
211 * @param string $password
212 * @param string $dbName
213 * @throws DBConnectionError
214 * @return resource|null
215 */
216 function open( $server, $user, $password, $dbName ) {
217 global $wgDBOracleDRCP;
218 if ( !function_exists( 'oci_connect' ) ) {
219 throw new DBConnectionError(
220 $this,
221 "Oracle functions missing, have you compiled PHP with the --with-oci8 option?\n " .
222 "(Note: if you recently installed PHP, you may need to restart your webserver\n " .
223 "and database)\n" );
224 }
225
226 $this->close();
227 $this->mUser = $user;
228 $this->mPassword = $password;
229 // changed internal variables functions
230 // mServer now holds the TNS endpoint
231 // mDBname is schema name if different from username
232 if ( !$server ) {
233 // backward compatibillity (server used to be null and TNS was supplied in dbname)
234 $this->mServer = $dbName;
235 $this->mDBname = $user;
236 } else {
237 $this->mServer = $server;
238 if ( !$dbName ) {
239 $this->mDBname = $user;
240 } else {
241 $this->mDBname = $dbName;
242 }
243 }
244
245 if ( !strlen( $user ) ) { # e.g. the class is being loaded
246 return null;
247 }
248
249 if ( $wgDBOracleDRCP ) {
250 $this->setFlag( DBO_PERSISTENT );
251 }
252
253 $session_mode = $this->mFlags & DBO_SYSDBA ? OCI_SYSDBA : OCI_DEFAULT;
254
255 MediaWiki\suppressWarnings();
256 if ( $this->mFlags & DBO_PERSISTENT ) {
257 $this->mConn = oci_pconnect(
258 $this->mUser,
259 $this->mPassword,
260 $this->mServer,
261 $this->defaultCharset,
262 $session_mode
263 );
264 } elseif ( $this->mFlags & DBO_DEFAULT ) {
265 $this->mConn = oci_new_connect(
266 $this->mUser,
267 $this->mPassword,
268 $this->mServer,
269 $this->defaultCharset,
270 $session_mode
271 );
272 } else {
273 $this->mConn = oci_connect(
274 $this->mUser,
275 $this->mPassword,
276 $this->mServer,
277 $this->defaultCharset,
278 $session_mode
279 );
280 }
281 MediaWiki\restoreWarnings();
282
283 if ( $this->mUser != $this->mDBname ) {
284 // change current schema in session
285 $this->selectDB( $this->mDBname );
286 }
287
288 if ( !$this->mConn ) {
289 throw new DBConnectionError( $this, $this->lastError() );
290 }
291
292 $this->mOpened = true;
293
294 # removed putenv calls because they interfere with the system globaly
295 $this->doQuery( 'ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'' );
296 $this->doQuery( 'ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'' );
297 $this->doQuery( 'ALTER SESSION SET NLS_NUMERIC_CHARACTERS=\'.,\'' );
298
299 return $this->mConn;
300 }
301
302 /**
303 * Closes a database connection, if it is open
304 * Returns success, true if already closed
305 * @return bool
306 */
307 protected function closeConnection() {
308 return oci_close( $this->mConn );
309 }
310
311 function execFlags() {
312 return $this->mTrxLevel ? OCI_NO_AUTO_COMMIT : OCI_COMMIT_ON_SUCCESS;
313 }
314
315 protected function doQuery( $sql ) {
316 wfDebug( "SQL: [$sql]\n" );
317 if ( !StringUtils::isUtf8( $sql ) ) {
318 throw new InvalidArgumentException( "SQL encoding is invalid\n$sql" );
319 }
320
321 // handle some oracle specifics
322 // remove AS column/table/subquery namings
323 if ( !$this->getFlag( DBO_DDLMODE ) ) {
324 $sql = preg_replace( '/ as /i', ' ', $sql );
325 }
326
327 // Oracle has issues with UNION clause if the statement includes LOB fields
328 // So we do a UNION ALL and then filter the results array with array_unique
329 $union_unique = ( preg_match( '/\/\* UNION_UNIQUE \*\/ /', $sql ) != 0 );
330 // EXPLAIN syntax in Oracle is EXPLAIN PLAN FOR and it return nothing
331 // you have to select data from plan table after explain
332 $explain_id = MWTimestamp::getLocalInstance()->format( 'dmYHis' );
333
334 $sql = preg_replace(
335 '/^EXPLAIN /',
336 'EXPLAIN PLAN SET STATEMENT_ID = \'' . $explain_id . '\' FOR',
337 $sql,
338 1,
339 $explain_count
340 );
341
342 MediaWiki\suppressWarnings();
343
344 $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql );
345 if ( $stmt === false ) {
346 $e = oci_error( $this->mConn );
347 $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
348
349 return false;
350 }
351
352 if ( !oci_execute( $stmt, $this->execFlags() ) ) {
353 $e = oci_error( $stmt );
354 if ( !$this->ignoreDupValOnIndex || $e['code'] != '1' ) {
355 $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
356
357 return false;
358 }
359 }
360
361 MediaWiki\restoreWarnings();
362
363 if ( $explain_count > 0 ) {
364 return $this->doQuery( 'SELECT id, cardinality "ROWS" FROM plan_table ' .
365 'WHERE statement_id = \'' . $explain_id . '\'' );
366 } elseif ( oci_statement_type( $stmt ) == 'SELECT' ) {
367 return new ORAResult( $this, $stmt, $union_unique );
368 } else {
369 $this->mAffectedRows = oci_num_rows( $stmt );
370
371 return true;
372 }
373 }
374
375 function queryIgnore( $sql, $fname = '' ) {
376 return $this->query( $sql, $fname, true );
377 }
378
379 /**
380 * Frees resources associated with the LOB descriptor
381 * @param ResultWrapper|ORAResult $res
382 */
383 function freeResult( $res ) {
384 if ( $res instanceof ResultWrapper ) {
385 $res = $res->result;
386 }
387
388 $res->free();
389 }
390
391 /**
392 * @param ResultWrapper|ORAResult $res
393 * @return mixed
394 */
395 function fetchObject( $res ) {
396 if ( $res instanceof ResultWrapper ) {
397 $res = $res->result;
398 }
399
400 return $res->fetchObject();
401 }
402
403 /**
404 * @param ResultWrapper|ORAResult $res
405 * @return mixed
406 */
407 function fetchRow( $res ) {
408 if ( $res instanceof ResultWrapper ) {
409 $res = $res->result;
410 }
411
412 return $res->fetchRow();
413 }
414
415 /**
416 * @param ResultWrapper|ORAResult $res
417 * @return int
418 */
419 function numRows( $res ) {
420 if ( $res instanceof ResultWrapper ) {
421 $res = $res->result;
422 }
423
424 return $res->numRows();
425 }
426
427 /**
428 * @param ResultWrapper|ORAResult $res
429 * @return int
430 */
431 function numFields( $res ) {
432 if ( $res instanceof ResultWrapper ) {
433 $res = $res->result;
434 }
435
436 return $res->numFields();
437 }
438
439 function fieldName( $stmt, $n ) {
440 return oci_field_name( $stmt, $n );
441 }
442
443 /**
444 * This must be called after nextSequenceVal
445 * @return null|int
446 */
447 function insertId() {
448 return $this->mInsertId;
449 }
450
451 /**
452 * @param mixed $res
453 * @param int $row
454 */
455 function dataSeek( $res, $row ) {
456 if ( $res instanceof ORAResult ) {
457 $res->seek( $row );
458 } else {
459 $res->result->seek( $row );
460 }
461 }
462
463 function lastError() {
464 if ( $this->mConn === false ) {
465 $e = oci_error();
466 } else {
467 $e = oci_error( $this->mConn );
468 }
469
470 return $e['message'];
471 }
472
473 function lastErrno() {
474 if ( $this->mConn === false ) {
475 $e = oci_error();
476 } else {
477 $e = oci_error( $this->mConn );
478 }
479
480 return $e['code'];
481 }
482
483 function affectedRows() {
484 return $this->mAffectedRows;
485 }
486
487 /**
488 * Returns information about an index
489 * If errors are explicitly ignored, returns NULL on failure
490 * @param string $table
491 * @param string $index
492 * @param string $fname
493 * @return bool
494 */
495 function indexInfo( $table, $index, $fname = __METHOD__ ) {
496 return false;
497 }
498
499 function indexUnique( $table, $index, $fname = __METHOD__ ) {
500 return false;
501 }
502
503 function insert( $table, $a, $fname = __METHOD__, $options = [] ) {
504 if ( !count( $a ) ) {
505 return true;
506 }
507
508 if ( !is_array( $options ) ) {
509 $options = [ $options ];
510 }
511
512 if ( in_array( 'IGNORE', $options ) ) {
513 $this->ignoreDupValOnIndex = true;
514 }
515
516 if ( !is_array( reset( $a ) ) ) {
517 $a = [ $a ];
518 }
519
520 foreach ( $a as &$row ) {
521 $this->insertOneRow( $table, $row, $fname );
522 }
523 $retVal = true;
524
525 if ( in_array( 'IGNORE', $options ) ) {
526 $this->ignoreDupValOnIndex = false;
527 }
528
529 return $retVal;
530 }
531
532 private function fieldBindStatement( $table, $col, &$val, $includeCol = false ) {
533 $col_info = $this->fieldInfoMulti( $table, $col );
534 $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
535
536 $bind = '';
537 if ( is_numeric( $col ) ) {
538 $bind = $val;
539 $val = null;
540
541 return $bind;
542 } elseif ( $includeCol ) {
543 $bind = "$col = ";
544 }
545
546 if ( $val == '' && $val !== 0 && $col_type != 'BLOB' && $col_type != 'CLOB' ) {
547 $val = null;
548 }
549
550 if ( $val === 'NULL' ) {
551 $val = null;
552 }
553
554 if ( $val === null ) {
555 if ( $col_info != false && $col_info->isNullable() == 0 && $col_info->defaultValue() != null ) {
556 $bind .= 'DEFAULT';
557 } else {
558 $bind .= 'NULL';
559 }
560 } else {
561 $bind .= ':' . $col;
562 }
563
564 return $bind;
565 }
566
567 /**
568 * @param string $table
569 * @param array $row
570 * @param string $fname
571 * @return bool
572 * @throws DBUnexpectedError
573 */
574 private function insertOneRow( $table, $row, $fname ) {
575 global $wgContLang;
576
577 $table = $this->tableName( $table );
578 // "INSERT INTO tables (a, b, c)"
579 $sql = "INSERT INTO " . $table . " (" . implode( ',', array_keys( $row ) ) . ')';
580 $sql .= " VALUES (";
581
582 // for each value, append ":key"
583 $first = true;
584 foreach ( $row as $col => &$val ) {
585 if ( !$first ) {
586 $sql .= ', ';
587 } else {
588 $first = false;
589 }
590 if ( $this->isQuotedIdentifier( $val ) ) {
591 $sql .= $this->removeIdentifierQuotes( $val );
592 unset( $row[$col] );
593 } else {
594 $sql .= $this->fieldBindStatement( $table, $col, $val );
595 }
596 }
597 $sql .= ')';
598
599 $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql );
600 if ( $stmt === false ) {
601 $e = oci_error( $this->mConn );
602 $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
603
604 return false;
605 }
606 foreach ( $row as $col => &$val ) {
607 $col_info = $this->fieldInfoMulti( $table, $col );
608 $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
609
610 if ( $val === null ) {
611 // do nothing ... null was inserted in statement creation
612 } elseif ( $col_type != 'BLOB' && $col_type != 'CLOB' ) {
613 if ( is_object( $val ) ) {
614 $val = $val->fetch();
615 }
616
617 // backward compatibility
618 if ( preg_match( '/^timestamp.*/i', $col_type ) == 1 && strtolower( $val ) == 'infinity' ) {
619 $val = $this->getInfinity();
620 }
621
622 $val = ( $wgContLang != null ) ? $wgContLang->checkTitleEncoding( $val ) : $val;
623 if ( oci_bind_by_name( $stmt, ":$col", $val, -1, SQLT_CHR ) === false ) {
624 $e = oci_error( $stmt );
625 $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
626
627 return false;
628 }
629 } else {
630 /** @var OCI_Lob[] $lob */
631 $lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB );
632 if ( $lob[$col] === false ) {
633 $e = oci_error( $stmt );
634 throw new DBUnexpectedError( $this, "Cannot create LOB descriptor: " . $e['message'] );
635 }
636
637 if ( is_object( $val ) ) {
638 $val = $val->fetch();
639 }
640
641 if ( $col_type == 'BLOB' ) {
642 $lob[$col]->writeTemporary( $val, OCI_TEMP_BLOB );
643 oci_bind_by_name( $stmt, ":$col", $lob[$col], -1, OCI_B_BLOB );
644 } else {
645 $lob[$col]->writeTemporary( $val, OCI_TEMP_CLOB );
646 oci_bind_by_name( $stmt, ":$col", $lob[$col], -1, OCI_B_CLOB );
647 }
648 }
649 }
650
651 MediaWiki\suppressWarnings();
652
653 if ( oci_execute( $stmt, $this->execFlags() ) === false ) {
654 $e = oci_error( $stmt );
655 if ( !$this->ignoreDupValOnIndex || $e['code'] != '1' ) {
656 $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
657
658 return false;
659 } else {
660 $this->mAffectedRows = oci_num_rows( $stmt );
661 }
662 } else {
663 $this->mAffectedRows = oci_num_rows( $stmt );
664 }
665
666 MediaWiki\restoreWarnings();
667
668 if ( isset( $lob ) ) {
669 foreach ( $lob as $lob_v ) {
670 $lob_v->free();
671 }
672 }
673
674 if ( !$this->mTrxLevel ) {
675 oci_commit( $this->mConn );
676 }
677
678 return oci_free_statement( $stmt );
679 }
680
681 function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
682 $insertOptions = [], $selectOptions = []
683 ) {
684 $destTable = $this->tableName( $destTable );
685 if ( !is_array( $selectOptions ) ) {
686 $selectOptions = [ $selectOptions ];
687 }
688 list( $startOpts, $useIndex, $tailOpts, $ignoreIndex ) =
689 $this->makeSelectOptions( $selectOptions );
690 if ( is_array( $srcTable ) ) {
691 $srcTable = implode( ',', array_map( [ &$this, 'tableName' ], $srcTable ) );
692 } else {
693 $srcTable = $this->tableName( $srcTable );
694 }
695
696 $sequenceData = $this->getSequenceData( $destTable );
697 if ( $sequenceData !== false &&
698 !isset( $varMap[$sequenceData['column']] )
699 ) {
700 $varMap[$sequenceData['column']] = 'GET_SEQUENCE_VALUE(\'' . $sequenceData['sequence'] . '\')';
701 }
702
703 // count-alias subselect fields to avoid abigious definition errors
704 $i = 0;
705 foreach ( $varMap as &$val ) {
706 $val = $val . ' field' . ( $i++ );
707 }
708
709 $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
710 " SELECT $startOpts " . implode( ',', $varMap ) .
711 " FROM $srcTable $useIndex $ignoreIndex ";
712 if ( $conds != '*' ) {
713 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
714 }
715 $sql .= " $tailOpts";
716
717 if ( in_array( 'IGNORE', $insertOptions ) ) {
718 $this->ignoreDupValOnIndex = true;
719 }
720
721 $retval = $this->query( $sql, $fname );
722
723 if ( in_array( 'IGNORE', $insertOptions ) ) {
724 $this->ignoreDupValOnIndex = false;
725 }
726
727 return $retval;
728 }
729
730 public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
731 $fname = __METHOD__
732 ) {
733 if ( !count( $rows ) ) {
734 return true; // nothing to do
735 }
736
737 if ( !is_array( reset( $rows ) ) ) {
738 $rows = [ $rows ];
739 }
740
741 $sequenceData = $this->getSequenceData( $table );
742 if ( $sequenceData !== false ) {
743 // add sequence column to each list of columns, when not set
744 foreach ( $rows as &$row ) {
745 if ( !isset( $row[$sequenceData['column']] ) ) {
746 $row[$sequenceData['column']] =
747 $this->addIdentifierQuotes( 'GET_SEQUENCE_VALUE(\'' .
748 $sequenceData['sequence'] . '\')' );
749 }
750 }
751 }
752
753 return parent::upsert( $table, $rows, $uniqueIndexes, $set, $fname );
754 }
755
756 function tableName( $name, $format = 'quoted' ) {
757 /*
758 Replace reserved words with better ones
759 Using uppercase because that's the only way Oracle can handle
760 quoted tablenames
761 */
762 switch ( $name ) {
763 case 'user':
764 $name = 'MWUSER';
765 break;
766 case 'text':
767 $name = 'PAGECONTENT';
768 break;
769 }
770
771 return strtoupper( parent::tableName( $name, $format ) );
772 }
773
774 function tableNameInternal( $name ) {
775 $name = $this->tableName( $name );
776
777 return preg_replace( '/.*\.(.*)/', '$1', $name );
778 }
779
780 /**
781 * Return the next in a sequence, save the value for retrieval via insertId()
782 *
783 * @param string $seqName
784 * @return null|int
785 */
786 function nextSequenceValue( $seqName ) {
787 $res = $this->query( "SELECT $seqName.nextval FROM dual" );
788 $row = $this->fetchRow( $res );
789 $this->mInsertId = $row[0];
790
791 return $this->mInsertId;
792 }
793
794 /**
795 * Return sequence_name if table has a sequence
796 *
797 * @param string $table
798 * @return bool
799 */
800 private function getSequenceData( $table ) {
801 if ( $this->sequenceData == null ) {
802 $result = $this->doQuery( "SELECT lower(asq.sequence_name),
803 lower(atc.table_name),
804 lower(atc.column_name)
805 FROM all_sequences asq, all_tab_columns atc
806 WHERE decode(
807 atc.table_name,
808 '{$this->mTablePrefix}MWUSER',
809 '{$this->mTablePrefix}USER',
810 atc.table_name
811 ) || '_' ||
812 atc.column_name || '_SEQ' = '{$this->mTablePrefix}' || asq.sequence_name
813 AND asq.sequence_owner = upper('{$this->mDBname}')
814 AND atc.owner = upper('{$this->mDBname}')" );
815
816 while ( ( $row = $result->fetchRow() ) !== false ) {
817 $this->sequenceData[$row[1]] = [
818 'sequence' => $row[0],
819 'column' => $row[2]
820 ];
821 }
822 }
823 $table = strtolower( $this->removeIdentifierQuotes( $this->tableName( $table ) ) );
824
825 return ( isset( $this->sequenceData[$table] ) ) ? $this->sequenceData[$table] : false;
826 }
827
828 /**
829 * Returns the size of a text field, or -1 for "unlimited"
830 *
831 * @param string $table
832 * @param string $field
833 * @return mixed
834 */
835 function textFieldSize( $table, $field ) {
836 $fieldInfoData = $this->fieldInfo( $table, $field );
837
838 return $fieldInfoData->maxLength();
839 }
840
841 function limitResult( $sql, $limit, $offset = false ) {
842 if ( $offset === false ) {
843 $offset = 0;
844 }
845
846 return "SELECT * FROM ($sql) WHERE rownum >= (1 + $offset) AND rownum < (1 + $limit + $offset)";
847 }
848
849 function encodeBlob( $b ) {
850 return new Blob( $b );
851 }
852
853 function decodeBlob( $b ) {
854 if ( $b instanceof Blob ) {
855 $b = $b->fetch();
856 }
857
858 return $b;
859 }
860
861 function unionQueries( $sqls, $all ) {
862 $glue = ' UNION ALL ';
863
864 return 'SELECT * ' . ( $all ? '' : '/* UNION_UNIQUE */ ' ) .
865 'FROM (' . implode( $glue, $sqls ) . ')';
866 }
867
868 function wasDeadlock() {
869 return $this->lastErrno() == 'OCI-00060';
870 }
871
872 function duplicateTableStructure( $oldName, $newName, $temporary = false,
873 $fname = __METHOD__
874 ) {
875 $temporary = $temporary ? 'TRUE' : 'FALSE';
876
877 $newName = strtoupper( $newName );
878 $oldName = strtoupper( $oldName );
879
880 $tabName = substr( $newName, strlen( $this->mTablePrefix ) );
881 $oldPrefix = substr( $oldName, 0, strlen( $oldName ) - strlen( $tabName ) );
882 $newPrefix = strtoupper( $this->mTablePrefix );
883
884 return $this->doQuery( "BEGIN DUPLICATE_TABLE( '$tabName', " .
885 "'$oldPrefix', '$newPrefix', $temporary ); END;" );
886 }
887
888 function listTables( $prefix = null, $fname = __METHOD__ ) {
889 $listWhere = '';
890 if ( !empty( $prefix ) ) {
891 $listWhere = ' AND table_name LIKE \'' . strtoupper( $prefix ) . '%\'';
892 }
893
894 $owner = strtoupper( $this->mDBname );
895 $result = $this->doQuery( "SELECT table_name FROM all_tables " .
896 "WHERE owner='$owner' AND table_name NOT LIKE '%!_IDX\$_' ESCAPE '!' $listWhere" );
897
898 // dirty code ... i know
899 $endArray = [];
900 $endArray[] = strtoupper( $prefix . 'MWUSER' );
901 $endArray[] = strtoupper( $prefix . 'PAGE' );
902 $endArray[] = strtoupper( $prefix . 'IMAGE' );
903 $fixedOrderTabs = $endArray;
904 while ( ( $row = $result->fetchRow() ) !== false ) {
905 if ( !in_array( $row['table_name'], $fixedOrderTabs ) ) {
906 $endArray[] = $row['table_name'];
907 }
908 }
909
910 return $endArray;
911 }
912
913 public function dropTable( $tableName, $fName = __METHOD__ ) {
914 $tableName = $this->tableName( $tableName );
915 if ( !$this->tableExists( $tableName ) ) {
916 return false;
917 }
918
919 return $this->doQuery( "DROP TABLE $tableName CASCADE CONSTRAINTS PURGE" );
920 }
921
922 function timestamp( $ts = 0 ) {
923 return wfTimestamp( TS_ORACLE, $ts );
924 }
925
926 /**
927 * Return aggregated value function call
928 *
929 * @param array $valuedata
930 * @param string $valuename
931 * @return mixed
932 */
933 public function aggregateValue( $valuedata, $valuename = 'value' ) {
934 return $valuedata;
935 }
936
937 /**
938 * @return string Wikitext of a link to the server software's web site
939 */
940 public function getSoftwareLink() {
941 return '[{{int:version-db-oracle-url}} Oracle]';
942 }
943
944 /**
945 * @return string Version information from the database
946 */
947 function getServerVersion() {
948 // better version number, fallback on driver
949 $rset = $this->doQuery(
950 'SELECT version FROM product_component_version ' .
951 'WHERE UPPER(product) LIKE \'ORACLE DATABASE%\''
952 );
953 $row = $rset->fetchRow();
954 if ( !$row ) {
955 return oci_server_version( $this->mConn );
956 }
957
958 return $row['version'];
959 }
960
961 /**
962 * Query whether a given index exists
963 * @param string $table
964 * @param string $index
965 * @param string $fname
966 * @return bool
967 */
968 function indexExists( $table, $index, $fname = __METHOD__ ) {
969 $table = $this->tableName( $table );
970 $table = strtoupper( $this->removeIdentifierQuotes( $table ) );
971 $index = strtoupper( $index );
972 $owner = strtoupper( $this->mDBname );
973 $sql = "SELECT 1 FROM all_indexes WHERE owner='$owner' AND index_name='{$table}_{$index}'";
974 $res = $this->doQuery( $sql );
975 if ( $res ) {
976 $count = $res->numRows();
977 $res->free();
978 } else {
979 $count = 0;
980 }
981
982 return $count != 0;
983 }
984
985 /**
986 * Query whether a given table exists (in the given schema, or the default mw one if not given)
987 * @param string $table
988 * @param string $fname
989 * @return bool
990 */
991 function tableExists( $table, $fname = __METHOD__ ) {
992 $table = $this->tableName( $table );
993 $table = $this->addQuotes( strtoupper( $this->removeIdentifierQuotes( $table ) ) );
994 $owner = $this->addQuotes( strtoupper( $this->mDBname ) );
995 $sql = "SELECT 1 FROM all_tables WHERE owner=$owner AND table_name=$table";
996 $res = $this->doQuery( $sql );
997 if ( $res && $res->numRows() > 0 ) {
998 $exists = true;
999 } else {
1000 $exists = false;
1001 }
1002
1003 $res->free();
1004
1005 return $exists;
1006 }
1007
1008 /**
1009 * Function translates mysql_fetch_field() functionality on ORACLE.
1010 * Caching is present for reducing query time.
1011 * For internal calls. Use fieldInfo for normal usage.
1012 * Returns false if the field doesn't exist
1013 *
1014 * @param array|string $table
1015 * @param string $field
1016 * @return ORAField|ORAResult
1017 */
1018 private function fieldInfoMulti( $table, $field ) {
1019 $field = strtoupper( $field );
1020 if ( is_array( $table ) ) {
1021 $table = array_map( [ &$this, 'tableNameInternal' ], $table );
1022 $tableWhere = 'IN (';
1023 foreach ( $table as &$singleTable ) {
1024 $singleTable = $this->removeIdentifierQuotes( $singleTable );
1025 if ( isset( $this->mFieldInfoCache["$singleTable.$field"] ) ) {
1026 return $this->mFieldInfoCache["$singleTable.$field"];
1027 }
1028 $tableWhere .= '\'' . $singleTable . '\',';
1029 }
1030 $tableWhere = rtrim( $tableWhere, ',' ) . ')';
1031 } else {
1032 $table = $this->removeIdentifierQuotes( $this->tableNameInternal( $table ) );
1033 if ( isset( $this->mFieldInfoCache["$table.$field"] ) ) {
1034 return $this->mFieldInfoCache["$table.$field"];
1035 }
1036 $tableWhere = '= \'' . $table . '\'';
1037 }
1038
1039 $fieldInfoStmt = oci_parse(
1040 $this->mConn,
1041 'SELECT * FROM wiki_field_info_full WHERE table_name ' .
1042 $tableWhere . ' and column_name = \'' . $field . '\''
1043 );
1044 if ( oci_execute( $fieldInfoStmt, $this->execFlags() ) === false ) {
1045 $e = oci_error( $fieldInfoStmt );
1046 $this->reportQueryError( $e['message'], $e['code'], 'fieldInfo QUERY', __METHOD__ );
1047
1048 return false;
1049 }
1050 $res = new ORAResult( $this, $fieldInfoStmt );
1051 if ( $res->numRows() == 0 ) {
1052 if ( is_array( $table ) ) {
1053 foreach ( $table as &$singleTable ) {
1054 $this->mFieldInfoCache["$singleTable.$field"] = false;
1055 }
1056 } else {
1057 $this->mFieldInfoCache["$table.$field"] = false;
1058 }
1059 $fieldInfoTemp = null;
1060 } else {
1061 $fieldInfoTemp = new ORAField( $res->fetchRow() );
1062 $table = $fieldInfoTemp->tableName();
1063 $this->mFieldInfoCache["$table.$field"] = $fieldInfoTemp;
1064 }
1065 $res->free();
1066
1067 return $fieldInfoTemp;
1068 }
1069
1070 /**
1071 * @throws DBUnexpectedError
1072 * @param string $table
1073 * @param string $field
1074 * @return ORAField
1075 */
1076 function fieldInfo( $table, $field ) {
1077 if ( is_array( $table ) ) {
1078 throw new DBUnexpectedError( $this, 'DatabaseOracle::fieldInfo called with table array!' );
1079 }
1080
1081 return $this->fieldInfoMulti( $table, $field );
1082 }
1083
1084 protected function doBegin( $fname = __METHOD__ ) {
1085 $this->mTrxLevel = 1;
1086 $this->doQuery( 'SET CONSTRAINTS ALL DEFERRED' );
1087 }
1088
1089 protected function doCommit( $fname = __METHOD__ ) {
1090 if ( $this->mTrxLevel ) {
1091 $ret = oci_commit( $this->mConn );
1092 if ( !$ret ) {
1093 throw new DBUnexpectedError( $this, $this->lastError() );
1094 }
1095 $this->mTrxLevel = 0;
1096 $this->doQuery( 'SET CONSTRAINTS ALL IMMEDIATE' );
1097 }
1098 }
1099
1100 protected function doRollback( $fname = __METHOD__ ) {
1101 if ( $this->mTrxLevel ) {
1102 oci_rollback( $this->mConn );
1103 $this->mTrxLevel = 0;
1104 $this->doQuery( 'SET CONSTRAINTS ALL IMMEDIATE' );
1105 }
1106 }
1107
1108 /**
1109 * defines must comply with ^define\s*([^\s=]*)\s*=\s?'\{\$([^\}]*)\}';
1110 *
1111 * @param resource $fp
1112 * @param bool|string $lineCallback
1113 * @param bool|callable $resultCallback
1114 * @param string $fname
1115 * @param bool|callable $inputCallback
1116 * @return bool|string
1117 */
1118 function sourceStream( $fp, $lineCallback = false, $resultCallback = false,
1119 $fname = __METHOD__, $inputCallback = false ) {
1120 $cmd = '';
1121 $done = false;
1122 $dollarquote = false;
1123
1124 $replacements = [];
1125
1126 while ( !feof( $fp ) ) {
1127 if ( $lineCallback ) {
1128 call_user_func( $lineCallback );
1129 }
1130 $line = trim( fgets( $fp, 1024 ) );
1131 $sl = strlen( $line ) - 1;
1132
1133 if ( $sl < 0 ) {
1134 continue;
1135 }
1136 if ( '-' == $line[0] && '-' == $line[1] ) {
1137 continue;
1138 }
1139
1140 // Allow dollar quoting for function declarations
1141 if ( substr( $line, 0, 8 ) == '/*$mw$*/' ) {
1142 if ( $dollarquote ) {
1143 $dollarquote = false;
1144 $line = str_replace( '/*$mw$*/', '', $line ); // remove dollarquotes
1145 $done = true;
1146 } else {
1147 $dollarquote = true;
1148 }
1149 } elseif ( !$dollarquote ) {
1150 if ( ';' == $line[$sl] && ( $sl < 2 || ';' != $line[$sl - 1] ) ) {
1151 $done = true;
1152 $line = substr( $line, 0, $sl );
1153 }
1154 }
1155
1156 if ( $cmd != '' ) {
1157 $cmd .= ' ';
1158 }
1159 $cmd .= "$line\n";
1160
1161 if ( $done ) {
1162 $cmd = str_replace( ';;', ";", $cmd );
1163 if ( strtolower( substr( $cmd, 0, 6 ) ) == 'define' ) {
1164 if ( preg_match( '/^define\s*([^\s=]*)\s*=\s*\'\{\$([^\}]*)\}\'/', $cmd, $defines ) ) {
1165 $replacements[$defines[2]] = $defines[1];
1166 }
1167 } else {
1168 foreach ( $replacements as $mwVar => $scVar ) {
1169 $cmd = str_replace( '&' . $scVar . '.', '`{$' . $mwVar . '}`', $cmd );
1170 }
1171
1172 $cmd = $this->replaceVars( $cmd );
1173 if ( $inputCallback ) {
1174 call_user_func( $inputCallback, $cmd );
1175 }
1176 $res = $this->doQuery( $cmd );
1177 if ( $resultCallback ) {
1178 call_user_func( $resultCallback, $res, $this );
1179 }
1180
1181 if ( false === $res ) {
1182 $err = $this->lastError();
1183
1184 return "Query \"{$cmd}\" failed with error code \"$err\".\n";
1185 }
1186 }
1187
1188 $cmd = '';
1189 $done = false;
1190 }
1191 }
1192
1193 return true;
1194 }
1195
1196 function selectDB( $db ) {
1197 $this->mDBname = $db;
1198 if ( $db == null || $db == $this->mUser ) {
1199 return true;
1200 }
1201 $sql = 'ALTER SESSION SET CURRENT_SCHEMA=' . strtoupper( $db );
1202 $stmt = oci_parse( $this->mConn, $sql );
1203 MediaWiki\suppressWarnings();
1204 $success = oci_execute( $stmt );
1205 MediaWiki\restoreWarnings();
1206 if ( !$success ) {
1207 $e = oci_error( $stmt );
1208 if ( $e['code'] != '1435' ) {
1209 $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
1210 }
1211
1212 return false;
1213 }
1214
1215 return true;
1216 }
1217
1218 function strencode( $s ) {
1219 return str_replace( "'", "''", $s );
1220 }
1221
1222 function addQuotes( $s ) {
1223 global $wgContLang;
1224 if ( isset( $wgContLang->mLoaded ) && $wgContLang->mLoaded ) {
1225 $s = $wgContLang->checkTitleEncoding( $s );
1226 }
1227
1228 return "'" . $this->strencode( $s ) . "'";
1229 }
1230
1231 public function addIdentifierQuotes( $s ) {
1232 if ( !$this->getFlag( DBO_DDLMODE ) ) {
1233 $s = '/*Q*/' . $s;
1234 }
1235
1236 return $s;
1237 }
1238
1239 public function removeIdentifierQuotes( $s ) {
1240 return strpos( $s, '/*Q*/' ) === false ? $s : substr( $s, 5 );
1241 }
1242
1243 public function isQuotedIdentifier( $s ) {
1244 return strpos( $s, '/*Q*/' ) !== false;
1245 }
1246
1247 private function wrapFieldForWhere( $table, &$col, &$val ) {
1248 global $wgContLang;
1249
1250 $col_info = $this->fieldInfoMulti( $table, $col );
1251 $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
1252 if ( $col_type == 'CLOB' ) {
1253 $col = 'TO_CHAR(' . $col . ')';
1254 $val = $wgContLang->checkTitleEncoding( $val );
1255 } elseif ( $col_type == 'VARCHAR2' ) {
1256 $val = $wgContLang->checkTitleEncoding( $val );
1257 }
1258 }
1259
1260 private function wrapConditionsForWhere( $table, $conds, $parentCol = null ) {
1261 $conds2 = [];
1262 foreach ( $conds as $col => $val ) {
1263 if ( is_array( $val ) ) {
1264 $conds2[$col] = $this->wrapConditionsForWhere( $table, $val, $col );
1265 } else {
1266 if ( is_numeric( $col ) && $parentCol != null ) {
1267 $this->wrapFieldForWhere( $table, $parentCol, $val );
1268 } else {
1269 $this->wrapFieldForWhere( $table, $col, $val );
1270 }
1271 $conds2[$col] = $val;
1272 }
1273 }
1274
1275 return $conds2;
1276 }
1277
1278 function selectRow( $table, $vars, $conds, $fname = __METHOD__,
1279 $options = [], $join_conds = []
1280 ) {
1281 if ( is_array( $conds ) ) {
1282 $conds = $this->wrapConditionsForWhere( $table, $conds );
1283 }
1284
1285 return parent::selectRow( $table, $vars, $conds, $fname, $options, $join_conds );
1286 }
1287
1288 /**
1289 * Returns an optional USE INDEX clause to go after the table, and a
1290 * string to go at the end of the query
1291 *
1292 * @param array $options An associative array of options to be turned into
1293 * an SQL query, valid keys are listed in the function.
1294 * @return array
1295 */
1296 function makeSelectOptions( $options ) {
1297 $preLimitTail = $postLimitTail = '';
1298 $startOpts = '';
1299
1300 $noKeyOptions = [];
1301 foreach ( $options as $key => $option ) {
1302 if ( is_numeric( $key ) ) {
1303 $noKeyOptions[$option] = true;
1304 }
1305 }
1306
1307 $preLimitTail .= $this->makeGroupByWithHaving( $options );
1308
1309 $preLimitTail .= $this->makeOrderBy( $options );
1310
1311 if ( isset( $noKeyOptions['FOR UPDATE'] ) ) {
1312 $postLimitTail .= ' FOR UPDATE';
1313 }
1314
1315 if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) {
1316 $startOpts .= 'DISTINCT';
1317 }
1318
1319 if ( isset( $options['USE INDEX'] ) && !is_array( $options['USE INDEX'] ) ) {
1320 $useIndex = $this->useIndexClause( $options['USE INDEX'] );
1321 } else {
1322 $useIndex = '';
1323 }
1324
1325 if ( isset( $options['IGNORE INDEX'] ) && !is_array( $options['IGNORE INDEX'] ) ) {
1326 $ignoreIndex = $this->ignoreIndexClause( $options['IGNORE INDEX'] );
1327 } else {
1328 $ignoreIndex = '';
1329 }
1330
1331 return [ $startOpts, $useIndex, $preLimitTail, $postLimitTail, $ignoreIndex ];
1332 }
1333
1334 public function delete( $table, $conds, $fname = __METHOD__ ) {
1335 if ( is_array( $conds ) ) {
1336 $conds = $this->wrapConditionsForWhere( $table, $conds );
1337 }
1338 // a hack for deleting pages, users and images (which have non-nullable FKs)
1339 // all deletions on these tables have transactions so final failure rollbacks these updates
1340 $table = $this->tableName( $table );
1341 if ( $table == $this->tableName( 'user' ) ) {
1342 $this->update( 'archive', [ 'ar_user' => 0 ],
1343 [ 'ar_user' => $conds['user_id'] ], $fname );
1344 $this->update( 'ipblocks', [ 'ipb_user' => 0 ],
1345 [ 'ipb_user' => $conds['user_id'] ], $fname );
1346 $this->update( 'image', [ 'img_user' => 0 ],
1347 [ 'img_user' => $conds['user_id'] ], $fname );
1348 $this->update( 'oldimage', [ 'oi_user' => 0 ],
1349 [ 'oi_user' => $conds['user_id'] ], $fname );
1350 $this->update( 'filearchive', [ 'fa_deleted_user' => 0 ],
1351 [ 'fa_deleted_user' => $conds['user_id'] ], $fname );
1352 $this->update( 'filearchive', [ 'fa_user' => 0 ],
1353 [ 'fa_user' => $conds['user_id'] ], $fname );
1354 $this->update( 'uploadstash', [ 'us_user' => 0 ],
1355 [ 'us_user' => $conds['user_id'] ], $fname );
1356 $this->update( 'recentchanges', [ 'rc_user' => 0 ],
1357 [ 'rc_user' => $conds['user_id'] ], $fname );
1358 $this->update( 'logging', [ 'log_user' => 0 ],
1359 [ 'log_user' => $conds['user_id'] ], $fname );
1360 } elseif ( $table == $this->tableName( 'image' ) ) {
1361 $this->update( 'oldimage', [ 'oi_name' => 0 ],
1362 [ 'oi_name' => $conds['img_name'] ], $fname );
1363 }
1364
1365 return parent::delete( $table, $conds, $fname );
1366 }
1367
1368 /**
1369 * @param string $table
1370 * @param array $values
1371 * @param array $conds
1372 * @param string $fname
1373 * @param array $options
1374 * @return bool
1375 * @throws DBUnexpectedError
1376 */
1377 function update( $table, $values, $conds, $fname = __METHOD__, $options = [] ) {
1378 global $wgContLang;
1379
1380 $table = $this->tableName( $table );
1381 $opts = $this->makeUpdateOptions( $options );
1382 $sql = "UPDATE $opts $table SET ";
1383
1384 $first = true;
1385 foreach ( $values as $col => &$val ) {
1386 $sqlSet = $this->fieldBindStatement( $table, $col, $val, true );
1387
1388 if ( !$first ) {
1389 $sqlSet = ', ' . $sqlSet;
1390 } else {
1391 $first = false;
1392 }
1393 $sql .= $sqlSet;
1394 }
1395
1396 if ( $conds !== [] && $conds !== '*' ) {
1397 $conds = $this->wrapConditionsForWhere( $table, $conds );
1398 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
1399 }
1400
1401 $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql );
1402 if ( $stmt === false ) {
1403 $e = oci_error( $this->mConn );
1404 $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
1405
1406 return false;
1407 }
1408 foreach ( $values as $col => &$val ) {
1409 $col_info = $this->fieldInfoMulti( $table, $col );
1410 $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
1411
1412 if ( $val === null ) {
1413 // do nothing ... null was inserted in statement creation
1414 } elseif ( $col_type != 'BLOB' && $col_type != 'CLOB' ) {
1415 if ( is_object( $val ) ) {
1416 $val = $val->getData();
1417 }
1418
1419 if ( preg_match( '/^timestamp.*/i', $col_type ) == 1 && strtolower( $val ) == 'infinity' ) {
1420 $val = '31-12-2030 12:00:00.000000';
1421 }
1422
1423 $val = ( $wgContLang != null ) ? $wgContLang->checkTitleEncoding( $val ) : $val;
1424 if ( oci_bind_by_name( $stmt, ":$col", $val ) === false ) {
1425 $e = oci_error( $stmt );
1426 $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
1427
1428 return false;
1429 }
1430 } else {
1431 /** @var OCI_Lob[] $lob */
1432 $lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB );
1433 if ( $lob[$col] === false ) {
1434 $e = oci_error( $stmt );
1435 throw new DBUnexpectedError( $this, "Cannot create LOB descriptor: " . $e['message'] );
1436 }
1437
1438 if ( is_object( $val ) ) {
1439 $val = $val->getData();
1440 }
1441
1442 if ( $col_type == 'BLOB' ) {
1443 $lob[$col]->writeTemporary( $val );
1444 oci_bind_by_name( $stmt, ":$col", $lob[$col], -1, SQLT_BLOB );
1445 } else {
1446 $lob[$col]->writeTemporary( $val );
1447 oci_bind_by_name( $stmt, ":$col", $lob[$col], -1, OCI_B_CLOB );
1448 }
1449 }
1450 }
1451
1452 MediaWiki\suppressWarnings();
1453
1454 if ( oci_execute( $stmt, $this->execFlags() ) === false ) {
1455 $e = oci_error( $stmt );
1456 if ( !$this->ignoreDupValOnIndex || $e['code'] != '1' ) {
1457 $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
1458
1459 return false;
1460 } else {
1461 $this->mAffectedRows = oci_num_rows( $stmt );
1462 }
1463 } else {
1464 $this->mAffectedRows = oci_num_rows( $stmt );
1465 }
1466
1467 MediaWiki\restoreWarnings();
1468
1469 if ( isset( $lob ) ) {
1470 foreach ( $lob as $lob_v ) {
1471 $lob_v->free();
1472 }
1473 }
1474
1475 if ( !$this->mTrxLevel ) {
1476 oci_commit( $this->mConn );
1477 }
1478
1479 return oci_free_statement( $stmt );
1480 }
1481
1482 function bitNot( $field ) {
1483 // expecting bit-fields smaller than 4bytes
1484 return 'BITNOT(' . $field . ')';
1485 }
1486
1487 function bitAnd( $fieldLeft, $fieldRight ) {
1488 return 'BITAND(' . $fieldLeft . ', ' . $fieldRight . ')';
1489 }
1490
1491 function bitOr( $fieldLeft, $fieldRight ) {
1492 return 'BITOR(' . $fieldLeft . ', ' . $fieldRight . ')';
1493 }
1494
1495 function getDBname() {
1496 return $this->mDBname;
1497 }
1498
1499 function getServer() {
1500 return $this->mServer;
1501 }
1502
1503 public function buildGroupConcatField(
1504 $delim, $table, $field, $conds = '', $join_conds = []
1505 ) {
1506 $fld = "LISTAGG($field," . $this->addQuotes( $delim ) . ") WITHIN GROUP (ORDER BY $field)";
1507
1508 return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')';
1509 }
1510
1511 /**
1512 * @param string $field Field or column to cast
1513 * @return string
1514 * @since 1.28
1515 */
1516 public function buildStringCast( $field ) {
1517 return 'CAST ( ' . $field . ' AS VARCHAR2 )';
1518 }
1519
1520 public function getSearchEngine() {
1521 return 'SearchOracle';
1522 }
1523
1524 public function getInfinity() {
1525 return '31-12-2030 12:00:00.000000';
1526 }
1527 }