All the databases but MySQL were overriding DatabaseBase::deleteJoin() with the same...
authorPlatonides <platonides@users.mediawiki.org>
Sat, 18 Jun 2011 20:26:31 +0000 (20:26 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Sat, 18 Jun 2011 20:26:31 +0000 (20:26 +0000)
Move DatabaseBase::deleteJoin() to DatabaseMysql::deleteJoin() and the common code to DatabaseBase::deleteJoin()
Follow up r90356

includes/db/Database.php
includes/db/DatabaseIbm_db2.php
includes/db/DatabaseMssql.php
includes/db/DatabaseMysql.php
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php
includes/db/DatabaseSqlite.php

index 7a8a66b..d851882 100644 (file)
@@ -2004,7 +2004,7 @@ abstract class DatabaseBase implements DatabaseType {
 
        /**
         * DELETE where the condition is a join
-        * MySQL does this with a multi-table DELETE syntax, PostgreSQL does it with sub-selects
+        * MySQL overrides this to use a multi-table DELETE syntax, in other databases we use sub-selects
         *
         * For safety, an empty $conds will not delete everything. If you want to delete all rows where the
         * join condition matches, set $conds='*'
@@ -2025,13 +2025,13 @@ abstract class DatabaseBase implements DatabaseType {
 
                $delTable = $this->tableName( $delTable );
                $joinTable = $this->tableName( $joinTable );
-               $sql = "DELETE $delTable FROM $delTable, $joinTable WHERE $delVar=$joinVar ";
-
+               $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable ";
                if ( $conds != '*' ) {
-                       $sql .= ' AND ' . $this->makeList( $conds, LIST_AND );
+                       $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
                }
+               $sql .= ')';
 
-               return $this->query( $sql, $fname );
+               $this->query( $sql, $fname );
        }
 
        /**
index ed37939..d94e625 100644 (file)
@@ -1479,39 +1479,6 @@ SQL;
                return $size;
        }
 
-       /**
-        * DELETE where the condition is a join
-        * @param $delTable String: deleting from this table
-        * @param $joinTable String: using data from this table
-        * @param $delVar String: variable in deleteable table
-        * @param $joinVar String: variable in data table
-        * @param $conds Array: conditionals for join table
-        * @param $fname String: function name for profiling
-        */
-       public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar,
-               $conds, $fname = "DatabaseIbm_db2::deleteJoin" )
-       {
-               if ( !$conds ) {
-                       throw new DBUnexpectedError( $this,
-                               'DatabaseIbm_db2::deleteJoin() called with empty $conds' );
-               }
-
-               $delTable = $this->tableName( $delTable );
-               $joinTable = $this->tableName( $joinTable );
-               $sql = <<<SQL
-DELETE FROM $delTable
-WHERE $delVar IN (
-       SELECT $joinVar FROM $joinTable
-
-SQL;
-               if ( $conds != '*' ) {
-                       $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
-               }
-               $sql .= ' )';
-
-               $this->query( $sql, $fname );
-       }
-
        /**
         * Description is left as an exercise for the reader
         * @param $b Mixed: data to be encoded
index c234baf..077bd36 100644 (file)
@@ -598,23 +598,6 @@ class DatabaseMssql extends DatabaseBase {
                }
        }
 
-       # DELETE where the condition is a join
-       function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = "DatabaseMssql::deleteJoin" ) {
-               if ( !$conds ) {
-                       throw new DBUnexpectedError( $this, 'DatabaseMssql::deleteJoin() called with empty $conds' );
-               }
-
-               $delTable = $this->tableName( $delTable );
-               $joinTable = $this->tableName( $joinTable );
-               $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable ";
-               if ( $conds != '*' ) {
-                       $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
-               }
-               $sql .= ')';
-
-               $this->query( $sql, $fname );
-       }
-
        # Returns the size of a text field, or -1 for "unlimited"
        function textFieldSize( $table, $field ) {
                $table = $this->tableName( $table );
index 759d1ac..2dc3b73 100644 (file)
@@ -482,6 +482,25 @@ class DatabaseMysql extends DatabaseBase {
                $this->query( "SET sql_big_selects=$encValue", __METHOD__ );
        }
 
+       /**
+        * DELETE where the condition is a join. MySql uses multi-table deletes.
+        */
+       function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabaseBase::deleteJoin' ) {
+               if ( !$conds ) {
+                       throw new DBUnexpectedError( $this, 'DatabaseBase::deleteJoin() called with empty $conds' );
+               }
+
+               $delTable = $this->tableName( $delTable );
+               $joinTable = $this->tableName( $joinTable );
+               $sql = "DELETE $delTable FROM $delTable, $joinTable WHERE $delVar=$joinVar ";
+
+               if ( $conds != '*' ) {
+                       $sql .= ' AND ' . $this->makeList( $conds, LIST_AND );
+               }
+
+               return $this->query( $sql, $fname );
+       }
+
        /**
         * Determines if the last failure was due to a deadlock
         */
index f79d369..d140a11 100644 (file)
@@ -767,23 +767,6 @@ class DatabaseOracle extends DatabaseBase {
                }
        }
 
