Index: trunk/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -454,11 +454,12 @@ |
455 | 455 | return $retVal; |
456 | 456 | } |
457 | 457 | |
458 | | - function insertOneRow( $table, $row, $fname ) { |
| 458 | + private function insertOneRow( $table, $row, $fname ) { |
459 | 459 | global $wgLang; |
460 | 460 | |
| 461 | + $table = $this->tableName( $table ); |
461 | 462 | // "INSERT INTO tables (a, b, c)" |
462 | | - $sql = "INSERT INTO " . $this->tableName( $table ) . " (" . join( ',', array_keys( $row ) ) . ')'; |
| 463 | + $sql = "INSERT INTO " . $table . " (" . join( ',', array_keys( $row ) ) . ')'; |
463 | 464 | $sql .= " VALUES ("; |
464 | 465 | |
465 | 466 | // for each value, append ":key" |
— | — | @@ -476,7 +477,7 @@ |
477 | 478 | |
478 | 479 | $stmt = oci_parse( $this->mConn, $sql ); |
479 | 480 | foreach ( $row as $col => &$val ) { |
480 | | - $col_info = $this->fieldInfo( $this->tableName( $table ), $col ); |
| 481 | + $col_info = $this->fieldInfoMulti( $table, $col ); |
481 | 482 | $col_type = $col_info != false ? $col_info->type() : 'CONSTANT'; |
482 | 483 | |
483 | 484 | if ( $val === null ) { |
— | — | @@ -585,13 +586,6 @@ |
586 | 587 | } |
587 | 588 | |
588 | 589 | function tableName( $name ) { |
589 | | - if (is_array($name)) { |
590 | | - foreach($name as &$single_name) { |
591 | | - $single_name = $this->tableName($single_name); |
592 | | - } |
593 | | - return $name; |
594 | | - } |
595 | | - |
596 | 590 | global $wgSharedDB, $wgSharedPrefix, $wgSharedTables; |
597 | 591 | /* |
598 | 592 | Replace reserved words with better ones |
— | — | @@ -663,7 +657,7 @@ |
664 | 658 | /** |
665 | 659 | * Return sequence_name if table has a sequence |
666 | 660 | */ |
667 | | - function getSequenceData( $table ) { |
| 661 | + private function getSequenceData( $table ) { |
668 | 662 | if ( $this->sequenceData == null ) { |
669 | 663 | $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'" ); |
670 | 664 | |
— | — | @@ -741,18 +735,12 @@ |
742 | 736 | # Returns the size of a text field, or -1 for "unlimited" |
743 | 737 | function textFieldSize( $table, $field ) { |
744 | 738 | $table = $this->tableName( $table ); |
745 | | - $sql = "SELECT t.typname as ftype,a.atttypmod as size |
746 | | - FROM pg_class c, pg_attribute a, pg_type t |
747 | | - WHERE relname='$table' AND a.attrelid=c.oid AND |
748 | | - a.atttypid=t.oid and a.attname='$field'"; |
749 | | - $res = $this->query( $sql ); |
750 | | - $row = $this->fetchObject( $res ); |
751 | | - if ( $row->ftype == "varchar" ) { |
| 739 | + $fieldInfoData = $this->fieldInfo( $table, $field); |
| 740 | + if ( $fieldInfoData->type == "varchar" ) { |
752 | 741 | $size = $row->size - 4; |
753 | 742 | } else { |
754 | 743 | $size = $row->size; |
755 | 744 | } |
756 | | - $this->freeResult( $res ); |
757 | 745 | return $size; |
758 | 746 | } |
759 | 747 | |
— | — | @@ -834,14 +822,15 @@ |
835 | 823 | } |
836 | 824 | |
837 | 825 | /** |
838 | | - * Query whether a given column exists in the mediawiki schema |
839 | | - * based on prebuilt table to simulate MySQL field info and keep query speed minimal |
| 826 | + * Function translates mysql_fetch_field() functionality on ORACLE. |
| 827 | + * Caching is present for reducing query time. |
| 828 | + * For internal calls. Use fieldInfo for normal usage. |
| 829 | + * Returns false if the field doesn't exist |
| 830 | + * |
| 831 | + * @param Array $table |
| 832 | + * @param String $field |
840 | 833 | */ |
841 | | - function fieldExists( $table, $field, $fname = 'DatabaseOracle::fieldExists' ) { |
842 | | - return (bool)$this->fieldInfo( $table, $field, $fname ); |
843 | | - } |
844 | | - |
845 | | - function fieldInfo( $table, $field ) { |
| 834 | + private function fieldInfoMulti( $table, $field ) { |
846 | 835 | $tableWhere = ''; |
847 | 836 | $field = strtoupper($field); |
848 | 837 | if (is_array($table)) { |
— | — | @@ -885,6 +874,17 @@ |
886 | 875 | } |
887 | 876 | } |
888 | 877 | |
| 878 | + function fieldInfo( $table, $field ) { |
| 879 | + if ( is_array( $table ) ) { |
| 880 | + throw new DBUnexpectedError( $this, 'Database::fieldInfo called with table array!' ); |
| 881 | + } |
| 882 | + return $this->fieldInfoMulti ($table, $field); |
| 883 | + } |
| 884 | + |
| 885 | + function fieldExists( $table, $field, $fname = 'DatabaseOracle::fieldExists' ) { |
| 886 | + return (bool)$this->fieldInfo( $table, $field, $fname ); |
| 887 | + } |
| 888 | + |
889 | 889 | function begin( $fname = '' ) { |
890 | 890 | $this->mTrxLevel = 1; |
891 | 891 | } |
— | — | @@ -1021,10 +1021,14 @@ |
1022 | 1022 | function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) { |
1023 | 1023 | global $wgLang; |
1024 | 1024 | |
| 1025 | + if (is_array($table)) { |
| 1026 | + $table = array_map( array( &$this, 'tableName' ), $table ); |
| 1027 | + } |
| 1028 | + |
1025 | 1029 | $conds2 = array(); |
1026 | 1030 | $conds = ($conds != null && !is_array($conds)) ? array($conds) : $conds; |
1027 | 1031 | foreach ( $conds as $col => $val ) { |
1028 | | - $col_info = $this->fieldInfo( $this->tableName( $table ), $col ); |
| 1032 | + $col_info = $this->fieldInfoMulti( $table, $col ); |
1029 | 1033 | $col_type = $col_info != false ? $col_info->type() : 'CONSTANT'; |
1030 | 1034 | if ( $col_type == 'CLOB' ) { |
1031 | 1035 | $conds2['TO_CHAR(' . $col . ')'] = $wgLang->checkTitleEncoding( $val ); |
— | — | @@ -1035,14 +1039,6 @@ |
1036 | 1040 | } |
1037 | 1041 | } |
1038 | 1042 | |
1039 | | - if ( is_array( $table ) ) { |
1040 | | - foreach ( $table as $tab ) { |
1041 | | - $tab = $this->tableName( $tab ); |
1042 | | - } |
1043 | | - } else { |
1044 | | - $table = $this->tableName( $table ); |
1045 | | - } |
1046 | | - |
1047 | 1043 | return parent::selectRow( $table, $vars, $conds2, $fname, $options, $join_conds ); |
1048 | 1044 | } |
1049 | 1045 | |
— | — | @@ -1092,11 +1088,15 @@ |
1093 | 1089 | public function delete( $table, $conds, $fname = 'DatabaseOracle::delete' ) { |
1094 | 1090 | global $wgLang; |
1095 | 1091 | |
| 1092 | + if (is_array($table)) { |
| 1093 | + $table = array_map( array( &$this, 'tableName' ), $table ); |
| 1094 | + } |
| 1095 | + |
1096 | 1096 | if ( $wgLang != null ) { |
1097 | 1097 | $conds2 = array(); |
1098 | 1098 | $conds = ($conds != null && !is_array($conds)) ? array($conds) : $conds; |
1099 | 1099 | foreach ( $conds as $col => $val ) { |
1100 | | - $col_info = $this->fieldInfo( $this->tableName( $table ), $col ); |
| 1100 | + $col_info = $this->fieldInfoMulti( $table, $col ); |
1101 | 1101 | $col_type = $col_info != false ? $col_info->type() : 'CONSTANT'; |
1102 | 1102 | if ( $col_type == 'CLOB' ) { |
1103 | 1103 | $conds2['TO_CHAR(' . $col . ')'] = $wgLang->checkTitleEncoding( $val ); |