Move DatabaseBase::deleteJoin() to DatabaseMysql::deleteJoin() and the common code to DatabaseBase::deleteJoin()
Follow up r90356
/**
* 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='*'
$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 );
}
/**
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
}
}
- # 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 );
$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
*/
}
}
- # 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 );
}
}
- # 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 );
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.