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