From 18fb675995882191fbaf3f625879ec1718f5d6ed Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Sat, 26 Jun 2010 12:10:47 +0000 Subject: [PATCH] Support for $wgSharedDB in SQlite --- RELEASE-NOTES | 1 + includes/db/DatabaseSqlite.php | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3c32a06d7e..541834e7cb 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -93,6 +93,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 11641) \dotsc \dotsm \dotsi \dotso can now be used in * (bug 21475) \mathtt and \textsf can now be used in * texvc is now run via ulimit4.sh, to limit execution time. +* SQLite now supports $wgSharedDB. === Bug fixes in 1.17 === * (bug 17560) Half-broken deletion moved image files to deletion archive diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 7e399fbe61..64388cfa6f 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -24,10 +24,14 @@ class DatabaseSqlite extends DatabaseBase { * Parameters $server, $user and $password are not used. */ function __construct( $server = false, $user = false, $password = false, $dbName = false, $failFunction = false, $flags = 0 ) { + global $wgSharedDB; $this->mFailFunction = $failFunction; $this->mFlags = $flags; $this->mName = $dbName; - $this->open( $server, $user, $password, $dbName ); + + if ( $this->open( $server, $user, $password, $dbName ) && $wgSharedDB ) { + $this->attachDatabase( $wgSharedDB ); + } } function getType() { @@ -144,6 +148,21 @@ class DatabaseSqlite extends DatabaseBase { return false; } + /** + * Attaches external database to our connection, see http://sqlite.org/lang_attach.html + * for details. + * @param $name: Database name to be used in queries like SELECT foo FROM dbname.table + * @param $file: Database file name. If omitted, will be generated using $name and $wgSQLiteDataDir + */ + function attachDatabase( $name, $file = false, $fname = 'DatabaseSqlite::attachDatabase' ) { + global $wgSQLiteDataDir; + if ( !$file ) { + $file = self::generateFileName( $wgSQLiteDataDir, $name ); + } + $file = $this->addQuotes( $file ); + return $this->query( "ATTACH DATABASE $file AS $name", $fname ); + } + /** * SQLite doesn't allow buffered results or data seeking etc, so we'll use fetchAll as the result */ -- 2.20.1