Index: trunk/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -83,8 +83,9 @@ |
84 | 84 | } |
85 | 85 | |
86 | 86 | public function fetchObject() { |
87 | | - if ( $this->cursor >= $this->nrows ) |
| 87 | + if ( $this->cursor >= $this->nrows ) { |
88 | 88 | return false; |
| 89 | + } |
89 | 90 | $row = $this->rows[$this->cursor++]; |
90 | 91 | $ret = new stdClass(); |
91 | 92 | foreach ( $row as $k => $v ) { |
— | — | @@ -96,8 +97,9 @@ |
97 | 98 | } |
98 | 99 | |
99 | 100 | public function fetchRow() { |
100 | | - if ( $this->cursor >= $this->nrows ) |
| 101 | + if ( $this->cursor >= $this->nrows ) { |
101 | 102 | return false; |
| 103 | + } |
102 | 104 | |
103 | 105 | $row = $this->rows[$this->cursor++]; |
104 | 106 | $ret = array(); |
— | — | @@ -168,9 +170,9 @@ |
169 | 171 | * @ingroup Database |
170 | 172 | */ |
171 | 173 | class DatabaseOracle extends DatabaseBase { |
172 | | - var $mInsertId = NULL; |
173 | | - var $mLastResult = NULL; |
174 | | - var $numeric_version = NULL; |
| 174 | + var $mInsertId = null; |
| 175 | + var $mLastResult = null; |
| 176 | + var $numeric_version = null; |
175 | 177 | var $lastResult = null; |
176 | 178 | var $cursor = 0; |
177 | 179 | var $mAffectedRows; |
— | — | @@ -180,7 +182,7 @@ |
181 | 183 | |
182 | 184 | var $defaultCharset = 'AL32UTF8'; |
183 | 185 | |
184 | | - function DatabaseOracle( $server = false, $user = false, $password = false, $dbName = false, |
| 186 | + function __construct( $server = false, $user = false, $password = false, $dbName = false, |
185 | 187 | $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) |
186 | 188 | { |
187 | 189 | $tablePrefix = $tablePrefix == 'get from global' ? $tablePrefix : strtoupper( $tablePrefix ); |
— | — | @@ -223,8 +225,6 @@ |
224 | 226 | if ( !function_exists( 'oci_connect' ) ) { |
225 | 227 | throw new DBConnectionError( $this, "Oracle functions missing, have you compiled PHP with the --with-oci8 option?\n (Note: if you recently installed PHP, you may need to restart your webserver and database)\n" ); |
226 | 228 | } |
227 | | - |
228 | | - // putenv("NLS_LANG=AMERICAN_AMERICA.AL32UTF8"); |
229 | 229 | |
230 | 230 | $this->close(); |
231 | 231 | $this->mServer = $server; |
— | — | @@ -232,15 +232,16 @@ |
233 | 233 | $this->mPassword = $password; |
234 | 234 | $this->mDBname = $dbName; |
235 | 235 | |
236 | | - if ( !strlen( $user ) ) { # # e.g. the class is being loaded |
237 | | - return; |
| 236 | + if ( !strlen( $user ) ) { # e.g. the class is being loaded |
| 237 | + return; |
238 | 238 | } |
239 | 239 | |
240 | 240 | $session_mode = $this->mFlags & DBO_SYSDBA ? OCI_SYSDBA : OCI_DEFAULT; |
241 | | - if ( $this->mFlags & DBO_DEFAULT ) |
| 241 | + if ( $this->mFlags & DBO_DEFAULT ) { |
242 | 242 | $this->mConn = oci_new_connect( $user, $password, $dbName, $this->defaultCharset, $session_mode ); |
243 | | - else |
| 243 | + } else { |
244 | 244 | $this->mConn = oci_connect( $user, $password, $dbName, $this->defaultCharset, $session_mode ); |
| 245 | + } |
245 | 246 | |
246 | 247 | if ( $this->mConn == false ) { |
247 | 248 | wfDebug( "DB connection error\n" ); |
— | — | @@ -282,8 +283,9 @@ |
283 | 284 | |
284 | 285 | // handle some oracle specifics |
285 | 286 | // remove AS column/table/subquery namings |
286 | | - if ( !defined( 'MEDIAWIKI_INSTALL' ) ) |
| 287 | + if ( !defined( 'MEDIAWIKI_INSTALL' ) ) { |
287 | 288 | $sql = preg_replace( '/ as /i', ' ', $sql ); |
| 289 | + } |
288 | 290 | // Oracle has issues with UNION clause if the statement includes LOB fields |
289 | 291 | // So we do a UNION ALL and then filter the results array with array_unique |
290 | 292 | $union_unique = ( preg_match( '/\/\* UNION_UNIQUE \*\/ /', $sql ) != 0 ); |
— | — | @@ -306,14 +308,15 @@ |
307 | 309 | $olderr = error_reporting( E_ERROR ); |
308 | 310 | if ( oci_execute( $stmt, $this->execFlags() ) == false ) { |
309 | 311 | $e = oci_error( $stmt ); |
310 | | - if ( !$this->ignore_DUP_VAL_ON_INDEX || $e['code'] != '1' ) |
| 312 | + if ( !$this->ignore_DUP_VAL_ON_INDEX || $e['code'] != '1' ) { |
311 | 313 | $this->reportQueryError( $e['message'], $e['code'], $sql, __FUNCTION__ ); |
| 314 | + } |
312 | 315 | } |
313 | 316 | error_reporting( $olderr ); |
314 | 317 | |
315 | 318 | if ( $explain_count > 0 ) { |
316 | 319 | return $this->doQuery( 'SELECT id, cardinality "ROWS" FROM plan_table WHERE statement_id = \'' . $explain_id . '\'' ); |
317 | | - } elseif ( oci_statement_type( $stmt ) == "SELECT" ) { |
| 320 | + } elseif ( oci_statement_type( $stmt ) == 'SELECT' ) { |
318 | 321 | return new ORAResult( $this, $stmt, $union_unique ); |
319 | 322 | } else { |
320 | 323 | $this->mAffectedRows = oci_num_rows( $stmt ); |
— | — | @@ -385,18 +388,20 @@ |
386 | 389 | } |
387 | 390 | |
388 | 391 | function lastError() { |
389 | | - if ( $this->mConn === false ) |
| 392 | + if ( $this->mConn === false ) { |
390 | 393 | $e = oci_error(); |
391 | | - else |
| 394 | + } else { |
392 | 395 | $e = oci_error( $this->mConn ); |
| 396 | + } |
393 | 397 | return $e['message']; |
394 | 398 | } |
395 | 399 | |
396 | 400 | function lastErrno() { |
397 | | - if ( $this->mConn === false ) |
| 401 | + if ( $this->mConn === false ) { |
398 | 402 | $e = oci_error(); |
399 | | - else |
| 403 | + } else { |
400 | 404 | $e = oci_error( $this->mConn ); |
| 405 | + } |
401 | 406 | return $e['code']; |
402 | 407 | } |
403 | 408 | |
— | — | @@ -412,19 +417,22 @@ |
413 | 418 | return false; |
414 | 419 | } |
415 | 420 | |
416 | | - function indexUnique ( $table, $index, $fname = 'DatabaseOracle::indexUnique' ) { |
| 421 | + function indexUnique( $table, $index, $fname = 'DatabaseOracle::indexUnique' ) { |
417 | 422 | return false; |
418 | 423 | } |
419 | 424 | |
420 | 425 | function insert( $table, $a, $fname = 'DatabaseOracle::insert', $options = array() ) { |
421 | | - if ( !count( $a ) ) |
| 426 | + if ( !count( $a ) ) { |
422 | 427 | return true; |
| 428 | + } |
423 | 429 | |
424 | | - if ( !is_array( $options ) ) |
| 430 | + if ( !is_array( $options ) ) { |
425 | 431 | $options = array( $options ); |
| 432 | + } |
426 | 433 | |
427 | | - if ( in_array( 'IGNORE', $options ) ) |
| 434 | + if ( in_array( 'IGNORE', $options ) ) { |
428 | 435 | $this->ignore_DUP_VAL_ON_INDEX = true; |
| 436 | + } |
429 | 437 | |
430 | 438 | if ( !is_array( reset( $a ) ) ) { |
431 | 439 | $a = array( $a ); |
— | — | @@ -435,8 +443,9 @@ |
436 | 444 | } |
437 | 445 | $retVal = true; |
438 | 446 | |
439 | | - if ( in_array( 'IGNORE', $options ) ) |
| 447 | + if ( in_array( 'IGNORE', $options ) ) { |
440 | 448 | $this->ignore_DUP_VAL_ON_INDEX = false; |
| 449 | + } |
441 | 450 | |
442 | 451 | return $retVal; |
443 | 452 | } |
— | — | @@ -451,38 +460,41 @@ |
452 | 461 | // for each value, append ":key" |
453 | 462 | $first = true; |
454 | 463 | foreach ( $row as $col => $val ) { |
455 | | - if ( $first ) |
456 | | - $sql .= $val !== NULL ? ':' . $col : 'NULL'; |
457 | | - else |
458 | | - $sql .= $val !== NULL ? ', :' . $col : ', NULL'; |
| 464 | + if ( $first ) { |
| 465 | + $sql .= $val !== null ? ':' . $col : 'NULL'; |
| 466 | + } else { |
| 467 | + $sql .= $val !== null ? ', :' . $col : ', NULL'; |
| 468 | + } |
459 | 469 | |
460 | 470 | $first = false; |
461 | 471 | } |
462 | 472 | $sql .= ')'; |
463 | 473 | |
464 | | - |
465 | 474 | $stmt = oci_parse( $this->mConn, $sql ); |
466 | 475 | foreach ( $row as $col => &$val ) { |
467 | 476 | $col_type = $this->fieldInfo( $this->tableName( $table ), $col )->type(); |
468 | | - |
469 | | - if ( $val === NULL ) { |
| 477 | + |
| 478 | + if ( $val === null ) { |
470 | 479 | // do nothing ... null was inserted in statement creation |
471 | 480 | } elseif ( $col_type != 'BLOB' && $col_type != 'CLOB' ) { |
472 | | - if ( is_object( $val ) ) |
| 481 | + if ( is_object( $val ) ) { |
473 | 482 | $val = $val->getData(); |
474 | | - |
475 | | - if ( preg_match( '/^timestamp.*/i', $col_type ) == 1 && strtolower( $val ) == 'infinity' ) |
| 483 | + } |
| 484 | + |
| 485 | + if ( preg_match( '/^timestamp.*/i', $col_type ) == 1 && strtolower( $val ) == 'infinity' ) { |
476 | 486 | $val = '31-12-2030 12:00:00.000000'; |
| 487 | + } |
477 | 488 | |
478 | 489 | $val = ( $wgLang != null ) ? $wgLang->checkTitleEncoding( $val ) : $val; |
479 | | - if ( oci_bind_by_name( $stmt, ":$col", $val ) === false ) |
| 490 | + if ( oci_bind_by_name( $stmt, ":$col", $val ) === false ) { |
480 | 491 | $this->reportQueryError( $this->lastErrno(), $this->lastError(), $sql, __METHOD__ ); |
| 492 | + } |
481 | 493 | } else { |
482 | 494 | if ( ( $lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB ) ) === false ) { |
483 | 495 | $e = oci_error( $stmt ); |
484 | 496 | throw new DBUnexpectedError( $this, "Cannot create LOB descriptor: " . $e['message'] ); |
485 | 497 | } |
486 | | - |
| 498 | + |
487 | 499 | if ( $col_type == 'BLOB' ) { // is_object($val)) { |
488 | 500 | $lob[$col]->writeTemporary( $val ); // ->getData()); |
489 | 501 | oci_bind_by_name( $stmt, ":$col", $lob[$col], - 1, SQLT_BLOB ); |
— | — | @@ -497,12 +509,14 @@ |
498 | 510 | if ( oci_execute( $stmt, OCI_DEFAULT ) === false ) { |
499 | 511 | $e = oci_error( $stmt ); |
500 | 512 | |
501 | | - if ( !$this->ignore_DUP_VAL_ON_INDEX || $e['code'] != '1' ) |
| 513 | + if ( !$this->ignore_DUP_VAL_ON_INDEX || $e['code'] != '1' ) { |
502 | 514 | $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); |
503 | | - else |
| 515 | + } else { |
504 | 516 | $this->mAffectedRows = oci_num_rows( $stmt ); |
505 | | - } else |
| 517 | + } |
| 518 | + } else { |
506 | 519 | $this->mAffectedRows = oci_num_rows( $stmt ); |
| 520 | + } |
507 | 521 | error_reporting( $olderr ); |
508 | 522 | |
509 | 523 | if ( isset( $lob ) ) { |
— | — | @@ -511,9 +525,10 @@ |
512 | 526 | } |
513 | 527 | } |
514 | 528 | |
515 | | - if ( !$this->mTrxLevel ) |
| 529 | + if ( !$this->mTrxLevel ) { |
516 | 530 | oci_commit( $this->mConn ); |
517 | | - |
| 531 | + } |
| 532 | + |
518 | 533 | oci_free_statement( $stmt ); |
519 | 534 | } |
520 | 535 | |
— | — | @@ -537,8 +552,9 @@ |
538 | 553 | |
539 | 554 | // count-alias subselect fields to avoid abigious definition errors |
540 | 555 | $i = 0; |
541 | | - foreach ( $varMap as $key => &$val ) |
| 556 | + foreach ( $varMap as $key => &$val ) { |
542 | 557 | $val = $val . ' field' . ( $i++ ); |
| 558 | + } |
543 | 559 | |
544 | 560 | $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' . |
545 | 561 | " SELECT $startOpts " . implode( ',', $varMap ) . |
— | — | @@ -548,14 +564,16 @@ |
549 | 565 | } |
550 | 566 | $sql .= " $tailOpts"; |
551 | 567 | |
552 | | - if ( in_array( 'IGNORE', $insertOptions ) ) |
| 568 | + if ( in_array( 'IGNORE', $insertOptions ) ) { |
553 | 569 | $this->ignore_DUP_VAL_ON_INDEX = true; |
| 570 | + } |
554 | 571 | |
555 | 572 | $retval = $this->query( $sql, $fname ); |
556 | 573 | |
557 | | - if ( in_array( 'IGNORE', $insertOptions ) ) |
| 574 | + if ( in_array( 'IGNORE', $insertOptions ) ) { |
558 | 575 | $this->ignore_DUP_VAL_ON_INDEX = false; |
559 | | - |
| 576 | + } |
| 577 | + |
560 | 578 | return $retval; |
561 | 579 | } |
562 | 580 | |
— | — | @@ -563,46 +581,58 @@ |
564 | 582 | global $wgSharedDB, $wgSharedPrefix, $wgSharedTables; |
565 | 583 | /* |
566 | 584 | Replace reserved words with better ones |
567 | | - Useing uppercase, because that's the only way oracle can handle |
| 585 | + Using uppercase because that's the only way Oracle can handle |
568 | 586 | quoted tablenames |
569 | 587 | */ |
570 | 588 | switch( $name ) { |
571 | 589 | case 'user': |
572 | | - $name = 'MWUSER'; break; |
| 590 | + $name = 'MWUSER'; |
| 591 | + break; |
573 | 592 | case 'text': |
574 | | - $name = 'PAGECONTENT'; break; |
| 593 | + $name = 'PAGECONTENT'; |
| 594 | + break; |
575 | 595 | } |
576 | 596 | |
577 | 597 | /* |
578 | 598 | The rest of procedure is equal to generic Databse class |
579 | 599 | except for the quoting style |
580 | 600 | */ |
581 | | - if ( $name[0] == '"' && substr( $name, - 1, 1 ) == '"' ) return $name; |
| 601 | + if ( $name[0] == '"' && substr( $name, - 1, 1 ) == '"' ) { |
| 602 | + return $name; |
| 603 | + } |
582 | 604 | |
583 | | - if ( preg_match( '/(^|\s)(DISTINCT|JOIN|ON|AS)(\s|$)/i', $name ) !== 0 ) return $name; |
| 605 | + if ( preg_match( '/(^|\s)(DISTINCT|JOIN|ON|AS)(\s|$)/i', $name ) !== 0 ) { |
| 606 | + return $name; |
| 607 | + } |
584 | 608 | $dbDetails = array_reverse( explode( '.', $name, 2 ) ); |
585 | | - if ( isset( $dbDetails[1] ) ) @list( $table, $database ) = $dbDetails; |
586 | | - else @list( $table ) = $dbDetails; |
587 | | - |
| 609 | + if ( isset( $dbDetails[1] ) ) { |
| 610 | + @list( $table, $database ) = $dbDetails; |
| 611 | + } else { |
| 612 | + @list( $table ) = $dbDetails; |
| 613 | + } |
| 614 | + |
588 | 615 | $prefix = $this->mTablePrefix; |
589 | 616 | |
590 | | - if ( isset( $database ) ) $table = ( $table[0] == '`' ? $table : "`{$table}`" ); |
591 | | - |
592 | | - if ( !isset( $database ) |
593 | | - && isset( $wgSharedDB ) |
594 | | - && $table[0] != '"' |
595 | | - && isset( $wgSharedTables ) |
596 | | - && is_array( $wgSharedTables ) |
597 | | - && in_array( $table, $wgSharedTables ) ) { |
| 617 | + if ( isset( $database ) ) { |
| 618 | + $table = ( $table[0] == '`' ? $table : "`{$table}`" ); |
| 619 | + } |
| 620 | + |
| 621 | + if ( !isset( $database ) && isset( $wgSharedDB ) && $table[0] != '"' |
| 622 | + && isset( $wgSharedTables ) |
| 623 | + && is_array( $wgSharedTables ) |
| 624 | + && in_array( $table, $wgSharedTables ) |
| 625 | + ) { |
598 | 626 | $database = $wgSharedDB; |
599 | 627 | $prefix = isset( $wgSharedPrefix ) ? $wgSharedPrefix : $prefix; |
600 | 628 | } |
601 | | - |
602 | | - if ( isset( $database ) ) $database = ( $database[0] == '"' ? $database : "\"{$database}\"" ); |
| 629 | + |
| 630 | + if ( isset( $database ) ) { |
| 631 | + $database = ( $database[0] == '"' ? $database : "\"{$database}\"" ); |
| 632 | + } |
603 | 633 | $table = ( $table[0] == '"' ? $table : "\"{$prefix}{$table}\"" ); |
604 | | - |
| 634 | + |
605 | 635 | $tableName = ( isset( $database ) ? "{$database}.{$table}" : "{$table}" ); |
606 | | - |
| 636 | + |
607 | 637 | return strtoupper( $tableName ); |
608 | 638 | } |
609 | 639 | |
— | — | @@ -621,17 +651,20 @@ |
622 | 652 | * Return sequence_name if table has a sequence |
623 | 653 | */ |
624 | 654 | function getSequenceData( $table ) { |
625 | | - if ( $this->sequenceData == NULL ) { |
| 655 | + if ( $this->sequenceData == null ) { |
626 | 656 | $result = $this->query( "SELECT lower(us.sequence_name), lower(utc.table_name), lower(utc.column_name) from user_sequences us, user_tab_columns utc where us.sequence_name = utc.table_name||'_'||utc.column_name||'_SEQ'" ); |
627 | 657 | |
628 | | - while ( ( $row = $result->fetchRow() ) !== false ) |
629 | | - $this->sequenceData[$this->tableName( $row[1] )] = array( 'sequence' => $row[0], 'column' => $row[2] ); |
| 658 | + while ( ( $row = $result->fetchRow() ) !== false ) { |
| 659 | + $this->sequenceData[$this->tableName( $row[1] )] = array( |
| 660 | + 'sequence' => $row[0], |
| 661 | + 'column' => $row[2] |
| 662 | + ); |
| 663 | + } |
630 | 664 | } |
631 | | - |
| 665 | + |
632 | 666 | return ( isset( $this->sequenceData[$table] ) ) ? $this->sequenceData[$table] : false; |
633 | 667 | } |
634 | 668 | |
635 | | - |
636 | 669 | # REPLACE query wrapper |
637 | 670 | # Oracle simulates this with a DELETE followed by INSERT |
638 | 671 | # $row is the row to insert, an associative array |
— | — | @@ -692,8 +725,9 @@ |
693 | 726 | */ |
694 | 727 | } |
695 | 728 | |
696 | | - if ( $sequenceData !== false && !isset( $row[$sequenceData['column']] ) ) |
| 729 | + if ( $sequenceData !== false && !isset( $row[$sequenceData['column']] ) ) { |
697 | 730 | $row[$sequenceData['column']] = $this->nextSequenceValue( $sequenceData['sequence'] ); |
| 731 | + } |
698 | 732 | |
699 | 733 | # Now insert the row |
700 | 734 | $this->insert( $table, $row, $fname ); |
— | — | @@ -736,8 +770,9 @@ |
737 | 771 | } |
738 | 772 | |
739 | 773 | function limitResult( $sql, $limit, $offset = false ) { |
740 | | - if ( $offset === false ) |
| 774 | + if ( $offset === false ) { |
741 | 775 | $offset = 0; |
| 776 | + } |
742 | 777 | return "SELECT * FROM ($sql) WHERE rownum >= (1 + $offset) AND rownum < (1 + $limit + $offset)"; |
743 | 778 | } |
744 | 779 | |
— | — | @@ -777,17 +812,16 @@ |
778 | 813 | if ( $ignore || $tempIgnore ) { |
779 | 814 | wfDebug( "SQL ERROR (ignored): $error\n" ); |
780 | 815 | $this->ignoreErrors( $ignore ); |
| 816 | + } else { |
| 817 | + throw new DBQueryError( $this, $error, $errno, $sql, $fname ); |
781 | 818 | } |
782 | | - else { |
783 | | - throw new DBQueryError($this, $error, $errno, $sql, $fname); |
784 | | - } |
785 | 819 | } |
786 | 820 | |
787 | 821 | /** |
788 | 822 | * @return string wikitext of a link to the server software's web site |
789 | 823 | */ |
790 | 824 | function getSoftwareLink() { |
791 | | - return "[http://www.oracle.com/ Oracle]"; |
| 825 | + return '[http://www.oracle.com/ Oracle]'; |
792 | 826 | } |
793 | 827 | |
794 | 828 | /** |
— | — | @@ -817,8 +851,9 @@ |
818 | 852 | * based on prebuilt table to simulate MySQL field info and keep query speed minimal |
819 | 853 | */ |
820 | 854 | function fieldExists( $table, $field, $fname = 'DatabaseOracle::fieldExists' ) { |
821 | | - if ( !isset( $this->fieldInfo_stmt ) ) |
| 855 | + if ( !isset( $this->fieldInfo_stmt ) ) { |
822 | 856 | $this->fieldInfo_stmt = oci_parse( $this->mConn, 'SELECT * FROM wiki_field_info_full WHERE table_name = upper(:tab) and column_name = UPPER(:col)' ); |
| 857 | + } |
823 | 858 | |
824 | 859 | oci_bind_by_name( $this->fieldInfo_stmt, ':tab', trim( $table, '"' ) ); |
825 | 860 | oci_bind_by_name( $this->fieldInfo_stmt, ':col', $field ); |
— | — | @@ -833,8 +868,9 @@ |
834 | 869 | } |
835 | 870 | |
836 | 871 | function fieldInfo( $table, $field ) { |
837 | | - if ( !isset( $this->fieldInfo_stmt ) ) |
| 872 | + if ( !isset( $this->fieldInfo_stmt ) ) { |
838 | 873 | $this->fieldInfo_stmt = oci_parse( $this->mConn, 'SELECT * FROM wiki_field_info_full WHERE table_name = upper(:tab) and column_name = UPPER(:col)' ); |
| 874 | + } |
839 | 875 | |
840 | 876 | $table = trim( $table, '"' ); |
841 | 877 | oci_bind_by_name( $this->fieldInfo_stmt, ':tab', $table ); |
— | — | @@ -852,9 +888,11 @@ |
853 | 889 | function begin( $fname = '' ) { |
854 | 890 | $this->mTrxLevel = 1; |
855 | 891 | } |
| 892 | + |
856 | 893 | function immediateCommit( $fname = '' ) { |
857 | 894 | return true; |
858 | 895 | } |
| 896 | + |
859 | 897 | function commit( $fname = '' ) { |
860 | 898 | oci_commit( $this->mConn ); |
861 | 899 | $this->mTrxLevel = 0; |
— | — | @@ -867,7 +905,7 @@ |
868 | 906 | |
869 | 907 | /* defines must comply with ^define\s*([^\s=]*)\s*=\s?'\{\$([^\}]*)\}'; */ |
870 | 908 | function sourceStream( $fp, $lineCallback = false, $resultCallback = false ) { |
871 | | - $cmd = ""; |
| 909 | + $cmd = ''; |
872 | 910 | $done = false; |
873 | 911 | $dollarquote = false; |
874 | 912 | |
— | — | @@ -880,27 +918,31 @@ |
881 | 919 | $line = trim( fgets( $fp, 1024 ) ); |
882 | 920 | $sl = strlen( $line ) - 1; |
883 | 921 | |
884 | | - if ( $sl < 0 ) { continue; } |
885 | | - if ( '-' == $line { 0 } && '-' == $line { 1 } ) { continue; } |
| 922 | + if ( $sl < 0 ) { |
| 923 | + continue; |
| 924 | + } |
| 925 | + if ( '-' == $line { 0 } && '-' == $line { 1 } ) { |
| 926 | + continue; |
| 927 | + } |
886 | 928 | |
887 | 929 | // Allow dollar quoting for function declarations |
888 | 930 | if ( substr( $line, 0, 8 ) == '/*$mw$*/' ) { |
889 | 931 | if ( $dollarquote ) { |
890 | 932 | $dollarquote = false; |
891 | 933 | $done = true; |
892 | | - } |
893 | | - else { |
| 934 | + } else { |
894 | 935 | $dollarquote = true; |
895 | 936 | } |
896 | | - } |
897 | | - else if ( !$dollarquote ) { |
| 937 | + } elseif ( !$dollarquote ) { |
898 | 938 | if ( ';' == $line { $sl } && ( $sl < 2 || ';' != $line { $sl - 1 } ) ) { |
899 | 939 | $done = true; |
900 | 940 | $line = substr( $line, 0, $sl ); |
901 | 941 | } |
902 | 942 | } |
903 | 943 | |
904 | | - if ( '' != $cmd ) { $cmd .= ' '; } |
| 944 | + if ( '' != $cmd ) { |
| 945 | + $cmd .= ' '; |
| 946 | + } |
905 | 947 | $cmd .= "$line\n"; |
906 | 948 | |
907 | 949 | if ( $done ) { |
— | — | @@ -919,7 +961,7 @@ |
920 | 962 | if ( $resultCallback ) { |
921 | 963 | call_user_func( $resultCallback, $res, $this ); |
922 | 964 | } |
923 | | - |
| 965 | + |
924 | 966 | if ( false === $res ) { |
925 | 967 | $err = $this->lastError(); |
926 | 968 | return "Query \"{$cmd}\" failed with error code \"$err\".\n"; |
— | — | @@ -935,20 +977,20 @@ |
936 | 978 | |
937 | 979 | function setup_database() { |
938 | 980 | global $wgVersion, $wgDBmwschema, $wgDBts2schema, $wgDBport, $wgDBuser; |
939 | | - |
| 981 | + |
940 | 982 | echo "<li>Creating DB objects</li>\n"; |
941 | 983 | $res = $this->sourceFile( "../maintenance/ora/tables.sql" ); |
942 | | - |
| 984 | + |
943 | 985 | // Avoid the non-standard "REPLACE INTO" syntax |
944 | 986 | echo "<li>Populating table interwiki</li>\n"; |
945 | 987 | $f = fopen( "../maintenance/interwiki.sql", 'r' ); |
946 | 988 | if ( $f == false ) { |
947 | 989 | dieout( "<li>Could not find the interwiki.sql file</li>" ); |
948 | 990 | } |
949 | | - |
| 991 | + |
950 | 992 | // do it like the postgres :D |
951 | 993 | $SQL = "INSERT INTO interwiki(iw_prefix,iw_url,iw_local) VALUES "; |
952 | | - while ( ! feof( $f ) ) { |
| 994 | + while ( !feof( $f ) ) { |
953 | 995 | $line = fgets( $f, 1024 ); |
954 | 996 | $matches = array(); |
955 | 997 | if ( !preg_match( '/^\s*(\(.+?),(\d)\)/', $line, $matches ) ) { |
— | — | @@ -974,8 +1016,9 @@ |
975 | 1017 | */ |
976 | 1018 | function addQuotes( $s ) { |
977 | 1019 | global $wgLang; |
978 | | - if ( isset( $wgLang->mLoaded ) && $wgLang->mLoaded ) |
| 1020 | + if ( isset( $wgLang->mLoaded ) && $wgLang->mLoaded ) { |
979 | 1021 | $s = $wgLang->checkTitleEncoding( $s ); |
| 1022 | + } |
980 | 1023 | return "'" . $this->strencode( $s ) . "'"; |
981 | 1024 | } |
982 | 1025 | |
— | — | @@ -989,20 +1032,22 @@ |
990 | 1033 | $conds2 = array(); |
991 | 1034 | foreach ( $conds as $col => $val ) { |
992 | 1035 | $col_type = $this->fieldInfo( $this->tableName( $table ), $col )->type(); |
993 | | - if ( $col_type == 'CLOB' ) |
| 1036 | + if ( $col_type == 'CLOB' ) { |
994 | 1037 | $conds2['TO_CHAR(' . $col . ')'] = $wgLang->checkTitleEncoding( $val ); |
995 | | - elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) { |
| 1038 | + } elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) { |
996 | 1039 | $conds2[$col] = $wgLang->checkTitleEncoding( $val ); |
997 | 1040 | } else { |
998 | 1041 | $conds2[$col] = $val; |
999 | 1042 | } |
1000 | 1043 | } |
1001 | 1044 | |
1002 | | - if ( is_array( $table ) ) |
1003 | | - foreach ( $table as $tab ) |
| 1045 | + if ( is_array( $table ) ) { |
| 1046 | + foreach ( $table as $tab ) { |
1004 | 1047 | $tab = $this->tableName( $tab ); |
1005 | | - else |
| 1048 | + } |
| 1049 | + } else { |
1006 | 1050 | $table = $this->tableName( $table ); |
| 1051 | + } |
1007 | 1052 | |
1008 | 1053 | return parent::selectRow( $table, $vars, $conds2, $fname, $options, $join_conds ); |
1009 | 1054 | } |
— | — | @@ -1028,12 +1073,18 @@ |
1029 | 1074 | } |
1030 | 1075 | } |
1031 | 1076 | |
1032 | | - if ( isset( $options['GROUP BY'] ) ) $preLimitTail .= " GROUP BY {$options['GROUP BY']}"; |
1033 | | - if ( isset( $options['ORDER BY'] ) ) $preLimitTail .= " ORDER BY {$options['ORDER BY']}"; |
| 1077 | + if ( isset( $options['GROUP BY'] ) ) { |
| 1078 | + $preLimitTail .= " GROUP BY {$options['GROUP BY']}"; |
| 1079 | + } |
| 1080 | + if ( isset( $options['ORDER BY'] ) ) { |
| 1081 | + $preLimitTail .= " ORDER BY {$options['ORDER BY']}"; |
| 1082 | + } |
1034 | 1083 | |
1035 | 1084 | # if ( isset( $noKeyOptions['FOR UPDATE'] ) ) $tailOpts .= ' FOR UPDATE'; |
1036 | 1085 | # if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) $tailOpts .= ' LOCK IN SHARE MODE'; |
1037 | | - if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) $startOpts .= 'DISTINCT'; |
| 1086 | + if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) { |
| 1087 | + $startOpts .= 'DISTINCT'; |
| 1088 | + } |
1038 | 1089 | |
1039 | 1090 | if ( isset( $options['USE INDEX'] ) && ! is_array( $options['USE INDEX'] ) ) { |
1040 | 1091 | $useIndex = $this->useIndexClause( $options['USE INDEX'] ); |
— | — | @@ -1051,20 +1102,24 @@ |
1052 | 1103 | $conds2 = array(); |
1053 | 1104 | foreach ( $conds as $col => $val ) { |
1054 | 1105 | $col_type = $this->fieldInfo( $this->tableName( $table ), $col )->type(); |
1055 | | - if ( $col_type == 'CLOB' ) |
| 1106 | + if ( $col_type == 'CLOB' ) { |
1056 | 1107 | $conds2['TO_CHAR(' . $col . ')'] = $wgLang->checkTitleEncoding( $val ); |
1057 | | - else |
| 1108 | + } else { |
1058 | 1109 | if ( is_array( $val ) ) { |
1059 | 1110 | $conds2[$col] = $val; |
1060 | | - foreach ( $conds2[$col] as &$val2 ) |
| 1111 | + foreach ( $conds2[$col] as &$val2 ) { |
1061 | 1112 | $val2 = $wgLang->checkTitleEncoding( $val2 ); |
| 1113 | + } |
1062 | 1114 | } else { |
1063 | 1115 | $conds2[$col] = $wgLang->checkTitleEncoding( $val ); |
1064 | 1116 | } |
| 1117 | + } |
1065 | 1118 | } |
1066 | | - |
| 1119 | + |
1067 | 1120 | return parent::delete( $table, $conds2, $fname ); |
1068 | | - } else return parent::delete( $table, $conds, $fname ); |
| 1121 | + } else { |
| 1122 | + return parent::delete( $table, $conds, $fname ); |
| 1123 | + } |
1069 | 1124 | } |
1070 | 1125 | |
1071 | 1126 | function bitNot( $field ) { |
— | — | @@ -1122,6 +1177,6 @@ |
1123 | 1178 | } |
1124 | 1179 | |
1125 | 1180 | public function getSearchEngine() { |
1126 | | - return "SearchOracle"; |
| 1181 | + return 'SearchOracle'; |
1127 | 1182 | } |
1128 | 1183 | } // end DatabaseOracle class |