From f6cb1b04429ddd04a8219f3ba9b129af9d878a68 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Sun, 10 Jan 2010 17:27:46 +0000 Subject: [PATCH] Workaround for SQLite's inability to perform multi-row replacements --- includes/db/DatabaseSqlite.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 457d895965..159d37397b 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -295,7 +295,7 @@ class DatabaseSqlite extends DatabaseBase { } /** - * Based on MySQL method (parent) with some prior SQLite-sepcific adjustments + * Based on generic method (parent) with some prior SQLite-sepcific adjustments */ function insert( $table, $a, $fname = 'DatabaseSqlite::insert', $options = array() ) { if ( !count( $a ) ) return true; @@ -319,6 +319,22 @@ class DatabaseSqlite extends DatabaseBase { return $ret; } + function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseSqlite::replace' ) { + if ( !count( $rows ) ) return true; + + # SQLite can't handle multi-row replaces, so divide up into multiple single-row queries + if ( isset( $rows[0] ) && is_array( $rows[0] ) ) { + $ret = true; + foreach ( $rows as $k => $v ) + if ( !parent::replace( $table, $uniqueIndexes, $v, "$fname/multi-row" ) ) + $ret = false; + } else { + $ret = parent::replace( $table, $uniqueIndexes, $rows, "$fname/single-row" ); + } + + return $ret; + } + /** * 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