Support for $wgSharedDB in SQlite
authorMax Semenik <maxsem@users.mediawiki.org>
Sat, 26 Jun 2010 12:10:47 +0000 (12:10 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Sat, 26 Jun 2010 12:10:47 +0000 (12:10 +0000)
RELEASE-NOTES
includes/db/DatabaseSqlite.php

index 3c32a06..541834e 100644 (file)
@@ -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 <math>
 * (bug 21475) \mathtt and \textsf can now be used in <math>
 * 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
index 7e399fb..64388cf 100644 (file)
@@ -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
         */