r61296 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61295‎ | r61296 | r61297 >
Date:16:19, 20 January 2010
Author:freakolowsky
Status:ok
Tags:
Comment:
Fixed as per Tim's comments on r60665:
* fieldExists reduced to bool-cast output of fieldInfo
* added negative cache (handled acordingly on fieldInfo usage)
* uppercased parameters on entry. DB data is uppercased by default
Modified paths:
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -476,7 +476,8 @@
477477
478478 $stmt = oci_parse( $this->mConn, $sql );
479479 foreach ( $row as $col => &$val ) {
480 - $col_type = $this->fieldInfo( $this->tableName( $table ), $col )->type();
 480+ $col_info = $this->fieldInfo( $this->tableName( $table ), $col );
 481+ $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
481482
482483 if ( $val === null ) {
483484 // do nothing ... null was inserted in statement creation
@@ -837,11 +838,16 @@
838839 * based on prebuilt table to simulate MySQL field info and keep query speed minimal
839840 */
840841 function fieldExists( $table, $field, $fname = 'DatabaseOracle::fieldExists' ) {
 842+ return (bool)$this->fieldInfo( $table, $field, $fname );
 843+ }
 844+
 845+ function fieldInfo( $table, $field ) {
841846 $tableWhere = '';
 847+ $field = strtoupper($field);
842848 if (is_array($table)) {
843849 $tableWhere = 'IN (';
844850 foreach($table as &$singleTable) {
845 - $singleTable = trim( $singleTable, '"' );
 851+ $singleTable = strtoupper(trim( $singleTable, '"' ));
846852 if (isset($this->mFieldInfoCache["$singleTable.$field"])) {
847853 return $this->mFieldInfoCache["$singleTable.$field"];
848854 }
@@ -849,65 +855,36 @@
850856 }
851857 $tableWhere = rtrim($tableWhere, ',').')';
852858 } else {
853 - $table = trim( $table, '"' );
 859+ $table = strtoupper(trim( $table, '"' ));
854860 if (isset($this->mFieldInfoCache["$table.$field"])) {
855861 return $this->mFieldInfoCache["$table.$field"];
856862 }
857 - $tableWhere = '= upper(\''.$table.'\')';
 863+ $tableWhere = '= \''.$table.'\'';
858864 }
859 -
860 - $fieldInfoStmt = oci_parse( $this->mConn, 'SELECT * FROM wiki_field_info_full WHERE table_name '.$tableWhere.' and column_name = UPPER(\''.$field.'\')' );
861865
 866+ $fieldInfoStmt = oci_parse( $this->mConn, 'SELECT * FROM wiki_field_info_full WHERE table_name '.$tableWhere.' and column_name = \''.$field.'\'' );
862867 if ( oci_execute( $fieldInfoStmt, OCI_DEFAULT ) === false ) {
863868 $e = oci_error( $fieldInfoStmt );
864869 $this->reportQueryError( $e['message'], $e['code'], 'fieldInfo QUERY', __METHOD__ );
865870 return false;
866871 }
867872 $res = new ORAResult( $this, $fieldInfoStmt );
868 - if ($res->numRows() != 0) {
 873+ if ($res->numRows() == 0 ) {
 874+ if (is_array($table)) {
 875+ foreach($table as &$singleTable) {
 876+ $this->mFieldInfoCache["$singleTable.$field"] = false;
 877+ }
 878+ } else {
 879+ $this->mFieldInfoCache["$table.$field"] = false;
 880+ }
 881+ } else {
869882 $fieldInfoTemp = new ORAField( $res->fetchRow() );
870883 $table = $fieldInfoTemp->tableName();
871884 $this->mFieldInfoCache["$table.$field"] = $fieldInfoTemp;
872 - return true;
873 - } else {
874 - return false;
 885+ return $fieldInfoTemp;
875886 }
876887 }
877888
878 - function fieldInfo( $table, $field ) {
879 - $tableWhere = '';
880 - if (is_array($table)) {
881 - $tableWhere = 'IN (';
882 - foreach($table as &$singleTable) {
883 - $singleTable = trim( $singleTable, '"' );
884 - if (isset($this->mFieldInfoCache["$singleTable.$field"])) {
885 - return $this->mFieldInfoCache["$singleTable.$field"];
886 - }
887 - $tableWhere .= '\''.$singleTable.'\',';
888 - }
889 - $tableWhere = rtrim($tableWhere, ',').')';
890 - } else {
891 - $table = trim( $table, '"' );
892 - if (isset($this->mFieldInfoCache["$table.$field"])) {
893 - return $this->mFieldInfoCache["$table.$field"];
894 - }
895 - $tableWhere = '= upper(\''.$table.'\')';
896 - }
897 -
898 - $fieldInfoStmt = oci_parse( $this->mConn, 'SELECT * FROM wiki_field_info_full WHERE table_name '.$tableWhere.' and column_name = UPPER(\''.$field.'\')' );
899 -
900 - if ( oci_execute( $fieldInfoStmt, OCI_DEFAULT ) === false ) {
901 - $e = oci_error( $fieldInfoStmt );
902 - $this->reportQueryError( $e['message'], $e['code'], 'fieldInfo QUERY', __METHOD__ );
903 - return false;
904 - }
905 - $res = new ORAResult( $this, $fieldInfoStmt );
906 - $fieldInfoTemp = new ORAField( $res->fetchRow() );
907 - $table = $fieldInfoTemp->tableName();
908 - $this->mFieldInfoCache["$table.$field"] = $fieldInfoTemp;
909 - return $fieldInfoTemp;
910 - }
911 -
912889 function begin( $fname = '' ) {
913890 $this->mTrxLevel = 1;
914891 }
@@ -1047,7 +1024,8 @@
10481025 $conds2 = array();
10491026 $conds = ($conds != null && !is_array($conds)) ? array($conds) : $conds;
10501027 foreach ( $conds as $col => $val ) {
1051 - $col_type = $this->fieldInfo( $this->tableName( $table ), $col )->type();
 1028+ $col_info = $this->fieldInfo( $this->tableName( $table ), $col );
 1029+ $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
10521030 if ( $col_type == 'CLOB' ) {
10531031 $conds2['TO_CHAR(' . $col . ')'] = $wgLang->checkTitleEncoding( $val );
10541032 } elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) {
@@ -1118,7 +1096,8 @@
11191097 $conds2 = array();
11201098 $conds = ($conds != null && !is_array($conds)) ? array($conds) : $conds;
11211099 foreach ( $conds as $col => $val ) {
1122 - $col_type = $this->fieldInfo( $this->tableName( $table ), $col )->type();
 1100+ $col_info = $this->fieldInfo( $this->tableName( $table ), $col );
 1101+ $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
11231102 if ( $col_type == 'CLOB' ) {
11241103 $conds2['TO_CHAR(' . $col . ')'] = $wgLang->checkTitleEncoding( $val );
11251104 } else {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r60665fixme for r58356freakolowsky13:35, 5 January 2010

Status & tagging log