From: Matěj Grabovský Date: Sat, 18 Jun 2011 18:58:26 +0000 (+0000) Subject: (bug 29476) DatabaseBase::deleteJoin fails for Sqlite X-Git-Tag: 1.31.0-rc.0~29436 X-Git-Url: http://git.cyclocoop.org/clavettes/images/siteon3.jpg?a=commitdiff_plain;h=07d40e6863d521669aed60404e2e8b0ebded8dba;p=lhc%2Fweb%2Fwiklou.git (bug 29476) DatabaseBase::deleteJoin fails for Sqlite Added deleteJoin() to DatabaseSqlite, C&P from DatabasePostgres --- diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index a6bc696e57..48dd858569 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -543,6 +543,35 @@ 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.