3 * This is the SQLite database abstraction layer.
4 * See maintenance/sqlite/README for development notes and other specific information
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
24 namespace Wikimedia\Rdbms;
30 use InvalidArgumentException;
37 class DatabaseSqlite extends Database {
38 /** @var bool Whether full text is enabled */
39 private static $fulltextEnabled = null;
41 /** @var string Directory */
43 /** @var string File name for SQLite database file */
45 /** @var string Transaction mode */
48 /** @var int The number of rows affected as an integer */
49 protected $mAffectedRows;
51 protected $mLastResult;
56 /** @var FSLockManager (hopefully on the same server as the DB) */
60 * Additional params include:
61 * - dbDirectory : directory containing the DB and the lock file directory
62 * [defaults to $wgSQLiteDataDir]
63 * - dbFilePath : use this to force the path of the DB file
64 * - trxMode : one of (deferred, immediate, exclusive)
67 function __construct( array $p ) {
68 if ( isset( $p['dbFilePath'] ) ) {
69 parent::__construct( $p );
70 // Standalone .sqlite file mode.
71 // Super doesn't open when $user is false, but we can work with $dbName,
72 // which is derived from the file path in this case.
73 $this->openFile( $p['dbFilePath'] );
74 $lockDomain = md5( $p['dbFilePath'] );
75 } elseif ( !isset( $p['dbDirectory'] ) ) {
76 throw new InvalidArgumentException( "Need 'dbDirectory' or 'dbFilePath' parameter." );
78 $this->dbDir = $p['dbDirectory'];
79 $this->mDBname = $p['dbname'];
80 $lockDomain = $this->mDBname;
81 // Stock wiki mode using standard file names per DB.
82 parent::__construct( $p );
83 // Super doesn't open when $user is false, but we can work with $dbName
84 if ( $p['dbname'] && !$this->isOpen() ) {
85 if ( $this->open( $p['host'], $p['user'], $p['password'], $p['dbname'] ) ) {
87 foreach ( $this->tableAliases as $params ) {
88 if ( isset( $done[$params['dbname']] ) ) {
91 $this->attachDatabase( $params['dbname'] );
92 $done[$params['dbname']] = 1;
98 $this->trxMode = isset( $p['trxMode'] ) ? strtoupper( $p['trxMode'] ) : null;
99 if ( $this->trxMode &&
100 !in_array( $this->trxMode, [ 'DEFERRED', 'IMMEDIATE', 'EXCLUSIVE' ] )
102 $this->trxMode = null;
103 $this->queryLogger->warning( "Invalid SQLite transaction mode provided." );
106 $this->lockMgr = new FSLockManager( [
107 'domain' => $lockDomain,
108 'lockDirectory' => "{$this->dbDir}/locks"
113 * @param string $filename
114 * @param array $p Options map; supports:
115 * - flags : (same as __construct counterpart)
116 * - trxMode : (same as __construct counterpart)
117 * - dbDirectory : (same as __construct counterpart)
118 * @return DatabaseSqlite
121 public static function newStandaloneInstance( $filename, array $p = [] ) {
122 $p['dbFilePath'] = $filename;
123 $p['schema'] = false;
124 $p['tablePrefix'] = '';
125 /** @var DatabaseSqlite $db */
126 $db = Database::factory( 'sqlite', $p );
139 * @todo Check if it should be true like parent class
143 function implicitGroupby() {
147 /** Open an SQLite database and return a resource handle to it
148 * NOTE: only $dbName is used, the other parameters are irrelevant for SQLite databases
150 * @param string $server
151 * @param string $user
152 * @param string $pass
153 * @param string $dbName
155 * @throws DBConnectionError
158 function open( $server, $user, $pass, $dbName ) {
160 $fileName = self::generateFileName( $this->dbDir, $dbName );
161 if ( !is_readable( $fileName ) ) {
162 $this->mConn = false;
163 throw new DBConnectionError( $this, "SQLite database not accessible" );
165 $this->openFile( $fileName );
167 return (bool)$this->mConn;
171 * Opens a database file
173 * @param string $fileName
174 * @throws DBConnectionError
175 * @return PDO|bool SQL connection or false if failed
177 protected function openFile( $fileName ) {
180 $this->dbPath = $fileName;
182 if ( $this->mFlags & self::DBO_PERSISTENT ) {
183 $this->mConn = new PDO( "sqlite:$fileName", '', '',
184 [ PDO::ATTR_PERSISTENT => true ] );
186 $this->mConn = new PDO( "sqlite:$fileName", '', '' );
188 } catch ( PDOException $e ) {
189 $err = $e->getMessage();
192 if ( !$this->mConn ) {
193 $this->queryLogger->debug( "DB connection error: $err\n" );
194 throw new DBConnectionError( $this, $err );
197 $this->mOpened = !!$this->mConn;
198 if ( $this->mOpened ) {
199 # Set error codes only, don't raise exceptions
200 $this->mConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
201 # Enforce LIKE to be case sensitive, just like MySQL
202 $this->query( 'PRAGMA case_sensitive_like = 1' );
211 * @return string SQLite DB file path
214 public function getDbFilePath() {
215 return $this->dbPath;
219 * Does not actually close the connection, just destroys the reference for GC to do its work
222 protected function closeConnection() {
229 * Generates a database file name. Explicitly public for installer.
230 * @param string $dir Directory where database resides
231 * @param string $dbName Database name
234 public static function generateFileName( $dir, $dbName ) {
235 return "$dir/$dbName.sqlite";
239 * Check if the searchindext table is FTS enabled.
240 * @return bool False if not enabled.
242 function checkForEnabledSearch() {
243 if ( self::$fulltextEnabled === null ) {
244 self::$fulltextEnabled = false;
245 $table = $this->tableName( 'searchindex' );
246 $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name = '$table'", __METHOD__ );
248 $row = $res->fetchRow();
249 self::$fulltextEnabled = stristr( $row['sql'], 'fts' ) !== false;
253 return self::$fulltextEnabled;
257 * Returns version of currently supported SQLite fulltext search module or false if none present.
260 static function getFulltextSearchModule() {
261 static $cachedResult = null;
262 if ( $cachedResult !== null ) {
263 return $cachedResult;
265 $cachedResult = false;
266 $table = 'dummy_search_test';
268 $db = self::newStandaloneInstance( ':memory:' );
269 if ( $db->query( "CREATE VIRTUAL TABLE $table USING FTS3(dummy_field)", __METHOD__, true ) ) {
270 $cachedResult = 'FTS3';
274 return $cachedResult;
278 * Attaches external database to our connection, see https://sqlite.org/lang_attach.html
281 * @param string $name Database name to be used in queries like
282 * SELECT foo FROM dbname.table
283 * @param bool|string $file Database file name. If omitted, will be generated
284 * using $name and configured data directory
285 * @param string $fname Calling function name
286 * @return ResultWrapper
288 function attachDatabase( $name, $file = false, $fname = __METHOD__ ) {
290 $file = self::generateFileName( $this->dbDir, $name );
292 $file = $this->addQuotes( $file );
294 return $this->query( "ATTACH DATABASE $file AS $name", $fname );
297 function isWriteQuery( $sql ) {
298 return parent::isWriteQuery( $sql ) && !preg_match( '/^(ATTACH|PRAGMA)\b/i', $sql );
302 * SQLite doesn't allow buffered results or data seeking etc, so we'll use fetchAll as the result
305 * @return bool|ResultWrapper
307 protected function doQuery( $sql ) {
308 $res = $this->mConn->query( $sql );
309 if ( $res === false ) {
313 $r = $res instanceof ResultWrapper ? $res->result : $res;
314 $this->mAffectedRows = $r->rowCount();
315 $res = new ResultWrapper( $this, $r->fetchAll() );
321 * @param ResultWrapper|mixed $res
323 function freeResult( $res ) {
324 if ( $res instanceof ResultWrapper ) {
332 * @param ResultWrapper|array $res
333 * @return stdClass|bool
335 function fetchObject( $res ) {
336 if ( $res instanceof ResultWrapper ) {
342 $cur = current( $r );
343 if ( is_array( $cur ) ) {
346 foreach ( $cur as $k => $v ) {
347 if ( !is_numeric( $k ) ) {
359 * @param ResultWrapper|mixed $res
362 function fetchRow( $res ) {
363 if ( $res instanceof ResultWrapper ) {
368 $cur = current( $r );
369 if ( is_array( $cur ) ) {
379 * The PDO::Statement class implements the array interface so count() will work
381 * @param ResultWrapper|array $res
384 function numRows( $res ) {
385 $r = $res instanceof ResultWrapper ? $res->result : $res;
391 * @param ResultWrapper $res
394 function numFields( $res ) {
395 $r = $res instanceof ResultWrapper ? $res->result : $res;
396 if ( is_array( $r ) && count( $r ) > 0 ) {
397 // The size of the result array is twice the number of fields. (Bug: 65578)
398 return count( $r[0] ) / 2;
400 // If the result is empty return 0
406 * @param ResultWrapper $res
410 function fieldName( $res, $n ) {
411 $r = $res instanceof ResultWrapper ? $res->result : $res;
412 if ( is_array( $r ) ) {
413 $keys = array_keys( $r[0] );
422 * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks
424 * @param string $name
425 * @param string $format
428 function tableName( $name, $format = 'quoted' ) {
429 // table names starting with sqlite_ are reserved
430 if ( strpos( $name, 'sqlite_' ) === 0 ) {
434 return str_replace( '"', '', parent::tableName( $name, $format ) );
438 * This must be called after nextSequenceVal
442 function insertId() {
443 // PDO::lastInsertId yields a string :(
444 return intval( $this->mConn->lastInsertId() );
448 * @param ResultWrapper|array $res
451 function dataSeek( $res, $row ) {
452 if ( $res instanceof ResultWrapper ) {
459 for ( $i = 0; $i < $row; $i++ ) {
468 function lastError() {
469 if ( !is_object( $this->mConn ) ) {
470 return "Cannot return last error, no db connection";
472 $e = $this->mConn->errorInfo();
474 return isset( $e[2] ) ? $e[2] : '';
480 function lastErrno() {
481 if ( !is_object( $this->mConn ) ) {
482 return "Cannot return last error, no db connection";
484 $info = $this->mConn->errorInfo();
493 function affectedRows() {
494 return $this->mAffectedRows;
498 * Returns information about an index
499 * Returns false if the index does not exist
500 * - if errors are explicitly ignored, returns NULL on failure
502 * @param string $table
503 * @param string $index
504 * @param string $fname
505 * @return array|false
507 function indexInfo( $table, $index, $fname = __METHOD__ ) {
508 $sql = 'PRAGMA index_info(' . $this->addQuotes( $this->indexName( $index ) ) . ')';
509 $res = $this->query( $sql, $fname );
510 if ( !$res || $res->numRows() == 0 ) {
514 foreach ( $res as $row ) {
515 $info[] = $row->name;
522 * @param string $table
523 * @param string $index
524 * @param string $fname
527 function indexUnique( $table, $index, $fname = __METHOD__ ) {
528 $row = $this->selectRow( 'sqlite_master', '*',
531 'name' => $this->indexName( $index ),
533 if ( !$row || !isset( $row->sql ) ) {
537 // $row->sql will be of the form CREATE [UNIQUE] INDEX ...
538 $indexPos = strpos( $row->sql, 'INDEX' );
539 if ( $indexPos === false ) {
542 $firstPart = substr( $row->sql, 0, $indexPos );
543 $options = explode( ' ', $firstPart );
545 return in_array( 'UNIQUE', $options );
549 * Filter the options used in SELECT statements
551 * @param array $options
554 function makeSelectOptions( $options ) {
555 foreach ( $options as $k => $v ) {
556 if ( is_numeric( $k ) && ( $v == 'FOR UPDATE' || $v == 'LOCK IN SHARE MODE' ) ) {
561 return parent::makeSelectOptions( $options );
565 * @param array $options
568 protected function makeUpdateOptionsArray( $options ) {
569 $options = parent::makeUpdateOptionsArray( $options );
570 $options = self::fixIgnore( $options );
576 * @param array $options
579 static function fixIgnore( $options ) {
580 # SQLite uses OR IGNORE not just IGNORE
581 foreach ( $options as $k => $v ) {
582 if ( $v == 'IGNORE' ) {
583 $options[$k] = 'OR IGNORE';
591 * @param array $options
594 function makeInsertOptions( $options ) {
595 $options = self::fixIgnore( $options );
597 return parent::makeInsertOptions( $options );
601 * Based on generic method (parent) with some prior SQLite-sepcific adjustments
602 * @param string $table
604 * @param string $fname
605 * @param array $options
608 function insert( $table, $a, $fname = __METHOD__, $options = [] ) {
609 if ( !count( $a ) ) {
613 # SQLite can't handle multi-row inserts, so divide up into multiple single-row inserts
614 if ( isset( $a[0] ) && is_array( $a[0] ) ) {
616 foreach ( $a as $v ) {
617 if ( !parent::insert( $table, $v, "$fname/multi-row", $options ) ) {
622 $ret = parent::insert( $table, $a, "$fname/single-row", $options );
629 * @param string $table
630 * @param array $uniqueIndexes Unused
631 * @param string|array $rows
632 * @param string $fname
633 * @return bool|ResultWrapper
635 function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
636 if ( !count( $rows ) ) {
640 # SQLite can't handle multi-row replaces, so divide up into multiple single-row queries
641 if ( isset( $rows[0] ) && is_array( $rows[0] ) ) {
643 foreach ( $rows as $v ) {
644 if ( !$this->nativeReplace( $table, $v, "$fname/multi-row" ) ) {
649 $ret = $this->nativeReplace( $table, $rows, "$fname/single-row" );
656 * Returns the size of a text field, or -1 for "unlimited"
657 * In SQLite this is SQLITE_MAX_LENGTH, by default 1GB. No way to query it though.
659 * @param string $table
660 * @param string $field
663 function textFieldSize( $table, $field ) {
670 function unionSupportsOrderAndLimit() {
675 * @param string[] $sqls
676 * @param bool $all Whether to "UNION ALL" or not
679 function unionQueries( $sqls, $all ) {
680 $glue = $all ? ' UNION ALL ' : ' UNION ';
682 return implode( $glue, $sqls );
688 function wasDeadlock() {
689 return $this->lastErrno() == 5; // SQLITE_BUSY
695 function wasErrorReissuable() {
696 return $this->lastErrno() == 17; // SQLITE_SCHEMA;
702 function wasReadOnlyError() {
703 return $this->lastErrno() == 8; // SQLITE_READONLY;
707 * @return string Wikitext of a link to the server software's web site
709 public function getSoftwareLink() {
710 return "[{{int:version-db-sqlite-url}} SQLite]";
714 * @return string Version information from the database
716 function getServerVersion() {
717 $ver = $this->mConn->getAttribute( PDO::ATTR_SERVER_VERSION );
723 * Get information about a given field
724 * Returns false if the field does not exist.
726 * @param string $table
727 * @param string $field
728 * @return SQLiteField|bool False on failure
730 function fieldInfo( $table, $field ) {
731 $tableName = $this->tableName( $table );
732 $sql = 'PRAGMA table_info(' . $this->addQuotes( $tableName ) . ')';
733 $res = $this->query( $sql, __METHOD__ );
734 foreach ( $res as $row ) {
735 if ( $row->name == $field ) {
736 return new SQLiteField( $row, $tableName );
743 protected function doBegin( $fname = '' ) {
744 if ( $this->trxMode ) {
745 $this->query( "BEGIN {$this->trxMode}", $fname );
747 $this->query( 'BEGIN', $fname );
749 $this->mTrxLevel = 1;
756 function strencode( $s ) {
757 return substr( $this->addQuotes( $s ), 1, -1 );
764 function encodeBlob( $b ) {
765 return new Blob( $b );
769 * @param Blob|string $b
772 function decodeBlob( $b ) {
773 if ( $b instanceof Blob ) {
781 * @param string|int|null|bool|Blob $s
784 function addQuotes( $s ) {
785 if ( $s instanceof Blob ) {
786 return "x'" . bin2hex( $s->fetch() ) . "'";
787 } elseif ( is_bool( $s ) ) {
789 } elseif ( strpos( (string)$s, "\0" ) !== false ) {
790 // SQLite doesn't support \0 in strings, so use the hex representation as a workaround.
791 // This is a known limitation of SQLite's mprintf function which PDO
792 // should work around, but doesn't. I have reported this to php.net as bug #63419:
793 // https://bugs.php.net/bug.php?id=63419
794 // There was already a similar report for SQLite3::escapeString, bug #62361:
795 // https://bugs.php.net/bug.php?id=62361
796 // There is an additional bug regarding sorting this data after insert
797 // on older versions of sqlite shipped with ubuntu 12.04
798 // https://phabricator.wikimedia.org/T74367
799 $this->queryLogger->debug(
801 ': Quoting value containing null byte. ' .
802 'For consistency all binary data should have been ' .
803 'first processed with self::encodeBlob()'
805 return "x'" . bin2hex( (string)$s ) . "'";
807 return $this->mConn->quote( (string)$s );
812 * @param string $field Field or column to cast
816 public function buildStringCast( $field ) {
817 return 'CAST ( ' . $field . ' AS TEXT )';
821 * No-op version of deadlockLoop
825 public function deadlockLoop( /*...*/ ) {
826 $args = func_get_args();
827 $function = array_shift( $args );
829 return call_user_func_array( $function, $args );
836 protected function replaceVars( $s ) {
837 $s = parent::replaceVars( $s );
838 if ( preg_match( '/^\s*(CREATE|ALTER) TABLE/i', $s ) ) {
839 // CREATE TABLE hacks to allow schema file sharing with MySQL
841 // binary/varbinary column type -> blob
842 $s = preg_replace( '/\b(var)?binary(\(\d+\))/i', 'BLOB', $s );
843 // no such thing as unsigned
844 $s = preg_replace( '/\b(un)?signed\b/i', '', $s );
846 $s = preg_replace( '/\b(tiny|small|medium|big|)int(\s*\(\s*\d+\s*\)|\b)/i', 'INTEGER', $s );
847 // floating point types -> REAL
849 '/\b(float|double(\s+precision)?)(\s*\(\s*\d+\s*(,\s*\d+\s*)?\)|\b)/i',
854 $s = preg_replace( '/\b(var)?char\s*\(.*?\)/i', 'TEXT', $s );
855 // TEXT normalization
856 $s = preg_replace( '/\b(tiny|medium|long)text\b/i', 'TEXT', $s );
857 // BLOB normalization
858 $s = preg_replace( '/\b(tiny|small|medium|long|)blob\b/i', 'BLOB', $s );
860 $s = preg_replace( '/\bbool(ean)?\b/i', 'INTEGER', $s );
862 $s = preg_replace( '/\b(datetime|timestamp)\b/i', 'TEXT', $s );
864 $s = preg_replace( '/\benum\s*\([^)]*\)/i', 'TEXT', $s );
865 // binary collation type -> nothing
866 $s = preg_replace( '/\bbinary\b/i', '', $s );
867 // auto_increment -> autoincrement
868 $s = preg_replace( '/\bauto_increment\b/i', 'AUTOINCREMENT', $s );
869 // No explicit options
870 $s = preg_replace( '/\)[^);]*(;?)\s*$/', ')\1', $s );
871 // AUTOINCREMENT should immedidately follow PRIMARY KEY
872 $s = preg_replace( '/primary key (.*?) autoincrement/i', 'PRIMARY KEY AUTOINCREMENT $1', $s );
873 } elseif ( preg_match( '/^\s*CREATE (\s*(?:UNIQUE|FULLTEXT)\s+)?INDEX/i', $s ) ) {
874 // No truncated indexes
875 $s = preg_replace( '/\(\d+\)/', '', $s );
877 $s = preg_replace( '/\bfulltext\b/i', '', $s );
878 } elseif ( preg_match( '/^\s*DROP INDEX/i', $s ) ) {
879 // DROP INDEX is database-wide, not table-specific, so no ON <table> clause.
880 $s = preg_replace( '/\sON\s+[^\s]*/i', '', $s );
881 } elseif ( preg_match( '/^\s*INSERT IGNORE\b/i', $s ) ) {
882 // INSERT IGNORE --> INSERT OR IGNORE
883 $s = preg_replace( '/^\s*INSERT IGNORE\b/i', 'INSERT OR IGNORE', $s );
889 public function lock( $lockName, $method, $timeout = 5 ) {
890 if ( !is_dir( "{$this->dbDir}/locks" ) ) { // create dir as needed
891 if ( !is_writable( $this->dbDir ) || !mkdir( "{$this->dbDir}/locks" ) ) {
892 throw new DBError( $this, "Cannot create directory \"{$this->dbDir}/locks\"." );
896 return $this->lockMgr->lock( [ $lockName ], LockManager::LOCK_EX, $timeout )->isOK();
899 public function unlock( $lockName, $method ) {
900 return $this->lockMgr->unlock( [ $lockName ], LockManager::LOCK_EX )->isOK();
904 * Build a concatenation list to feed into a SQL query
906 * @param string[] $stringList
909 function buildConcat( $stringList ) {
910 return '(' . implode( ') || (', $stringList ) . ')';
913 public function buildGroupConcatField(
914 $delim, $table, $field, $conds = '', $join_conds = []
916 $fld = "group_concat($field," . $this->addQuotes( $delim ) . ')';
918 return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')';
922 * @param string $oldName
923 * @param string $newName
924 * @param bool $temporary
925 * @param string $fname
926 * @return bool|ResultWrapper
927 * @throws RuntimeException
929 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__ ) {
930 $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" .
931 $this->addQuotes( $oldName ) . " AND type='table'", $fname );
932 $obj = $this->fetchObject( $res );
934 throw new RuntimeException( "Couldn't retrieve structure for table $oldName" );
938 '/(?<=\W)"?' . preg_quote( trim( $this->addIdentifierQuotes( $oldName ), '"' ) ) . '"?(?=\W)/',
939 $this->addIdentifierQuotes( $newName ),
944 if ( preg_match( '/^\\s*CREATE\\s+VIRTUAL\\s+TABLE\b/i', $sql ) ) {
945 $this->queryLogger->debug(
946 "Table $oldName is virtual, can't create a temporary duplicate.\n" );
948 $sql = str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $sql );
952 $res = $this->query( $sql, $fname );
955 $indexList = $this->query( 'PRAGMA INDEX_LIST(' . $this->addQuotes( $oldName ) . ')' );
956 foreach ( $indexList as $index ) {
957 if ( strpos( $index->name, 'sqlite_autoindex' ) === 0 ) {
961 if ( $index->unique ) {
962 $sql = 'CREATE UNIQUE INDEX';
964 $sql = 'CREATE INDEX';
966 // Try to come up with a new index name, given indexes have database scope in SQLite
967 $indexName = $newName . '_' . $index->name;
968 $sql .= ' ' . $indexName . ' ON ' . $newName;
970 $indexInfo = $this->query( 'PRAGMA INDEX_INFO(' . $this->addQuotes( $index->name ) . ')' );
972 foreach ( $indexInfo as $indexInfoRow ) {
973 $fields[$indexInfoRow->seqno] = $indexInfoRow->name;
976 $sql .= '(' . implode( ',', $fields ) . ')';
978 $this->query( $sql );
985 * List all tables on the database
987 * @param string $prefix Only show tables with this prefix, e.g. mw_
988 * @param string $fname Calling function name
992 function listTables( $prefix = null, $fname = __METHOD__ ) {
993 $result = $this->select(
1001 foreach ( $result as $table ) {
1002 $vars = get_object_vars( $table );
1003 $table = array_pop( $vars );
1005 if ( !$prefix || strpos( $table, $prefix ) === 0 ) {
1006 if ( strpos( $table, 'sqlite_' ) !== 0 ) {
1007 $endArray[] = $table;
1016 * Override due to no CASCADE support
1018 * @param string $tableName
1019 * @param string $fName
1020 * @return bool|ResultWrapper
1021 * @throws DBReadOnlyError
1023 public function dropTable( $tableName, $fName = __METHOD__ ) {
1024 if ( !$this->tableExists( $tableName, $fName ) ) {
1027 $sql = "DROP TABLE " . $this->tableName( $tableName );
1029 return $this->query( $sql, $fName );
1032 protected function requiresDatabaseUser() {
1033 return false; // just a file
1039 public function __toString() {
1040 return 'SQLite ' . (string)$this->mConn->getAttribute( PDO::ATTR_SERVER_VERSION );
1044 class_alias( DatabaseSqlite::class, 'DatabaseSqlite' );