From 8093e9733c60c0f29f745b859ae3bd272177e495 Mon Sep 17 00:00:00 2001 From: Platonides Date: Sat, 18 Jun 2011 20:26:31 +0000 Subject: [PATCH] All the databases but MySQL were overriding DatabaseBase::deleteJoin() with the same code. Move DatabaseBase::deleteJoin() to DatabaseMysql::deleteJoin() and the common code to DatabaseBase::deleteJoin() Follow up r90356 --- includes/db/Database.php | 10 +++++----- includes/db/DatabaseIbm_db2.php | 33 -------------------------------- includes/db/DatabaseMssql.php | 17 ---------------- includes/db/DatabaseMysql.php | 19 ++++++++++++++++++ includes/db/DatabaseOracle.php | 17 ---------------- includes/db/DatabasePostgres.php | 17 ---------------- includes/db/DatabaseSqlite.php | 29 ---------------------------- 7 files changed, 24 insertions(+), 118 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 7a8a66bd9c..d8518823b8 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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 ); } /** diff --git a/includes/db/DatabaseIbm_db2.php b/includes/db/DatabaseIbm_db2.php index ed37939747..d94e625156 100644 --- a/includes/db/DatabaseIbm_db2.php +++ b/includes/db/DatabaseIbm_db2.php @@ -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 = <<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 diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index c234baff1c..077bd36887 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -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 ); diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index 759d1ac188..2dc3b7364a 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -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 */ diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index f79d369c42..d140a11916 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -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 ); diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 4f85ba73fc..3b54cce261 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -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 ); diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 48dd858569..a6bc696e57 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -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. -- 2.20.1