Merge "[JobQueue] Added a JobQueueRedis class."
[lhc/web/wiklou.git] / includes / db / DatabaseIbm_db2.php
index f1f6dfc..57fc7b9 100644 (file)
@@ -143,13 +143,12 @@ class IBM_DB2Result{
         * @param $sql String
         * @param $columns Array
         */
-       public function __construct( $db, $result, $num_rows, $sql, $columns ){
+       public function __construct( $db, $result, $num_rows, $sql, $columns ) {
                $this->db = $db;
 
-               if( $result instanceof ResultWrapper ){
+               if( $result instanceof ResultWrapper ) {
                        $this->result = $result->result;
-               }
-               else{
+               } else {
                        $this->result = $result;
                }
 
@@ -224,7 +223,7 @@ class IBM_DB2Result{
         * @return mixed Array on success, false on failure
         * @throws DBUnexpectedError
         */
-       public function fetchRow(){
+       public function fetchRow() {
                if ( $this->result
                                && $this->num_rows > 0
                                && $this->current_pos >= 0
@@ -239,7 +238,7 @@ class IBM_DB2Result{
                                }
                        }
 
-                       if ( $this->loadedLines > $this->current_pos ){
+                       if ( $this->loadedLines > $this->current_pos ) {
                                return $this->resultSet[$this->current_pos++];
                        }
 
@@ -251,7 +250,7 @@ class IBM_DB2Result{
         * Free a DB2 result object
         * @throws DBUnexpectedError
         */
-       public function freeResult(){
+       public function freeResult() {
                unset( $this->resultSet );
                if ( !@db2_free_result( $this->result ) ) {
                        throw new DBUnexpectedError( $this, "Unable to free DB2 result\n" );
@@ -420,7 +419,7 @@ class DatabaseIbm_db2 extends DatabaseBase {
         * Returns the database connection object
         * @return Object
         */
-       public function getDb(){
+       public function getDb() {
                return $this->mConn;
        }
 
@@ -496,6 +495,7 @@ class DatabaseIbm_db2 extends DatabaseBase {
         * @param $user String
         * @param $password String
         * @param $dbName String: database name
+        * @throws DBConnectionError
         * @return DatabaseBase a fresh connection
         */
        public function open( $server, $user, $password, $dbName ) {
@@ -622,6 +622,7 @@ class DatabaseIbm_db2 extends DatabaseBase {
        /**
         * The DBMS-dependent part of query()
         * @param  $sql String: SQL query.
+        * @throws DBUnexpectedError
         * @return object Result object for fetch functions or false on failure
         */
        protected function doQuery( $sql ) {
@@ -786,8 +787,8 @@ class DatabaseIbm_db2 extends DatabaseBase {
                // Wide characters are evil -- some of them look like '
                $s = utf8_encode( $s );
                // Fix its stupidity
-               $from = array(  "\\\\", "\\'",  '\\n',  '\\t',  '\\"',  '\\r' );
-               $to = array(            "\\",           "''",           "\n",           "\t",           '"',            "\r" );
+               $from = array( "\\\\", "\\'", '\\n', '\\t', '\\"', '\\r' );
+               $to = array( "\\", "''", "\n", "\t", '"', "\r" );
                $s = str_replace( $from, $to, $s ); // DB2 expects '', not \' escaping
                return $s;
        }
@@ -854,6 +855,9 @@ class DatabaseIbm_db2 extends DatabaseBase {
         *   LIST_SET           - comma separated with field names, like a SET clause
         *   LIST_NAMES         - comma separated field names
         *   LIST_SET_PREPARED  - like LIST_SET, except with ? tokens as values
+        * @param array $a
+        * @param int $mode
+        * @throws DBUnexpectedError
         * @return string
         */
        function makeList( $a, $mode = LIST_COMMA ) {
@@ -891,7 +895,8 @@ class DatabaseIbm_db2 extends DatabaseBase {
         *
         * @param $sql string SQL query we will append the limit too
         * @param $limit integer the SQL limit
-        * @param $offset integer the SQL offset (default false)
+        * @param bool|int $offset SQL offset (default false)
+        * @throws DBUnexpectedError
         * @return string
         */
        public function limitResult( $sql, $limit, $offset=false ) {
@@ -1110,10 +1115,10 @@ class DatabaseIbm_db2 extends DatabaseBase {
 
                // find out the primary keys
                $keyres = $this->doQuery( "SELECT NAME FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = '"
-                 . strtoupper( $table )
-                 . "' AND TBCREATOR = '"
-                 . strtoupper( $schema )
-                 . "' AND KEYSEQ > 0" );
+                       . strtoupper( $table )
+                       . "' AND TBCREATOR = '"
+                       . strtoupper( $schema )
+                       . "' AND KEYSEQ > 0" );
 
                $keys = array();
                for (
@@ -1173,7 +1178,11 @@ class DatabaseIbm_db2 extends DatabaseBase {
         * DELETE query wrapper
         *
         * Use $conds == "*" to delete all rows
-        * @return bool|\ResultWrapper
+        * @param array $table
+        * @param array|string $conds
+        * @param string $fname
+        * @throws DBUnexpectedError
+        * @return bool|ResultWrapper
         */
        public function delete( $table, $conds, $fname = 'DatabaseIbm_db2::delete' ) {
                if ( !$conds ) {
@@ -1247,6 +1256,7 @@ class DatabaseIbm_db2 extends DatabaseBase {
        /**
         * Frees memory associated with a statement resource
         * @param $res Object: statement resource to free
+        * @throws DBUnexpectedError
         * @return Boolean success or failure
         */
        public function freeResult( $res ) {
@@ -1369,15 +1379,9 @@ class DatabaseIbm_db2 extends DatabaseBase {
                        }
                }
 
-               if ( isset( $options['GROUP BY'] ) ) {
-                       $preLimitTail .= " GROUP BY {$options['GROUP BY']}";
-               }
-               if ( isset( $options['HAVING'] ) ) {
-                       $preLimitTail .= " HAVING {$options['HAVING']}";
-               }
-               if ( isset( $options['ORDER BY'] ) ) {
-                       $preLimitTail .= " ORDER BY {$options['ORDER BY']}";
-               }
+               $preLimitTail .= $this->makeGroupByWithHaving( $options );
+
+               $preLimitTail .= $this->makeOrderBy( $options );
 
                if ( isset( $noKeyOptions['DISTINCT'] )
                        || isset( $noKeyOptions['DISTINCTROW'] ) )