Reverting for now this undiscussed and problematic change:
[lhc/web/wiklou.git] / includes / Database.php
index 375756f..cb4632b 100644 (file)
@@ -300,7 +300,7 @@ class Database {
                if ( $wgProfiling ) {
                        # generalizeSQL will probably cut down the query to reasonable
                        # logging size most of the time. The substr is really just a sanity check.
-                       $profName = 'query: ' . substr( Database::generalizeSQL( $sql ), 0, 255 ); 
+                       $profName = 'query: ' . $fname . ' ' . substr( Database::generalizeSQL( $sql ), 0, 255 ); 
                        wfProfileIn( 'Database::query' );
                        wfProfileIn( $profName );
                }
@@ -660,6 +660,9 @@ class Database {
        function makeSelectOptions( $options ) {
                $tailOpts = '';
 
+               if ( isset( $options['GROUP BY'] ) ) {
+                       $tailOpts .= " GROUP BY {$options['GROUP BY']}";
+               }
                if ( isset( $options['ORDER BY'] ) ) {
                        $tailOpts .= " ORDER BY {$options['ORDER BY']}";
                } 
@@ -927,11 +930,39 @@ class Database {
        }
 
        /**
-        * UPDATE wrapper, takes a condition array and a SET array
+        * Make UPDATE options for the Database::update function
+        *
+        * @access private
+        * @param array $options The options passed to Database::update
+        * @return string
         */
-       function update( $table, $values, $conds, $fname = 'Database::update' ) {
+       function makeUpdateOptions( $options ) {
+               if( !is_array( $options ) ) {
+                       wfDebugDieBacktrace( 'makeUpdateOptions given non-array' );
+               }
+               $opts = array();
+               if ( in_array( 'LOW_PRIORITY', $options ) )
+                       $opts[] = $this->lowPriorityOption();
+               if ( in_array( 'IGNORE', $options ) ) 
+                       $opts[] = 'IGNORE';
+               return implode(' ', $opts);
+       }
+       
+       /**
+        * UPDATE wrapper, takes a condition array and a SET array
+        *
+        * @param string $table  The table to UPDATE
+        * @param array  $values An array of values to SET
+        * @param array  $conds  An array of conditions (WHERE)
+        * @param string $fname  The Class::Function calling this function
+        *                       (for the log)
+        * @param array  $options An array of UPDATE options, can be one or
+        *                        more of IGNORE, LOW_PRIORITY
+        */
+       function update( $table, $values, $conds, $fname = 'Database::update', $options = array() ) {
                $table = $this->tableName( $table );
-               $sql = "UPDATE $table SET " . $this->makeList( $values, LIST_SET );
+               $opts = $this->makeUpdateOptions( $options );
+               $sql = "UPDATE $opts $table SET " . $this->makeList( $values, LIST_SET );
                if ( $conds != '*' ) {
                        $sql .= " WHERE " . $this->makeList( $conds, LIST_AND );
                }
@@ -968,9 +999,9 @@ class Database {
                                $list .= $field." IN (".$this->makeList($value).") ";
                        } else {
                                if ( $mode == LIST_AND || $mode == LIST_SET ) {
-                                       $list .= $field.'=';
+                                       $list .= "$field = ";
                                }
-                               $list .= ($mode==LIST_NAMES?$value:$this->addQuotes( $value ));
+                               $list .= $mode == LIST_NAMES ? $value : $this->addQuotes( $value );
                        }
                }
                return $list;
@@ -1089,7 +1120,7 @@ class Database {
         * PostgreSQL doesn't have them and returns ""
         */
        function useIndexClause( $index ) {
-               return "USE INDEX ($index)";
+               return "FORCE INDEX ($index)";
        }
 
        /**
@@ -1425,7 +1456,7 @@ class Database {
        /**
         * @todo document
         */
-       function &resultObject( &$result ) {
+       function resultObject( &$result ) {
                if( empty( $result ) ) {
                        return NULL;
                } else {
@@ -1537,7 +1568,7 @@ class ResultWrapper {
        /**
         * @todo document
         */
-       function &fetchObject() {
+       function fetchObject() {
                return $this->db->fetchObject( $this->result );
        }