-       # DELETE where the condition is a join
-       function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabaseOracle::deleteJoin' ) {
-               if ( !$conds ) {
-                       throw new DBUnexpectedError( $this, 'DatabaseOracle::deleteJoin() called with empty $conds' );
-               }
-
-               $delTable = $this->tableName( $delTable );
-               $joinTable = $this->tableName( $joinTable );
-               $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable ";
-               if ( $conds != '*' ) {
-                       $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
-               }
-               $sql .= ')';
-
-               $this->query( $sql, $fname );
-       }
-
        # Returns the size of a text field, or -1 for "unlimited"
        function textFieldSize( $table, $field ) {
                $fieldInfoData = $this->fieldInfo( $table, $field );
index 4f85ba7..3b54cce 100644 (file)
@@ -707,23 +707,6 @@ class DatabasePostgres extends DatabaseBase {
                }
        }
 
-       # DELETE where the condition is a join
-       function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabasePostgres::deleteJoin' ) {
-               if ( !$conds ) {
-                       throw new DBUnexpectedError( $this, 'DatabasePostgres::deleteJoin() called with empty $conds' );
-               }
-
-               $delTable = $this->tableName( $delTable );
-               $joinTable = $this->tableName( $joinTable );
-               $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable ";
-               if ( $conds != '*' ) {
-                       $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
-               }
-               $sql .= ')';
-
-               $this->query( $sql, $fname );
-       }
-
        # Returns the size of a text field, or -1 for "unlimited"
        function textFieldSize( $table, $field ) {
                $table = $this->tableName( $table );
index 48dd858..a6bc696 100644 (file)
@@ -543,35 +543,6 @@ class DatabaseSqlite extends DatabaseBase {
                return $ret;
        }
 
-       /**
-        * DELETE where the condition is a join
-        *
-        * @param $delTable String: The table to delete from.
-        * @param $joinTable String: The other table.
-        * @param $delVar String: The variable to join on, in the first table.
-        * @param $joinVar String: The variable to join on, in the second table.
-        * @param $conds Array: Condition array of field names mapped to variables, ANDed together in the WHERE clause
-        * @param $fname String: Calling function name (use __METHOD__) for logs/profiling
-        */
-       public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
-               $fname = 'DatabaseSqlite::deleteJoin' )
-       {
-               if ( !$conds ) {
-                       throw new DBUnexpectedError( $this,
-                               'DatabaseSqlite::deleteJoin() called with empty $conds' );
-               }
-
-               $delTable = $this->tableName( $delTable );
-               $joinTable = $this->tableName( $joinTable );
-               $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable";
-               if ( $conds != '*' ) {
-                       $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
-               }
-               $sql .= ')';
-
-               $this->query( $sql, $fname );
-       }
-
        /**
         * Returns the size of a text field, or -1 for "unlimited"
         * In SQLite this is SQLITE_MAX_LENGTH, by default 1GB. No way to query it though.