Merge "Move up devunt's name to Developers"
[lhc/web/wiklou.git] / includes / db / DatabaseOracle.php
index 9e53653..561dadb 100644 (file)
@@ -50,7 +50,7 @@ class ORAResult {
        }
 
        /**
-        * @param DatabaseBase $db
+        * @param IDatabase $db
         * @param resource $stmt A valid OCI statement identifier
         * @param bool $unique
         */
@@ -129,63 +129,9 @@ class ORAResult {
 }
 
 /**
- * Utility class.
  * @ingroup Database
  */
-class ORAField implements Field {
-       private $name, $tablename, $default, $max_length, $nullable,
-               $is_pk, $is_unique, $is_multiple, $is_key, $type;
-
-       function __construct( $info ) {
-               $this->name = $info['column_name'];
-               $this->tablename = $info['table_name'];
-               $this->default = $info['data_default'];
-               $this->max_length = $info['data_length'];
-               $this->nullable = $info['not_null'];
-               $this->is_pk = isset( $info['prim'] ) && $info['prim'] == 1 ? 1 : 0;
-               $this->is_unique = isset( $info['uniq'] ) && $info['uniq'] == 1 ? 1 : 0;
-               $this->is_multiple = isset( $info['nonuniq'] ) && $info['nonuniq'] == 1 ? 1 : 0;
-               $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple );
-               $this->type = $info['data_type'];
-       }
-
-       function name() {
-               return $this->name;
-       }
-
-       function tableName() {
-               return $this->tablename;
-       }
-
-       function defaultValue() {
-               return $this->default;
-       }
-
-       function maxLength() {
-               return $this->max_length;
-       }
-
-       function isNullable() {
-               return $this->nullable;
-       }
-
-       function isKey() {
-               return $this->is_key;
-       }
-
-       function isMultipleKey() {
-               return $this->is_multiple;
-       }
-
-       function type() {
-               return $this->type;
-       }
-}
-
-/**
- * @ingroup Database
- */
-class DatabaseOracle extends Database {
+class DatabaseOracle extends DatabaseBase {
        /** @var resource */
        protected $mLastResult = null;
 
@@ -230,22 +176,6 @@ class DatabaseOracle extends Database {
                return 'oracle';
        }
 
-       function cascadingDeletes() {
-               return true;
-       }
-
-       function cleanupTriggers() {
-               return true;
-       }
-
-       function strictIPs() {
-               return true;
-       }
-
-       function realTimestamps() {
-               return true;
-       }
-
        function implicitGroupby() {
                return false;
        }
@@ -254,10 +184,6 @@ class DatabaseOracle extends Database {
                return false;
        }
 
-       function searchableIPs() {
-               return true;
-       }
-
        /**
         * Usually aborts on failure
         * @param string $server
@@ -265,7 +191,7 @@ class DatabaseOracle extends Database {
         * @param string $password
         * @param string $dbName
         * @throws DBConnectionError
-        * @return DatabaseBase|null
+        * @return resource|null
         */
        function open( $server, $user, $password, $dbName ) {
                global $wgDBOracleDRCP;
@@ -369,7 +295,7 @@ class DatabaseOracle extends Database {
        protected function doQuery( $sql ) {
                wfDebug( "SQL: [$sql]\n" );
                if ( !StringUtils::isUtf8( $sql ) ) {
-                       throw new MWException( "SQL encoding is invalid\n$sql" );
+                       throw new InvalidArgumentException( "SQL encoding is invalid\n$sql" );
                }
 
                // handle some oracle specifics
@@ -432,7 +358,7 @@ class DatabaseOracle extends Database {
 
        /**
         * Frees resources associated with the LOB descriptor
-        * @param ResultWrapper|resource $res
+        * @param ResultWrapper|ORAResult $res
         */
        function freeResult( $res ) {
                if ( $res instanceof ResultWrapper ) {
@@ -443,7 +369,7 @@ class DatabaseOracle extends Database {
        }
 
        /**
-        * @param ResultWrapper|stdClass $res
+        * @param ResultWrapper|ORAResult $res
         * @return mixed
         */
        function fetchObject( $res ) {
@@ -454,6 +380,10 @@ class DatabaseOracle extends Database {
                return $res->fetchObject();
        }
 
+       /**
+        * @param ResultWrapper|ORAResult $res
+        * @return mixed
+        */
        function fetchRow( $res ) {
                if ( $res instanceof ResultWrapper ) {
                        $res = $res->result;
@@ -462,6 +392,10 @@ class DatabaseOracle extends Database {
                return $res->fetchRow();
        }
 
+       /**
+        * @param ResultWrapper|ORAResult $res
+        * @return int
+        */
        function numRows( $res ) {
                if ( $res instanceof ResultWrapper ) {
                        $res = $res->result;
@@ -470,6 +404,10 @@ class DatabaseOracle extends Database {
                return $res->numRows();
        }
 
+       /**
+        * @param ResultWrapper|ORAResult $res
+        * @return int
+        */
        function numFields( $res ) {
                if ( $res instanceof ResultWrapper ) {
                        $res = $res->result;
@@ -720,14 +658,15 @@ class DatabaseOracle extends Database {
                return oci_free_statement( $stmt );
        }
 
-       function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
+       function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
                $insertOptions = [], $selectOptions = []
        ) {
                $destTable = $this->tableName( $destTable );
                if ( !is_array( $selectOptions ) ) {
                        $selectOptions = [ $selectOptions ];
                }
-               list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $selectOptions );
+               list( $startOpts, $useIndex, $tailOpts, $ignoreIndex ) =
+                       $this->makeSelectOptions( $selectOptions );
                if ( is_array( $srcTable ) ) {
                        $srcTable = implode( ',', array_map( [ &$this, 'tableName' ], $srcTable ) );
                } else {
@@ -749,7 +688,7 @@ class DatabaseOracle extends Database {
 
                $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
                        " SELECT $startOpts " . implode( ',', $varMap ) .
-                       " FROM $srcTable $useIndex ";
+                       " FROM $srcTable $useIndex $ignoreIndex ";
                if ( $conds != '*' ) {
                        $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
                }
@@ -1363,7 +1302,13 @@ class DatabaseOracle extends Database {
                        $useIndex = '';
                }
 
-               return [ $startOpts, $useIndex, $preLimitTail, $postLimitTail ];
+               if ( isset( $options['IGNORE INDEX'] ) && !is_array( $options['IGNORE INDEX'] ) ) {
+                       $ignoreIndex = $this->ignoreIndexClause( $options['IGNORE INDEX'] );
+               } else {
+                       $ignoreIndex = '';
+               }
+
+               return [ $startOpts, $useIndex, $preLimitTail, $postLimitTail, $ignoreIndex ];
        }
 
        public function delete( $table, $conds, $fname = __METHOD__ ) {
@@ -1543,8 +1488,13 @@ class DatabaseOracle extends Database {
                return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')';
        }
 
-       public function getSearchEngine() {
-               return 'SearchOracle';
+       /**
+        * @param string $field Field or column to cast
+        * @return string
+        * @since 1.28
+        */
+       public function buildStringCast( $field ) {
+               return 'CAST ( ' . $field . ' AS VARCHAR2 )';
        }
 
        public function getInfinity() {