+ /**
+ * Generates a database file name. Explicitly public for installer.
+ * @param $dir String: Directory where database resides
+ * @param $dbName String: Database name
+ * @return String
+ */
+ public static function generateFileName( $dir, $dbName ) {
+ return "$dir/$dbName.sqlite";
+ }
+
+ /**
+ * Check if the searchindext table is FTS enabled.
+ * @returns false if not enabled.
+ */
+ function checkForEnabledSearch() {
+ if ( self::$fulltextEnabled === null ) {
+ self::$fulltextEnabled = false;
+ $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name = 'searchindex'", __METHOD__ );
+ if ( $res ) {
+ $row = $res->fetchRow();
+ self::$fulltextEnabled = stristr($row['sql'], 'fts' ) !== false;
+ }
+ }
+ return self::$fulltextEnabled;
+ }
+
+ /**
+ * Returns version of currently supported SQLite fulltext search module or false if none present.
+ * @return String
+ */
+ function getFulltextSearchModule() {
+ static $cachedResult = null;
+ if ( $cachedResult !== null ) {
+ return $cachedResult;
+ }
+ $cachedResult = false;
+ $table = 'dummy_search_test';
+ $this->query( "DROP TABLE IF EXISTS $table", __METHOD__ );
+
+ if ( $this->query( "CREATE VIRTUAL TABLE $table USING FTS3(dummy_field)", __METHOD__, true ) ) {
+ $this->query( "DROP TABLE IF EXISTS $table", __METHOD__ );
+ $cachedResult = 'FTS3';
+ }
+ return $cachedResult;
+ }
+
+ /**
+ * Attaches external database to our connection, see http://sqlite.org/lang_attach.html
+ * for details.
+ * @param $name String: database name to be used in queries like SELECT foo FROM dbname.table
+ * @param $file String: database file name. If omitted, will be generated using $name and $wgSQLiteDataDir
+ * @param $fname String: calling function name
+ */
+ 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 );
+ }
+
+ /**
+ * @see DatabaseBase::isWriteQuery()
+ */
+ function isWriteQuery( $sql ) {
+ return parent::isWriteQuery( $sql ) && !preg_match( '/^ATTACH\b/i', $sql );
+ }
+