From c2f49a75f24f259d35f2632a795d9444e027eee1 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Mon, 11 Apr 2011 17:16:41 +0000 Subject: [PATCH] Bug 28478: database error in DatabaseSqlite::getFulltextSearchModule(). It was caused by a weird bug in SQLite: virtual table using a non-existent module still gets created somehow, and it is completely undeletable. --- includes/db/DatabaseSqlite.php | 11 ++++++----- includes/installer/Installer.php | 3 +-- includes/installer/SqliteInstaller.php | 2 +- includes/installer/SqliteUpdater.php | 2 +- maintenance/rebuildtextindex.php | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 1ad8f6e70c..e7bc31eacc 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -130,19 +130,20 @@ class DatabaseSqlite extends DatabaseBase { * Returns version of currently supported SQLite fulltext search module or false if none present. * @return String */ - function getFulltextSearchModule() { + static function getFulltextSearchModule() { static $cachedResult = null; if ( $cachedResult !== null ) { return $cachedResult; } $cachedResult = false; $table = 'dummy_search_test'; - $this->query( "DROP TABLE IF EXISTS $table", __METHOD__ ); + + $db = new DatabaseSqliteStandalone( ':memory:' ); - if ( $this->query( "CREATE VIRTUAL TABLE $table USING FTS3(dummy_field)", __METHOD__, true ) ) { - $this->query( "DROP TABLE IF EXISTS $table", __METHOD__ ); + if ( $db->query( "CREATE VIRTUAL TABLE $table USING FTS3(dummy_field)", __METHOD__, true ) ) { $cachedResult = 'FTS3'; } + $db->close(); return $cachedResult; } @@ -460,7 +461,7 @@ class DatabaseSqlite extends DatabaseBase { * @return string User-friendly database information */ public function getServerInfo() { - return wfMsg( $this->getFulltextSearchModule() ? 'sqlite-has-fts' : 'sqlite-no-fts', $this->getServerVersion() ); + return wfMsg( self::getFulltextSearchModule() ? 'sqlite-has-fts' : 'sqlite-no-fts', $this->getServerVersion() ); } /** diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 87036c5e62..7b3f4f885e 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -625,8 +625,7 @@ abstract class Installer { // Check for FTS3 full-text search module $sqlite = $this->getDBInstaller( 'sqlite' ); if ( $sqlite->isCompiled() ) { - $db = new DatabaseSqliteStandalone( ':memory:' ); - if( $db->getFulltextSearchModule() != 'FTS3' ) { + if( DatabaseSqlite::getFulltextSearchModule() != 'FTS3' ) { $this->showMessage( 'config-no-fts3' ); } } diff --git a/includes/installer/SqliteInstaller.php b/includes/installer/SqliteInstaller.php index 6b57d18582..2edb3d9bd6 100644 --- a/includes/installer/SqliteInstaller.php +++ b/includes/installer/SqliteInstaller.php @@ -170,7 +170,7 @@ class SqliteInstaller extends DatabaseInstaller { public function setupSearchIndex( &$status ) { global $IP; - $module = $this->db->getFulltextSearchModule(); + $module = DatabaseSqlite::getFulltextSearchModule(); $fts3tTable = $this->db->checkForEnabledSearch(); if ( $fts3tTable && !$module ) { $status->warning( 'config-sqlite-fts3-downgrade' ); diff --git a/includes/installer/SqliteUpdater.php b/includes/installer/SqliteUpdater.php index 5cbe67a833..d1a6c20bb5 100644 --- a/includes/installer/SqliteUpdater.php +++ b/includes/installer/SqliteUpdater.php @@ -67,7 +67,7 @@ class SqliteUpdater extends DatabaseUpdater { } protected function sqliteSetupSearchindex() { - $module = $this->db->getFulltextSearchModule(); + $module = DatabaseSqlite::getFulltextSearchModule(); $fts3tTable = $this->updateRowExists( 'fts3' ); if ( $fts3tTable && !$module ) { $this->output( '...PHP is missing FTS3 support, downgrading tables...' ); diff --git a/maintenance/rebuildtextindex.php b/maintenance/rebuildtextindex.php index deabff737a..b0934eb120 100644 --- a/maintenance/rebuildtextindex.php +++ b/maintenance/rebuildtextindex.php @@ -50,11 +50,11 @@ class RebuildTextIndex extends Maintenance { $this->db = wfGetDB( DB_MASTER ); if ( $this->db->getType() == 'sqlite' ) { - if ( !$this->db->getFulltextSearchModule() ) { - $this->error( "Your version of SQLite module for PHP doesn't support full-text search (FTS3).\n" ); + if ( !DatabaseSqlite::getFulltextSearchModule() ) { + $this->error( "Your version of SQLite module for PHP doesn't support full-text search (FTS3).\n", true ); } if ( !$this->db->checkForEnabledSearch() ) { - $this->error( "Your database schema is not configured for full-text search support. Run update.php.\n" ); + $this->error( "Your database schema is not configured for full-text search support. Run update.php.\n", true ); } } -- 2.20.1