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
28 class DatabaseSqlite
extends Database
{
29 /** @var bool Whether full text is enabled */
30 private static $fulltextEnabled = null;
32 /** @var string Directory */
35 /** @var string File name for SQLite database file */
38 /** @var string Transaction mode */
41 /** @var int The number of rows affected as an integer */
42 protected $mAffectedRows;
45 protected $mLastResult;
50 /** @var FSLockManager (hopefully on the same server as the DB) */
54 * Additional params include:
55 * - dbDirectory : directory containing the DB and the lock file directory
56 * [defaults to $wgSQLiteDataDir]
57 * - dbFilePath : use this to force the path of the DB file
58 * - trxMode : one of (deferred, immediate, exclusive)
61 function __construct( array $p ) {
62 global $wgSQLiteDataDir;
64 $this->dbDir
= isset( $p['dbDirectory'] ) ?
$p['dbDirectory'] : $wgSQLiteDataDir;
66 if ( isset( $p['dbFilePath'] ) ) {
67 parent
::__construct( $p );
68 // Standalone .sqlite file mode.
69 // Super doesn't open when $user is false, but we can work with $dbName,
70 // which is derived from the file path in this case.
71 $this->openFile( $p['dbFilePath'] );
73 $this->mDBname
= $p['dbname'];
74 // Stock wiki mode using standard file names per DB.
75 parent
::__construct( $p );
76 // Super doesn't open when $user is false, but we can work with $dbName
77 if ( $p['dbname'] && !$this->isOpen() ) {
78 if ( $this->open( $p['host'], $p['user'], $p['password'], $p['dbname'] ) ) {
80 foreach ( $this->tableAliases
as $params ) {
81 if ( isset( $done[$params['dbname']] ) ) {
84 $this->attachDatabase( $params['dbname'] );
85 $done[$params['dbname']] = 1;
91 $this->trxMode
= isset( $p['trxMode'] ) ?
strtoupper( $p['trxMode'] ) : null;
92 if ( $this->trxMode
&&
93 !in_array( $this->trxMode
, [ 'DEFERRED', 'IMMEDIATE', 'EXCLUSIVE' ] )
95 $this->trxMode
= null;
96 wfWarn( "Invalid SQLite transaction mode provided." );
99 $this->lockMgr
= new FSLockManager( [ 'lockDirectory' => "{$this->dbDir}/locks" ] );
103 * @param string $filename
104 * @param array $p Options map; supports:
105 * - flags : (same as __construct counterpart)
106 * - trxMode : (same as __construct counterpart)
107 * - dbDirectory : (same as __construct counterpart)
108 * @return DatabaseSqlite
111 public static function newStandaloneInstance( $filename, array $p = [] ) {
112 $p['dbFilePath'] = $filename;
113 $p['schema'] = false;
114 $p['tablePrefix'] = '';
116 return DatabaseBase
::factory( 'sqlite', $p );
127 * @todo Check if it should be true like parent class
131 function implicitGroupby() {
135 /** Open an SQLite database and return a resource handle to it
136 * NOTE: only $dbName is used, the other parameters are irrelevant for SQLite databases
138 * @param string $server
139 * @param string $user
140 * @param string $pass
141 * @param string $dbName
143 * @throws DBConnectionError
146 function open( $server, $user, $pass, $dbName ) {
148 $fileName = self
::generateFileName( $this->dbDir
, $dbName );
149 if ( !is_readable( $fileName ) ) {
150 $this->mConn
= false;
151 throw new DBConnectionError( $this, "SQLite database not accessible" );
153 $this->openFile( $fileName );
159 * Opens a database file
161 * @param string $fileName
162 * @throws DBConnectionError
163 * @return PDO|bool SQL connection or false if failed
165 protected function openFile( $fileName ) {
168 $this->dbPath
= $fileName;
170 if ( $this->mFlags
& DBO_PERSISTENT
) {
171 $this->mConn
= new PDO( "sqlite:$fileName", '', '',
172 [ PDO
::ATTR_PERSISTENT
=> true ] );
174 $this->mConn
= new PDO( "sqlite:$fileName", '', '' );
176 } catch ( PDOException
$e ) {
177 $err = $e->getMessage();
180 if ( !$this->mConn
) {
181 wfDebug( "DB connection error: $err\n" );
182 throw new DBConnectionError( $this, $err );
185 $this->mOpened
= !!$this->mConn
;
186 if ( $this->mOpened
) {
187 # Set error codes only, don't raise exceptions
188 $this->mConn
->setAttribute( PDO
::ATTR_ERRMODE
, PDO
::ERRMODE_SILENT
);
189 # Enforce LIKE to be case sensitive, just like MySQL
190 $this->query( 'PRAGMA case_sensitive_like = 1' );
199 * @return string SQLite DB file path
202 public function getDbFilePath() {
203 return $this->dbPath
;
207 * Does not actually close the connection, just destroys the reference for GC to do its work
210 protected function closeConnection() {
217 * Generates a database file name. Explicitly public for installer.
218 * @param string $dir Directory where database resides
219 * @param string $dbName Database name
222 public static function generateFileName( $dir, $dbName ) {
223 return "$dir/$dbName.sqlite";
227 * Check if the searchindext table is FTS enabled.
228 * @return bool False if not enabled.
230 function checkForEnabledSearch() {
231 if ( self
::$fulltextEnabled === null ) {
232 self
::$fulltextEnabled = false;
233 $table = $this->tableName( 'searchindex' );
234 $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name = '$table'", __METHOD__
);
236 $row = $res->fetchRow();
237 self
::$fulltextEnabled = stristr( $row['sql'], 'fts' ) !== false;
241 return self
::$fulltextEnabled;
245 * Returns version of currently supported SQLite fulltext search module or false if none present.
248 static function getFulltextSearchModule() {
249 static $cachedResult = null;
250 if ( $cachedResult !== null ) {
251 return $cachedResult;
253 $cachedResult = false;
254 $table = 'dummy_search_test';
256 $db = self
::newStandaloneInstance( ':memory:' );
257 if ( $db->query( "CREATE VIRTUAL TABLE $table USING FTS3(dummy_field)", __METHOD__
, true ) ) {
258 $cachedResult = 'FTS3';
262 return $cachedResult;
266 * Attaches external database to our connection, see http://sqlite.org/lang_attach.html
269 * @param string $name Database name to be used in queries like
270 * SELECT foo FROM dbname.table
271 * @param bool|string $file Database file name. If omitted, will be generated
272 * using $name and configured data directory
273 * @param string $fname Calling function name
274 * @return ResultWrapper
276 function attachDatabase( $name, $file = false, $fname = __METHOD__
) {
278 $file = self
::generateFileName( $this->dbDir
, $name );
280 $file = $this->addQuotes( $file );
282 return $this->query( "ATTACH DATABASE $file AS $name", $fname );
285 function isWriteQuery( $sql ) {
286 return parent
::isWriteQuery( $sql ) && !preg_match( '/^(ATTACH|PRAGMA)\b/i', $sql );
290 * SQLite doesn't allow buffered results or data seeking etc, so we'll use fetchAll as the result
293 * @return bool|ResultWrapper
295 protected function doQuery( $sql ) {
296 $res = $this->mConn
->query( $sql );
297 if ( $res === false ) {
300 $r = $res instanceof ResultWrapper ?
$res->result
: $res;
301 $this->mAffectedRows
= $r->rowCount();
302 $res = new ResultWrapper( $this, $r->fetchAll() );
309 * @param ResultWrapper|mixed $res
311 function freeResult( $res ) {
312 if ( $res instanceof ResultWrapper
) {
320 * @param ResultWrapper|array $res
321 * @return stdClass|bool
323 function fetchObject( $res ) {
324 if ( $res instanceof ResultWrapper
) {
330 $cur = current( $r );
331 if ( is_array( $cur ) ) {
334 foreach ( $cur as $k => $v ) {
335 if ( !is_numeric( $k ) ) {
347 * @param ResultWrapper|mixed $res
350 function fetchRow( $res ) {
351 if ( $res instanceof ResultWrapper
) {
356 $cur = current( $r );
357 if ( is_array( $cur ) ) {
367 * The PDO::Statement class implements the array interface so count() will work
369 * @param ResultWrapper|array $res
372 function numRows( $res ) {
373 $r = $res instanceof ResultWrapper ?
$res->result
: $res;
379 * @param ResultWrapper $res
382 function numFields( $res ) {
383 $r = $res instanceof ResultWrapper ?
$res->result
: $res;
384 if ( is_array( $r ) && count( $r ) > 0 ) {
385 // The size of the result array is twice the number of fields. (Bug: 65578)
386 return count( $r[0] ) / 2;
388 // If the result is empty return 0
394 * @param ResultWrapper $res
398 function fieldName( $res, $n ) {
399 $r = $res instanceof ResultWrapper ?
$res->result
: $res;
400 if ( is_array( $r ) ) {
401 $keys = array_keys( $r[0] );
410 * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks
412 * @param string $name
413 * @param string $format
416 function tableName( $name, $format = 'quoted' ) {
417 // table names starting with sqlite_ are reserved
418 if ( strpos( $name, 'sqlite_' ) === 0 ) {
422 return str_replace( '"', '', parent
::tableName( $name, $format ) );
426 * Index names have DB scope
428 * @param string $index
431 protected function indexName( $index ) {
436 * This must be called after nextSequenceVal
440 function insertId() {
441 // PDO::lastInsertId yields a string :(
442 return intval( $this->mConn
->lastInsertId() );
446 * @param ResultWrapper|array $res
449 function dataSeek( $res, $row ) {
450 if ( $res instanceof ResultWrapper
) {
457 for ( $i = 0; $i < $row; $i++
) {
466 function lastError() {
467 if ( !is_object( $this->mConn
) ) {
468 return "Cannot return last error, no db connection";
470 $e = $this->mConn
->errorInfo();
472 return isset( $e[2] ) ?
$e[2] : '';
478 function lastErrno() {
479 if ( !is_object( $this->mConn
) ) {
480 return "Cannot return last error, no db connection";
482 $info = $this->mConn
->errorInfo();
491 function affectedRows() {
492 return $this->mAffectedRows
;
496 * Returns information about an index
497 * Returns false if the index does not exist
498 * - if errors are explicitly ignored, returns NULL on failure
500 * @param string $table
501 * @param string $index
502 * @param string $fname
505 function indexInfo( $table, $index, $fname = __METHOD__
) {
506 $sql = 'PRAGMA index_info(' . $this->addQuotes( $this->indexName( $index ) ) . ')';
507 $res = $this->query( $sql, $fname );
511 if ( $res->numRows() == 0 ) {
515 foreach ( $res as $row ) {
516 $info[] = $row->name
;
523 * @param string $table
524 * @param string $index
525 * @param string $fname
528 function indexUnique( $table, $index, $fname = __METHOD__
) {
529 $row = $this->selectRow( 'sqlite_master', '*',
532 'name' => $this->indexName( $index ),
534 if ( !$row ||
!isset( $row->sql
) ) {
538 // $row->sql will be of the form CREATE [UNIQUE] INDEX ...
539 $indexPos = strpos( $row->sql
, 'INDEX' );
540 if ( $indexPos === false ) {
543 $firstPart = substr( $row->sql
, 0, $indexPos );
544 $options = explode( ' ', $firstPart );
546 return in_array( 'UNIQUE', $options );
550 * Filter the options used in SELECT statements
552 * @param array $options
555 function makeSelectOptions( $options ) {
556 foreach ( $options as $k => $v ) {
557 if ( is_numeric( $k ) && ( $v == 'FOR UPDATE' ||
$v == 'LOCK IN SHARE MODE' ) ) {
562 return parent
::makeSelectOptions( $options );
566 * @param array $options
569 protected function makeUpdateOptionsArray( $options ) {
570 $options = parent
::makeUpdateOptionsArray( $options );
571 $options = self
::fixIgnore( $options );
577 * @param array $options
580 static function fixIgnore( $options ) {
581 # SQLite uses OR IGNORE not just IGNORE
582 foreach ( $options as $k => $v ) {
583 if ( $v == 'IGNORE' ) {
584 $options[$k] = 'OR IGNORE';
592 * @param array $options
595 function makeInsertOptions( $options ) {
596 $options = self
::fixIgnore( $options );
598 return parent
::makeInsertOptions( $options );
602 * Based on generic method (parent) with some prior SQLite-sepcific adjustments
603 * @param string $table
605 * @param string $fname
606 * @param array $options
609 function insert( $table, $a, $fname = __METHOD__
, $options = [] ) {
610 if ( !count( $a ) ) {
614 # SQLite can't handle multi-row inserts, so divide up into multiple single-row inserts
615 if ( isset( $a[0] ) && is_array( $a[0] ) ) {
617 foreach ( $a as $v ) {
618 if ( !parent
::insert( $table, $v, "$fname/multi-row", $options ) ) {
623 $ret = parent
::insert( $table, $a, "$fname/single-row", $options );
630 * @param string $table
631 * @param array $uniqueIndexes Unused
632 * @param string|array $rows
633 * @param string $fname
634 * @return bool|ResultWrapper
636 function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__
) {
637 if ( !count( $rows ) ) {
641 # SQLite can't handle multi-row replaces, so divide up into multiple single-row queries
642 if ( isset( $rows[0] ) && is_array( $rows[0] ) ) {
644 foreach ( $rows as $v ) {
645 if ( !$this->nativeReplace( $table, $v, "$fname/multi-row" ) ) {
650 $ret = $this->nativeReplace( $table, $rows, "$fname/single-row" );
657 * Returns the size of a text field, or -1 for "unlimited"
658 * In SQLite this is SQLITE_MAX_LENGTH, by default 1GB. No way to query it though.
660 * @param string $table
661 * @param string $field
664 function textFieldSize( $table, $field ) {
671 function unionSupportsOrderAndLimit() {
676 * @param string $sqls
677 * @param bool $all Whether to "UNION ALL" or not
680 function unionQueries( $sqls, $all ) {
681 $glue = $all ?
' UNION ALL ' : ' UNION ';
683 return implode( $glue, $sqls );
689 function wasDeadlock() {
690 return $this->lastErrno() == 5; // SQLITE_BUSY
696 function wasErrorReissuable() {
697 return $this->lastErrno() == 17; // SQLITE_SCHEMA;
703 function wasReadOnlyError() {
704 return $this->lastErrno() == 8; // SQLITE_READONLY;
708 * @return string Wikitext of a link to the server software's web site
710 public function getSoftwareLink() {
711 return "[{{int:version-db-sqlite-url}} SQLite]";
715 * @return string Version information from the database
717 function getServerVersion() {
718 $ver = $this->mConn
->getAttribute( PDO
::ATTR_SERVER_VERSION
);
724 * @return string User-friendly database information
726 public function getServerInfo() {
727 return wfMessage( self
::getFulltextSearchModule()
729 : 'sqlite-no-fts', $this->getServerVersion() )->text();
733 * Get information about a given field
734 * Returns false if the field does not exist.
736 * @param string $table
737 * @param string $field
738 * @return SQLiteField|bool False on failure
740 function fieldInfo( $table, $field ) {
741 $tableName = $this->tableName( $table );
742 $sql = 'PRAGMA table_info(' . $this->addQuotes( $tableName ) . ')';
743 $res = $this->query( $sql, __METHOD__
);
744 foreach ( $res as $row ) {
745 if ( $row->name
== $field ) {
746 return new SQLiteField( $row, $tableName );
753 protected function doBegin( $fname = '' ) {
754 if ( $this->trxMode
) {
755 $this->query( "BEGIN {$this->trxMode}", $fname );
757 $this->query( 'BEGIN', $fname );
759 $this->mTrxLevel
= 1;
766 function strencode( $s ) {
767 return substr( $this->addQuotes( $s ), 1, -1 );
774 function encodeBlob( $b ) {
775 return new Blob( $b );
779 * @param Blob|string $b
782 function decodeBlob( $b ) {
783 if ( $b instanceof Blob
) {
791 * @param Blob|string $s
794 function addQuotes( $s ) {
795 if ( $s instanceof Blob
) {
796 return "x'" . bin2hex( $s->fetch() ) . "'";
797 } elseif ( is_bool( $s ) ) {
799 } elseif ( strpos( $s, "\0" ) !== false ) {
800 // SQLite doesn't support \0 in strings, so use the hex representation as a workaround.
801 // This is a known limitation of SQLite's mprintf function which PDO
802 // should work around, but doesn't. I have reported this to php.net as bug #63419:
803 // https://bugs.php.net/bug.php?id=63419
804 // There was already a similar report for SQLite3::escapeString, bug #62361:
805 // https://bugs.php.net/bug.php?id=62361
806 // There is an additional bug regarding sorting this data after insert
807 // on older versions of sqlite shipped with ubuntu 12.04
808 // https://phabricator.wikimedia.org/T74367
812 ': Quoting value containing null byte. ' .
813 'For consistency all binary data should have been ' .
814 'first processed with self::encodeBlob()'
816 return "x'" . bin2hex( $s ) . "'";
818 return $this->mConn
->quote( $s );
825 function buildLike() {
826 $params = func_get_args();
827 if ( count( $params ) > 0 && is_array( $params[0] ) ) {
828 $params = $params[0];
831 return parent
::buildLike( $params ) . "ESCAPE '\' ";
835 * @param string $field Field or column to cast
839 public function buildStringCast( $field ) {
840 return 'CAST ( ' . $field . ' AS TEXT )';
846 public function getSearchEngine() {
847 return "SearchSqlite";
851 * No-op version of deadlockLoop
855 public function deadlockLoop( /*...*/ ) {
856 $args = func_get_args();
857 $function = array_shift( $args );
859 return call_user_func_array( $function, $args );
866 protected function replaceVars( $s ) {
867 $s = parent
::replaceVars( $s );
868 if ( preg_match( '/^\s*(CREATE|ALTER) TABLE/i', $s ) ) {
869 // CREATE TABLE hacks to allow schema file sharing with MySQL
871 // binary/varbinary column type -> blob
872 $s = preg_replace( '/\b(var)?binary(\(\d+\))/i', 'BLOB', $s );
873 // no such thing as unsigned
874 $s = preg_replace( '/\b(un)?signed\b/i', '', $s );
876 $s = preg_replace( '/\b(tiny|small|medium|big|)int(\s*\(\s*\d+\s*\)|\b)/i', 'INTEGER', $s );
877 // floating point types -> REAL
879 '/\b(float|double(\s+precision)?)(\s*\(\s*\d+\s*(,\s*\d+\s*)?\)|\b)/i',
884 $s = preg_replace( '/\b(var)?char\s*\(.*?\)/i', 'TEXT', $s );
885 // TEXT normalization
886 $s = preg_replace( '/\b(tiny|medium|long)text\b/i', 'TEXT', $s );
887 // BLOB normalization
888 $s = preg_replace( '/\b(tiny|small|medium|long|)blob\b/i', 'BLOB', $s );
890 $s = preg_replace( '/\bbool(ean)?\b/i', 'INTEGER', $s );
892 $s = preg_replace( '/\b(datetime|timestamp)\b/i', 'TEXT', $s );
894 $s = preg_replace( '/\benum\s*\([^)]*\)/i', 'TEXT', $s );
895 // binary collation type -> nothing
896 $s = preg_replace( '/\bbinary\b/i', '', $s );
897 // auto_increment -> autoincrement
898 $s = preg_replace( '/\bauto_increment\b/i', 'AUTOINCREMENT', $s );
899 // No explicit options
900 $s = preg_replace( '/\)[^);]*(;?)\s*$/', ')\1', $s );
901 // AUTOINCREMENT should immedidately follow PRIMARY KEY
902 $s = preg_replace( '/primary key (.*?) autoincrement/i', 'PRIMARY KEY AUTOINCREMENT $1', $s );
903 } elseif ( preg_match( '/^\s*CREATE (\s*(?:UNIQUE|FULLTEXT)\s+)?INDEX/i', $s ) ) {
904 // No truncated indexes
905 $s = preg_replace( '/\(\d+\)/', '', $s );
907 $s = preg_replace( '/\bfulltext\b/i', '', $s );
908 } elseif ( preg_match( '/^\s*DROP INDEX/i', $s ) ) {
909 // DROP INDEX is database-wide, not table-specific, so no ON <table> clause.
910 $s = preg_replace( '/\sON\s+[^\s]*/i', '', $s );
911 } elseif ( preg_match( '/^\s*INSERT IGNORE\b/i', $s ) ) {
912 // INSERT IGNORE --> INSERT OR IGNORE
913 $s = preg_replace( '/^\s*INSERT IGNORE\b/i', 'INSERT OR IGNORE', $s );
919 public function lock( $lockName, $method, $timeout = 5 ) {
920 if ( !is_dir( "{$this->dbDir}/locks" ) ) { // create dir as needed
921 if ( !is_writable( $this->dbDir
) ||
!mkdir( "{$this->dbDir}/locks" ) ) {
922 throw new DBError( $this, "Cannot create directory \"{$this->dbDir}/locks\"." );
926 return $this->lockMgr
->lock( [ $lockName ], LockManager
::LOCK_EX
, $timeout )->isOK();
929 public function unlock( $lockName, $method ) {
930 return $this->lockMgr
->unlock( [ $lockName ], LockManager
::LOCK_EX
)->isOK();
934 * Build a concatenation list to feed into a SQL query
936 * @param string[] $stringList
939 function buildConcat( $stringList ) {
940 return '(' . implode( ') || (', $stringList ) . ')';
943 public function buildGroupConcatField(
944 $delim, $table, $field, $conds = '', $join_conds = []
946 $fld = "group_concat($field," . $this->addQuotes( $delim ) . ')';
948 return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')';
952 * @param string $oldName
953 * @param string $newName
954 * @param bool $temporary
955 * @param string $fname
956 * @return bool|ResultWrapper
957 * @throws RuntimeException
959 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__
) {
960 $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" .
961 $this->addQuotes( $oldName ) . " AND type='table'", $fname );
962 $obj = $this->fetchObject( $res );
964 throw new RuntimeException( "Couldn't retrieve structure for table $oldName" );
968 '/(?<=\W)"?' . preg_quote( trim( $this->addIdentifierQuotes( $oldName ), '"' ) ) . '"?(?=\W)/',
969 $this->addIdentifierQuotes( $newName ),
974 if ( preg_match( '/^\\s*CREATE\\s+VIRTUAL\\s+TABLE\b/i', $sql ) ) {
975 wfDebug( "Table $oldName is virtual, can't create a temporary duplicate.\n" );
977 $sql = str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $sql );
981 $res = $this->query( $sql, $fname );
984 $indexList = $this->query( 'PRAGMA INDEX_LIST(' . $this->addQuotes( $oldName ) . ')' );
985 foreach ( $indexList as $index ) {
986 if ( strpos( $index->name
, 'sqlite_autoindex' ) === 0 ) {
990 if ( $index->unique
) {
991 $sql = 'CREATE UNIQUE INDEX';
993 $sql = 'CREATE INDEX';
995 // Try to come up with a new index name, given indexes have database scope in SQLite
996 $indexName = $newName . '_' . $index->name
;
997 $sql .= ' ' . $indexName . ' ON ' . $newName;
999 $indexInfo = $this->query( 'PRAGMA INDEX_INFO(' . $this->addQuotes( $index->name
) . ')' );
1001 foreach ( $indexInfo as $indexInfoRow ) {
1002 $fields[$indexInfoRow->seqno
] = $indexInfoRow->name
;
1005 $sql .= '(' . implode( ',', $fields ) . ')';
1007 $this->query( $sql );
1014 * List all tables on the database
1016 * @param string $prefix Only show tables with this prefix, e.g. mw_
1017 * @param string $fname Calling function name
1021 function listTables( $prefix = null, $fname = __METHOD__
) {
1022 $result = $this->select(
1030 foreach ( $result as $table ) {
1031 $vars = get_object_vars( $table );
1032 $table = array_pop( $vars );
1034 if ( !$prefix ||
strpos( $table, $prefix ) === 0 ) {
1035 if ( strpos( $table, 'sqlite_' ) !== 0 ) {
1036 $endArray[] = $table;
1047 public function __toString() {
1048 return 'SQLite ' . (string)$this->mConn
->getAttribute( PDO
::ATTR_SERVER_VERSION
);
1051 } // end DatabaseSqlite class