From 07d40e6863d521669aed60404e2e8b0ebded8dba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mat=C4=9Bj=20Grabovsk=C3=BD?= Date: Sat, 18 Jun 2011 18:58:26 +0000 Subject: [PATCH] (bug 29476) DatabaseBase::deleteJoin fails for Sqlite Added deleteJoin() to DatabaseSqlite, C&P from DatabasePostgres --- includes/db/DatabaseSqlite.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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. -- 2.20.1