MediaWiki  1.31.0
DatabaseSqlite.php
Go to the documentation of this file.
1 <?php
24 namespace Wikimedia\Rdbms;
25 
26 use PDO;
27 use PDOException;
30 use InvalidArgumentException;
31 use RuntimeException;
32 use stdClass;
33 
37 class DatabaseSqlite extends Database {
39  private static $fulltextEnabled = null;
40 
42  protected $dbDir;
44  protected $dbPath;
46  protected $trxMode;
47 
51  protected $lastResultHandle;
52 
54  protected $conn;
55 
57  protected $lockMgr;
58 
60  private $alreadyAttached = [];
61 
70  function __construct( array $p ) {
71  if ( isset( $p['dbFilePath'] ) ) {
72  $this->dbPath = $p['dbFilePath'];
73  $lockDomain = md5( $this->dbPath );
74  } elseif ( isset( $p['dbDirectory'] ) ) {
75  $this->dbDir = $p['dbDirectory'];
76  $lockDomain = $p['dbname'];
77  } else {
78  throw new InvalidArgumentException( "Need 'dbDirectory' or 'dbFilePath' parameter." );
79  }
80 
81  $this->trxMode = isset( $p['trxMode'] ) ? strtoupper( $p['trxMode'] ) : null;
82  if ( $this->trxMode &&
83  !in_array( $this->trxMode, [ 'DEFERRED', 'IMMEDIATE', 'EXCLUSIVE' ] )
84  ) {
85  $this->trxMode = null;
86  $this->queryLogger->warning( "Invalid SQLite transaction mode provided." );
87  }
88 
89  $this->lockMgr = new FSLockManager( [
90  'domain' => $lockDomain,
91  'lockDirectory' => "{$this->dbDir}/locks"
92  ] );
93 
94  parent::__construct( $p );
95  }
96 
97  protected static function getAttributes() {
98  return [ self::ATTR_DB_LEVEL_LOCKING => true ];
99  }
100 
110  public static function newStandaloneInstance( $filename, array $p = [] ) {
111  $p['dbFilePath'] = $filename;
112  $p['schema'] = false;
113  $p['tablePrefix'] = '';
115  $db = Database::factory( 'sqlite', $p );
116 
117  return $db;
118  }
119 
120  protected function doInitConnection() {
121  if ( $this->dbPath !== null ) {
122  // Standalone .sqlite file mode.
123  $this->openFile( $this->dbPath, $this->connectionParams['dbname'] );
124  } elseif ( $this->dbDir !== null ) {
125  // Stock wiki mode using standard file names per DB
126  if ( strlen( $this->connectionParams['dbname'] ) ) {
127  $this->open(
128  $this->connectionParams['host'],
129  $this->connectionParams['user'],
130  $this->connectionParams['password'],
131  $this->connectionParams['dbname']
132  );
133  } else {
134  // Caller will manually call open() later?
135  $this->connLogger->debug( __METHOD__ . ': no database opened.' );
136  }
137  } else {
138  throw new InvalidArgumentException( "Need 'dbDirectory' or 'dbFilePath' parameter." );
139  }
140  }
141 
145  function getType() {
146  return 'sqlite';
147  }
148 
154  function implicitGroupby() {
155  return false;
156  }
157 
169  function open( $server, $user, $pass, $dbName ) {
170  $this->close();
171  $fileName = self::generateFileName( $this->dbDir, $dbName );
172  if ( !is_readable( $fileName ) ) {
173  $this->conn = false;
174  throw new DBConnectionError( $this, "SQLite database not accessible" );
175  }
176  $this->openFile( $fileName, $dbName );
177 
178  return (bool)$this->conn;
179  }
180 
189  protected function openFile( $fileName, $dbName ) {
190  $err = false;
191 
192  $this->dbPath = $fileName;
193  try {
194  if ( $this->flags & self::DBO_PERSISTENT ) {
195  $this->conn = new PDO( "sqlite:$fileName", '', '',
196  [ PDO::ATTR_PERSISTENT => true ] );
197  } else {
198  $this->conn = new PDO( "sqlite:$fileName", '', '' );
199  }
200  } catch ( PDOException $e ) {
201  $err = $e->getMessage();
202  }
203 
204  if ( !$this->conn ) {
205  $this->queryLogger->debug( "DB connection error: $err\n" );
206  throw new DBConnectionError( $this, $err );
207  }
208 
209  $this->opened = is_object( $this->conn );
210  if ( $this->opened ) {
211  $this->dbName = $dbName;
212  # Set error codes only, don't raise exceptions
213  $this->conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
214  # Enforce LIKE to be case sensitive, just like MySQL
215  $this->query( 'PRAGMA case_sensitive_like = 1' );
216 
217  return $this->conn;
218  }
219 
220  return false;
221  }
222 
223  public function selectDB( $db ) {
224  return false; // doesn't make sense
225  }
226 
231  public function getDbFilePath() {
232  return $this->dbPath;
233  }
234 
239  protected function closeConnection() {
240  $this->conn = null;
241 
242  return true;
243  }
244 
251  public static function generateFileName( $dir, $dbName ) {
252  return "$dir/$dbName.sqlite";
253  }
254 
260  if ( self::$fulltextEnabled === null ) {
261  self::$fulltextEnabled = false;
262  $table = $this->tableName( 'searchindex' );
263  $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name = '$table'", __METHOD__ );
264  if ( $res ) {
265  $row = $res->fetchRow();
266  self::$fulltextEnabled = stristr( $row['sql'], 'fts' ) !== false;
267  }
268  }
269 
270  return self::$fulltextEnabled;
271  }
272 
277  static function getFulltextSearchModule() {
278  static $cachedResult = null;
279  if ( $cachedResult !== null ) {
280  return $cachedResult;
281  }
282  $cachedResult = false;
283  $table = 'dummy_search_test';
284 
285  $db = self::newStandaloneInstance( ':memory:' );
286  if ( $db->query( "CREATE VIRTUAL TABLE $table USING FTS3(dummy_field)", __METHOD__, true ) ) {
287  $cachedResult = 'FTS3';
288  }
289  $db->close();
290 
291  return $cachedResult;
292  }
293 
305  function attachDatabase( $name, $file = false, $fname = __METHOD__ ) {
306  if ( !$file ) {
307  $file = self::generateFileName( $this->dbDir, $name );
308  }
309  $file = $this->addQuotes( $file );
310 
311  return $this->query( "ATTACH DATABASE $file AS $name", $fname );
312  }
313 
314  function isWriteQuery( $sql ) {
315  return parent::isWriteQuery( $sql ) && !preg_match( '/^(ATTACH|PRAGMA)\b/i', $sql );
316  }
317 
318  protected function isTransactableQuery( $sql ) {
319  return parent::isTransactableQuery( $sql ) && !in_array(
320  $this->getQueryVerb( $sql ),
321  [ 'ATTACH', 'PRAGMA' ],
322  true
323  );
324  }
325 
332  protected function doQuery( $sql ) {
333  $res = $this->getBindingHandle()->query( $sql );
334  if ( $res === false ) {
335  return false;
336  }
337 
338  $r = $res instanceof ResultWrapper ? $res->result : $res;
339  $this->lastAffectedRowCount = $r->rowCount();
340  $res = new ResultWrapper( $this, $r->fetchAll() );
341 
342  return $res;
343  }
344 
348  function freeResult( $res ) {
349  if ( $res instanceof ResultWrapper ) {
350  $res->result = null;
351  } else {
352  $res = null;
353  }
354  }
355 
360  function fetchObject( $res ) {
361  if ( $res instanceof ResultWrapper ) {
362  $r =& $res->result;
363  } else {
364  $r =& $res;
365  }
366 
367  $cur = current( $r );
368  if ( is_array( $cur ) ) {
369  next( $r );
370  $obj = new stdClass;
371  foreach ( $cur as $k => $v ) {
372  if ( !is_numeric( $k ) ) {
373  $obj->$k = $v;
374  }
375  }
376 
377  return $obj;
378  }
379 
380  return false;
381  }
382 
387  function fetchRow( $res ) {
388  if ( $res instanceof ResultWrapper ) {
389  $r =& $res->result;
390  } else {
391  $r =& $res;
392  }
393  $cur = current( $r );
394  if ( is_array( $cur ) ) {
395  next( $r );
396 
397  return $cur;
398  }
399 
400  return false;
401  }
402 
409  function numRows( $res ) {
410  $r = $res instanceof ResultWrapper ? $res->result : $res;
411 
412  return count( $r );
413  }
414 
419  function numFields( $res ) {
420  $r = $res instanceof ResultWrapper ? $res->result : $res;
421  if ( is_array( $r ) && count( $r ) > 0 ) {
422  // The size of the result array is twice the number of fields. (Bug: 65578)
423  return count( $r[0] ) / 2;
424  } else {
425  // If the result is empty return 0
426  return 0;
427  }
428  }
429 
435  function fieldName( $res, $n ) {
436  $r = $res instanceof ResultWrapper ? $res->result : $res;
437  if ( is_array( $r ) ) {
438  $keys = array_keys( $r[0] );
439 
440  return $keys[$n];
441  }
442 
443  return false;
444  }
445 
453  function tableName( $name, $format = 'quoted' ) {
454  // table names starting with sqlite_ are reserved
455  if ( strpos( $name, 'sqlite_' ) === 0 ) {
456  return $name;
457  }
458 
459  return str_replace( '"', '', parent::tableName( $name, $format ) );
460  }
461 
467  function insertId() {
468  // PDO::lastInsertId yields a string :(
469  return intval( $this->getBindingHandle()->lastInsertId() );
470  }
471 
476  function dataSeek( $res, $row ) {
477  if ( $res instanceof ResultWrapper ) {
478  $r =& $res->result;
479  } else {
480  $r =& $res;
481  }
482  reset( $r );
483  if ( $row > 0 ) {
484  for ( $i = 0; $i < $row; $i++ ) {
485  next( $r );
486  }
487  }
488  }
489 
493  function lastError() {
494  if ( !is_object( $this->conn ) ) {
495  return "Cannot return last error, no db connection";
496  }
497  $e = $this->conn->errorInfo();
498 
499  return isset( $e[2] ) ? $e[2] : '';
500  }
501 
505  function lastErrno() {
506  if ( !is_object( $this->conn ) ) {
507  return "Cannot return last error, no db connection";
508  } else {
509  $info = $this->conn->errorInfo();
510 
511  return $info[1];
512  }
513  }
514 
518  protected function fetchAffectedRowCount() {
520  }
521 
532  function indexInfo( $table, $index, $fname = __METHOD__ ) {
533  $sql = 'PRAGMA index_info(' . $this->addQuotes( $this->indexName( $index ) ) . ')';
534  $res = $this->query( $sql, $fname );
535  if ( !$res || $res->numRows() == 0 ) {
536  return false;
537  }
538  $info = [];
539  foreach ( $res as $row ) {
540  $info[] = $row->name;
541  }
542 
543  return $info;
544  }
545 
552  function indexUnique( $table, $index, $fname = __METHOD__ ) {
553  $row = $this->selectRow( 'sqlite_master', '*',
554  [
555  'type' => 'index',
556  'name' => $this->indexName( $index ),
557  ], $fname );
558  if ( !$row || !isset( $row->sql ) ) {
559  return null;
560  }
561 
562  // $row->sql will be of the form CREATE [UNIQUE] INDEX ...
563  $indexPos = strpos( $row->sql, 'INDEX' );
564  if ( $indexPos === false ) {
565  return null;
566  }
567  $firstPart = substr( $row->sql, 0, $indexPos );
568  $options = explode( ' ', $firstPart );
569 
570  return in_array( 'UNIQUE', $options );
571  }
572 
580  foreach ( $options as $k => $v ) {
581  if ( is_numeric( $k ) && ( $v == 'FOR UPDATE' || $v == 'LOCK IN SHARE MODE' ) ) {
582  $options[$k] = '';
583  }
584  }
585 
586  return parent::makeSelectOptions( $options );
587  }
588 
593  protected function makeUpdateOptionsArray( $options ) {
594  $options = parent::makeUpdateOptionsArray( $options );
596 
597  return $options;
598  }
599 
604  static function fixIgnore( $options ) {
605  # SQLite uses OR IGNORE not just IGNORE
606  foreach ( $options as $k => $v ) {
607  if ( $v == 'IGNORE' ) {
608  $options[$k] = 'OR IGNORE';
609  }
610  }
611 
612  return $options;
613  }
614 
621 
622  return parent::makeInsertOptions( $options );
623  }
624 
633  function insert( $table, $a, $fname = __METHOD__, $options = [] ) {
634  if ( !count( $a ) ) {
635  return true;
636  }
637 
638  # SQLite can't handle multi-row inserts, so divide up into multiple single-row inserts
639  if ( isset( $a[0] ) && is_array( $a[0] ) ) {
640  $ret = true;
641  foreach ( $a as $v ) {
642  if ( !parent::insert( $table, $v, "$fname/multi-row", $options ) ) {
643  $ret = false;
644  }
645  }
646  } else {
647  $ret = parent::insert( $table, $a, "$fname/single-row", $options );
648  }
649 
650  return $ret;
651  }
652 
660  function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
661  if ( !count( $rows ) ) {
662  return true;
663  }
664 
665  # SQLite can't handle multi-row replaces, so divide up into multiple single-row queries
666  if ( isset( $rows[0] ) && is_array( $rows[0] ) ) {
667  $ret = true;
668  foreach ( $rows as $v ) {
669  if ( !$this->nativeReplace( $table, $v, "$fname/multi-row" ) ) {
670  $ret = false;
671  }
672  }
673  } else {
674  $ret = $this->nativeReplace( $table, $rows, "$fname/single-row" );
675  }
676 
677  return $ret;
678  }
679 
688  function textFieldSize( $table, $field ) {
689  return -1;
690  }
691 
696  return false;
697  }
698 
704  function unionQueries( $sqls, $all ) {
705  $glue = $all ? ' UNION ALL ' : ' UNION ';
706 
707  return implode( $glue, $sqls );
708  }
709 
713  function wasDeadlock() {
714  return $this->lastErrno() == 5; // SQLITE_BUSY
715  }
716 
720  function wasReadOnlyError() {
721  return $this->lastErrno() == 8; // SQLITE_READONLY;
722  }
723 
724  public function wasConnectionError( $errno ) {
725  return $errno == 17; // SQLITE_SCHEMA;
726  }
727 
728  protected function wasKnownStatementRollbackError() {
729  // ON CONFLICT ROLLBACK clauses make it so that SQLITE_CONSTRAINT error is
730  // ambiguous with regard to whether it implies a ROLLBACK or an ABORT happened.
731  // https://sqlite.org/lang_createtable.html#uniqueconst
732  // https://sqlite.org/lang_conflict.html
733  return false;
734  }
735 
739  public function getSoftwareLink() {
740  return "[{{int:version-db-sqlite-url}} SQLite]";
741  }
742 
746  function getServerVersion() {
747  $ver = $this->getBindingHandle()->getAttribute( PDO::ATTR_SERVER_VERSION );
748 
749  return $ver;
750  }
751 
760  function fieldInfo( $table, $field ) {
761  $tableName = $this->tableName( $table );
762  $sql = 'PRAGMA table_info(' . $this->addQuotes( $tableName ) . ')';
763  $res = $this->query( $sql, __METHOD__ );
764  foreach ( $res as $row ) {
765  if ( $row->name == $field ) {
766  return new SQLiteField( $row, $tableName );
767  }
768  }
769 
770  return false;
771  }
772 
773  protected function doBegin( $fname = '' ) {
774  if ( $this->trxMode ) {
775  $this->query( "BEGIN {$this->trxMode}", $fname );
776  } else {
777  $this->query( 'BEGIN', $fname );
778  }
779  $this->trxLevel = 1;
780  }
781 
786  function strencode( $s ) {
787  return substr( $this->addQuotes( $s ), 1, -1 );
788  }
789 
794  function encodeBlob( $b ) {
795  return new Blob( $b );
796  }
797 
802  function decodeBlob( $b ) {
803  if ( $b instanceof Blob ) {
804  $b = $b->fetch();
805  }
806 
807  return $b;
808  }
809 
814  function addQuotes( $s ) {
815  if ( $s instanceof Blob ) {
816  return "x'" . bin2hex( $s->fetch() ) . "'";
817  } elseif ( is_bool( $s ) ) {
818  return (int)$s;
819  } elseif ( strpos( (string)$s, "\0" ) !== false ) {
820  // SQLite doesn't support \0 in strings, so use the hex representation as a workaround.
821  // This is a known limitation of SQLite's mprintf function which PDO
822  // should work around, but doesn't. I have reported this to php.net as bug #63419:
823  // https://bugs.php.net/bug.php?id=63419
824  // There was already a similar report for SQLite3::escapeString, bug #62361:
825  // https://bugs.php.net/bug.php?id=62361
826  // There is an additional bug regarding sorting this data after insert
827  // on older versions of sqlite shipped with ubuntu 12.04
828  // https://phabricator.wikimedia.org/T74367
829  $this->queryLogger->debug(
830  __FUNCTION__ .
831  ': Quoting value containing null byte. ' .
832  'For consistency all binary data should have been ' .
833  'first processed with self::encodeBlob()'
834  );
835  return "x'" . bin2hex( (string)$s ) . "'";
836  } else {
837  return $this->getBindingHandle()->quote( (string)$s );
838  }
839  }
840 
841  public function buildSubstring( $input, $startPosition, $length = null ) {
842  $this->assertBuildSubstringParams( $startPosition, $length );
843  $params = [ $input, $startPosition ];
844  if ( $length !== null ) {
845  $params[] = $length;
846  }
847  return 'SUBSTR(' . implode( ',', $params ) . ')';
848  }
849 
855  public function buildStringCast( $field ) {
856  return 'CAST ( ' . $field . ' AS TEXT )';
857  }
858 
864  public function deadlockLoop( /*...*/ ) {
865  $args = func_get_args();
866  $function = array_shift( $args );
867 
868  return call_user_func_array( $function, $args );
869  }
870 
875  protected function replaceVars( $s ) {
876  $s = parent::replaceVars( $s );
877  if ( preg_match( '/^\s*(CREATE|ALTER) TABLE/i', $s ) ) {
878  // CREATE TABLE hacks to allow schema file sharing with MySQL
879 
880  // binary/varbinary column type -> blob
881  $s = preg_replace( '/\b(var)?binary(\(\d+\))/i', 'BLOB', $s );
882  // no such thing as unsigned
883  $s = preg_replace( '/\b(un)?signed\b/i', '', $s );
884  // INT -> INTEGER
885  $s = preg_replace( '/\b(tiny|small|medium|big|)int(\s*\(\s*\d+\s*\)|\b)/i', 'INTEGER', $s );
886  // floating point types -> REAL
887  $s = preg_replace(
888  '/\b(float|double(\s+precision)?)(\s*\(\s*\d+\s*(,\s*\d+\s*)?\)|\b)/i',
889  'REAL',
890  $s
891  );
892  // varchar -> TEXT
893  $s = preg_replace( '/\b(var)?char\s*\(.*?\)/i', 'TEXT', $s );
894  // TEXT normalization
895  $s = preg_replace( '/\b(tiny|medium|long)text\b/i', 'TEXT', $s );
896  // BLOB normalization
897  $s = preg_replace( '/\b(tiny|small|medium|long|)blob\b/i', 'BLOB', $s );
898  // BOOL -> INTEGER
899  $s = preg_replace( '/\bbool(ean)?\b/i', 'INTEGER', $s );
900  // DATETIME -> TEXT
901  $s = preg_replace( '/\b(datetime|timestamp)\b/i', 'TEXT', $s );
902  // No ENUM type
903  $s = preg_replace( '/\benum\s*\([^)]*\)/i', 'TEXT', $s );
904  // binary collation type -> nothing
905  $s = preg_replace( '/\bbinary\b/i', '', $s );
906  // auto_increment -> autoincrement
907  $s = preg_replace( '/\bauto_increment\b/i', 'AUTOINCREMENT', $s );
908  // No explicit options
909  $s = preg_replace( '/\)[^);]*(;?)\s*$/', ')\1', $s );
910  // AUTOINCREMENT should immedidately follow PRIMARY KEY
911  $s = preg_replace( '/primary key (.*?) autoincrement/i', 'PRIMARY KEY AUTOINCREMENT $1', $s );
912  } elseif ( preg_match( '/^\s*CREATE (\s*(?:UNIQUE|FULLTEXT)\s+)?INDEX/i', $s ) ) {
913  // No truncated indexes
914  $s = preg_replace( '/\(\d+\)/', '', $s );
915  // No FULLTEXT
916  $s = preg_replace( '/\bfulltext\b/i', '', $s );
917  } elseif ( preg_match( '/^\s*DROP INDEX/i', $s ) ) {
918  // DROP INDEX is database-wide, not table-specific, so no ON <table> clause.
919  $s = preg_replace( '/\sON\s+[^\s]*/i', '', $s );
920  } elseif ( preg_match( '/^\s*INSERT IGNORE\b/i', $s ) ) {
921  // INSERT IGNORE --> INSERT OR IGNORE
922  $s = preg_replace( '/^\s*INSERT IGNORE\b/i', 'INSERT OR IGNORE', $s );
923  }
924 
925  return $s;
926  }
927 
928  public function lock( $lockName, $method, $timeout = 5 ) {
929  if ( !is_dir( "{$this->dbDir}/locks" ) ) { // create dir as needed
930  if ( !is_writable( $this->dbDir ) || !mkdir( "{$this->dbDir}/locks" ) ) {
931  throw new DBError( $this, "Cannot create directory \"{$this->dbDir}/locks\"." );
932  }
933  }
934 
935  return $this->lockMgr->lock( [ $lockName ], LockManager::LOCK_EX, $timeout )->isOK();
936  }
937 
938  public function unlock( $lockName, $method ) {
939  return $this->lockMgr->unlock( [ $lockName ], LockManager::LOCK_EX )->isOK();
940  }
941 
948  function buildConcat( $stringList ) {
949  return '(' . implode( ') || (', $stringList ) . ')';
950  }
951 
952  public function buildGroupConcatField(
953  $delim, $table, $field, $conds = '', $join_conds = []
954  ) {
955  $fld = "group_concat($field," . $this->addQuotes( $delim ) . ')';
956 
957  return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')';
958  }
959 
968  function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__ ) {
969  $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" .
970  $this->addQuotes( $oldName ) . " AND type='table'", $fname );
971  $obj = $this->fetchObject( $res );
972  if ( !$obj ) {
973  throw new RuntimeException( "Couldn't retrieve structure for table $oldName" );
974  }
975  $sql = $obj->sql;
976  $sql = preg_replace(
977  '/(?<=\W)"?' . preg_quote( trim( $this->addIdentifierQuotes( $oldName ), '"' ) ) . '"?(?=\W)/',
978  $this->addIdentifierQuotes( $newName ),
979  $sql,
980  1
981  );
982  if ( $temporary ) {
983  if ( preg_match( '/^\\s*CREATE\\s+VIRTUAL\\s+TABLE\b/i', $sql ) ) {
984  $this->queryLogger->debug(
985  "Table $oldName is virtual, can't create a temporary duplicate.\n" );
986  } else {
987  $sql = str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $sql );
988  }
989  }
990 
991  $res = $this->query( $sql, $fname );
992 
993  // Take over indexes
994  $indexList = $this->query( 'PRAGMA INDEX_LIST(' . $this->addQuotes( $oldName ) . ')' );
995  foreach ( $indexList as $index ) {
996  if ( strpos( $index->name, 'sqlite_autoindex' ) === 0 ) {
997  continue;
998  }
999 
1000  if ( $index->unique ) {
1001  $sql = 'CREATE UNIQUE INDEX';
1002  } else {
1003  $sql = 'CREATE INDEX';
1004  }
1005  // Try to come up with a new index name, given indexes have database scope in SQLite
1006  $indexName = $newName . '_' . $index->name;
1007  $sql .= ' ' . $indexName . ' ON ' . $newName;
1008 
1009  $indexInfo = $this->query( 'PRAGMA INDEX_INFO(' . $this->addQuotes( $index->name ) . ')' );
1010  $fields = [];
1011  foreach ( $indexInfo as $indexInfoRow ) {
1012  $fields[$indexInfoRow->seqno] = $indexInfoRow->name;
1013  }
1014 
1015  $sql .= '(' . implode( ',', $fields ) . ')';
1016 
1017  $this->query( $sql );
1018  }
1019 
1020  return $res;
1021  }
1022 
1031  function listTables( $prefix = null, $fname = __METHOD__ ) {
1032  $result = $this->select(
1033  'sqlite_master',
1034  'name',
1035  "type='table'"
1036  );
1037 
1038  $endArray = [];
1039 
1040  foreach ( $result as $table ) {
1041  $vars = get_object_vars( $table );
1042  $table = array_pop( $vars );
1043 
1044  if ( !$prefix || strpos( $table, $prefix ) === 0 ) {
1045  if ( strpos( $table, 'sqlite_' ) !== 0 ) {
1046  $endArray[] = $table;
1047  }
1048  }
1049  }
1050 
1051  return $endArray;
1052  }
1053 
1062  public function dropTable( $tableName, $fName = __METHOD__ ) {
1063  if ( !$this->tableExists( $tableName, $fName ) ) {
1064  return false;
1065  }
1066  $sql = "DROP TABLE " . $this->tableName( $tableName );
1067 
1068  return $this->query( $sql, $fName );
1069  }
1070 
1071  public function setTableAliases( array $aliases ) {
1072  parent::setTableAliases( $aliases );
1073  foreach ( $this->tableAliases as $params ) {
1074  if ( isset( $this->alreadyAttached[$params['dbname']] ) ) {
1075  continue;
1076  }
1077  $this->attachDatabase( $params['dbname'] );
1078  $this->alreadyAttached[$params['dbname']] = true;
1079  }
1080  }
1081 
1082  public function resetSequenceForTable( $table, $fname = __METHOD__ ) {
1083  $encTable = $this->addIdentifierQuotes( 'sqlite_sequence' );
1084  $encName = $this->addQuotes( $this->tableName( $table, 'raw' ) );
1085  $this->query( "DELETE FROM $encTable WHERE name = $encName", $fname );
1086  }
1087 
1088  public function databasesAreIndependent() {
1089  return true;
1090  }
1091 
1095  public function __toString() {
1096  return is_object( $this->conn )
1097  ? 'SQLite ' . (string)$this->conn->getAttribute( PDO::ATTR_SERVER_VERSION )
1098  : '(not connected)';
1099  }
1100 
1104  protected function getBindingHandle() {
1105  return parent::getBindingHandle();
1106  }
1107 }
1108 
1109 class_alias( DatabaseSqlite::class, 'DatabaseSqlite' );
DBO_PERSISTENT
const DBO_PERSISTENT
Definition: defines.php:14
Wikimedia\Rdbms\DatabaseSqlite\$fulltextEnabled
static bool $fulltextEnabled
Whether full text is enabled.
Definition: DatabaseSqlite.php:39
Wikimedia\Rdbms\SQLiteField
Definition: SQLiteField.php:5
Wikimedia\Rdbms\DatabaseSqlite\$trxMode
string $trxMode
Transaction mode.
Definition: DatabaseSqlite.php:46
Wikimedia\Rdbms\DatabaseSqlite\fieldInfo
fieldInfo( $table, $field)
Get information about a given field Returns false if the field does not exist.
Definition: DatabaseSqlite.php:760
Wikimedia\Rdbms\DatabaseSqlite\$lockMgr
FSLockManager $lockMgr
(hopefully on the same server as the DB)
Definition: DatabaseSqlite.php:57
insert
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and insert
Definition: hooks.txt:2066
Wikimedia\Rdbms\DatabaseSqlite\selectDB
selectDB( $db)
Change the current database.
Definition: DatabaseSqlite.php:223
LockManager
Class for handling resource locking.
Definition: LockManager.php:46
Wikimedia\Rdbms\DatabaseSqlite\getBindingHandle
getBindingHandle()
Definition: DatabaseSqlite.php:1104
Wikimedia\Rdbms\DatabaseSqlite\addQuotes
addQuotes( $s)
Definition: DatabaseSqlite.php:814
Wikimedia\Rdbms\DatabaseSqlite\fetchRow
fetchRow( $res)
Definition: DatabaseSqlite.php:387
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:48
Wikimedia\Rdbms\DatabaseSqlite
Definition: DatabaseSqlite.php:37
Wikimedia\Rdbms\DatabaseSqlite\$dbDir
string $dbDir
Directory.
Definition: DatabaseSqlite.php:42
Wikimedia\Rdbms\DatabaseSqlite\wasKnownStatementRollbackError
wasKnownStatementRollbackError()
Definition: DatabaseSqlite.php:728
Wikimedia\Rdbms\Database\factory
static factory( $dbType, $p=[], $connect=self::NEW_CONNECTED)
Construct a Database subclass instance given a database type and parameters.
Definition: Database.php:422
Wikimedia\Rdbms\DatabaseSqlite\listTables
listTables( $prefix=null, $fname=__METHOD__)
List all tables on the database.
Definition: DatabaseSqlite.php:1031
FSLockManager
Simple version of LockManager based on using FS lock files.
Definition: FSLockManager.php:36
Wikimedia\Rdbms\DatabaseSqlite\unlock
unlock( $lockName, $method)
Release a lock.
Definition: DatabaseSqlite.php:938
captcha-old.count
count
Definition: captcha-old.py:249
Wikimedia\Rdbms\Database\nativeReplace
nativeReplace( $table, $rows, $fname)
REPLACE query wrapper for MySQL and SQLite, which have a native REPLACE statement.
Definition: Database.php:2720
Wikimedia\Rdbms\DatabaseSqlite\unionSupportsOrderAndLimit
unionSupportsOrderAndLimit()
Definition: DatabaseSqlite.php:695
Wikimedia\Rdbms\DatabaseSqlite\implicitGroupby
implicitGroupby()
Definition: DatabaseSqlite.php:154
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1985
Wikimedia\Rdbms\DatabaseSqlite\databasesAreIndependent
databasesAreIndependent()
Returns true if DBs are assumed to be on potentially different servers.
Definition: DatabaseSqlite.php:1088
Wikimedia\Rdbms\DatabaseSqlite\$dbPath
string $dbPath
File name for SQLite database file.
Definition: DatabaseSqlite.php:44
Wikimedia\Rdbms\Database\indexName
indexName( $index)
Allows for index remapping in queries where this is not consistent across DBMS.
Definition: Database.php:2531
Wikimedia\Rdbms\DatabaseSqlite\fetchAffectedRowCount
fetchAffectedRowCount()
Definition: DatabaseSqlite.php:518
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Wikimedia\Rdbms\DatabaseSqlite\replace
replace( $table, $uniqueIndexes, $rows, $fname=__METHOD__)
Definition: DatabaseSqlite.php:660
Wikimedia\Rdbms\DatabaseSqlite\encodeBlob
encodeBlob( $b)
Definition: DatabaseSqlite.php:794
Wikimedia\Rdbms\DatabaseSqlite\setTableAliases
setTableAliases(array $aliases)
Make certain table names use their own database, schema, and table prefix when passed into SQL querie...
Definition: DatabaseSqlite.php:1071
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
$params
$params
Definition: styleTest.css.php:40
Wikimedia\Rdbms\DatabaseSqlite\lastError
lastError()
Definition: DatabaseSqlite.php:493
Wikimedia\Rdbms\DatabaseSqlite\getServerVersion
getServerVersion()
Definition: DatabaseSqlite.php:746
$s
$s
Definition: mergeMessageFileList.php:187
Wikimedia\Rdbms\DatabaseSqlite\dataSeek
dataSeek( $res, $row)
Definition: DatabaseSqlite.php:476
Wikimedia\Rdbms\DatabaseSqlite\strencode
strencode( $s)
Definition: DatabaseSqlite.php:786
Wikimedia\Rdbms\DatabaseSqlite\$lastResultHandle
resource $lastResultHandle
Definition: DatabaseSqlite.php:51
Wikimedia\Rdbms\DatabaseSqlite\buildSubstring
buildSubstring( $input, $startPosition, $length=null)
Definition: DatabaseSqlite.php:841
$res
$res
Definition: database.txt:21
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
Wikimedia\Rdbms\ResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: ResultWrapper.php:24
Wikimedia\Rdbms\DatabaseSqlite\openFile
openFile( $fileName, $dbName)
Opens a database file.
Definition: DatabaseSqlite.php:189
Wikimedia\Rdbms\DatabaseSqlite\closeConnection
closeConnection()
Does not actually close the connection, just destroys the reference for GC to do its work.
Definition: DatabaseSqlite.php:239
Wikimedia\Rdbms\DBError
Database error base class.
Definition: DBError.php:30
Wikimedia\Rdbms\DatabaseSqlite\buildStringCast
buildStringCast( $field)
Definition: DatabaseSqlite.php:855
Wikimedia\Rdbms\DatabaseSqlite\makeInsertOptions
makeInsertOptions( $options)
Definition: DatabaseSqlite.php:619
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Wikimedia\Rdbms\DatabaseSqlite\unionQueries
unionQueries( $sqls, $all)
Definition: DatabaseSqlite.php:704
Wikimedia\Rdbms\DatabaseSqlite\$lastAffectedRowCount
int $lastAffectedRowCount
The number of rows affected as an integer.
Definition: DatabaseSqlite.php:49
Wikimedia\Rdbms\Database\assertBuildSubstringParams
assertBuildSubstringParams( $startPosition, $length)
Check type and bounds for parameters to self::buildSubstring()
Definition: Database.php:2161
Wikimedia\Rdbms\DatabaseSqlite\wasDeadlock
wasDeadlock()
Definition: DatabaseSqlite.php:713
tableName
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for tableName() and addQuotes(). You will need both of them. ------------------------------------------------------------------------ Basic query optimisation ------------------------------------------------------------------------ MediaWiki developers who need to write DB queries should have some understanding of databases and the performance issues associated with them. Patches containing unacceptably slow features will not be accepted. Unindexed queries are generally not welcome in MediaWiki
Wikimedia\Rdbms\Database\trxLevel
trxLevel()
Gets the current transaction level.
Definition: Database.php:577
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:141
Wikimedia\Rdbms\DatabaseSqlite\generateFileName
static generateFileName( $dir, $dbName)
Generates a database file name.
Definition: DatabaseSqlite.php:251
Wikimedia\Rdbms\DatabaseSqlite\doBegin
doBegin( $fname='')
Issues the BEGIN command to the database server.
Definition: DatabaseSqlite.php:773
Wikimedia\Rdbms\DatabaseSqlite\$conn
PDO $conn
Definition: DatabaseSqlite.php:54
Wikimedia\Rdbms\DatabaseSqlite\resetSequenceForTable
resetSequenceForTable( $table, $fname=__METHOD__)
Definition: DatabaseSqlite.php:1082
Wikimedia\Rdbms\DatabaseSqlite\fixIgnore
static fixIgnore( $options)
Definition: DatabaseSqlite.php:604
Wikimedia\Rdbms\Database\selectSQLText
selectSQLText( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
The equivalent of IDatabase::select() except that the constructed SQL is returned,...
Definition: Database.php:1656
Wikimedia\Rdbms\Database\$user
string $user
User that this instance is currently connected under the name of.
Definition: Database.php:81
Wikimedia\Rdbms\DatabaseSqlite\getDbFilePath
getDbFilePath()
Definition: DatabaseSqlite.php:231
Wikimedia\Rdbms\DatabaseSqlite\numRows
numRows( $res)
The PDO::Statement class implements the array interface so count() will work.
Definition: DatabaseSqlite.php:409
$vars
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:2220
Wikimedia\Rdbms\DatabaseSqlite\replaceVars
replaceVars( $s)
Definition: DatabaseSqlite.php:875
Wikimedia\Rdbms\DatabaseSqlite\deadlockLoop
deadlockLoop()
No-op version of deadlockLoop.
Definition: DatabaseSqlite.php:864
Wikimedia\Rdbms\DatabaseSqlite\fieldName
fieldName( $res, $n)
Definition: DatabaseSqlite.php:435
string
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:175
Wikimedia\Rdbms\Database\selectRow
selectRow( $table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[])
Single row SELECT wrapper.
Definition: Database.php:1725
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:112
Wikimedia\Rdbms\DatabaseSqlite\lock
lock( $lockName, $method, $timeout=5)
Acquire a named lock.
Definition: DatabaseSqlite.php:928
Wikimedia\Rdbms\Database\tableExists
tableExists( $table, $fname=__METHOD__)
Query whether a given table exists.
Definition: Database.php:1884
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2163
Wikimedia\Rdbms\DatabaseSqlite\fetchObject
fetchObject( $res)
Definition: DatabaseSqlite.php:360
Wikimedia\Rdbms\DatabaseSqlite\__toString
__toString()
Definition: DatabaseSqlite.php:1095
Wikimedia\Rdbms\DatabaseSqlite\doQuery
doQuery( $sql)
SQLite doesn't allow buffered results or data seeking etc, so we'll use fetchAll as the result.
Definition: DatabaseSqlite.php:332
Wikimedia\Rdbms\DatabaseSqlite\getAttributes
static getAttributes()
Definition: DatabaseSqlite.php:97
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1987
Wikimedia\Rdbms\DatabaseSqlite\getType
getType()
Definition: DatabaseSqlite.php:145
Wikimedia\Rdbms\DatabaseSqlite\$alreadyAttached
array $alreadyAttached
List of shared database already attached to this connection.
Definition: DatabaseSqlite.php:60
Wikimedia\Rdbms\Database\query
query( $sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
Definition: Database.php:1094
Wikimedia\Rdbms\DatabaseSqlite\buildGroupConcatField
buildGroupConcatField( $delim, $table, $field, $conds='', $join_conds=[])
Build a GROUP_CONCAT or equivalent statement for a query.
Definition: DatabaseSqlite.php:952
Wikimedia\Rdbms\DatabaseSqlite\attachDatabase
attachDatabase( $name, $file=false, $fname=__METHOD__)
Attaches external database to our connection, see https://sqlite.org/lang_attach.html for details.
Definition: DatabaseSqlite.php:305
Wikimedia\Rdbms\DatabaseSqlite\isTransactableQuery
isTransactableQuery( $sql)
Determine whether a SQL statement is sensitive to isolation level.
Definition: DatabaseSqlite.php:318
Wikimedia\Rdbms\DatabaseSqlite\insert
insert( $table, $a, $fname=__METHOD__, $options=[])
Based on generic method (parent) with some prior SQLite-sepcific adjustments.
Definition: DatabaseSqlite.php:633
Wikimedia\Rdbms\DatabaseSqlite\newStandaloneInstance
static newStandaloneInstance( $filename, array $p=[])
Definition: DatabaseSqlite.php:110
Wikimedia\Rdbms\Database\addIdentifierQuotes
addIdentifierQuotes( $s)
Quotes an identifier using backticks or "double quotes" depending on the database type.
Definition: Database.php:2563
$args
if( $line===false) $args
Definition: cdb.php:64
Wikimedia\Rdbms\DatabaseSqlite\open
open( $server, $user, $pass, $dbName)
Open an SQLite database and return a resource handle to it NOTE: only $dbName is used,...
Definition: DatabaseSqlite.php:169
Wikimedia\Rdbms\Database\close
close()
Close the database connection.
Definition: Database.php:900
Wikimedia\Rdbms\DatabaseSqlite\getFulltextSearchModule
static getFulltextSearchModule()
Returns version of currently supported SQLite fulltext search module or false if none present.
Definition: DatabaseSqlite.php:277
Wikimedia\Rdbms\Database\getQueryVerb
getQueryVerb( $sql)
Definition: Database.php:1034
flags
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database etc For and for historical it also represents a few features of articles that don t involve their such as access rights See also title txt Article Encapsulates access to the page table of the database The object represents a an and maintains state such as flags
Definition: design.txt:34
Wikimedia\Rdbms\DatabaseSqlite\makeUpdateOptionsArray
makeUpdateOptionsArray( $options)
Definition: DatabaseSqlite.php:593
Wikimedia\Rdbms\DatabaseSqlite\getSoftwareLink
getSoftwareLink()
Definition: DatabaseSqlite.php:739
Wikimedia\Rdbms\DatabaseSqlite\doInitConnection
doInitConnection()
Actually connect to the database over the wire (or to local files)
Definition: DatabaseSqlite.php:120
$rows
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition: hooks.txt:2604
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1987
Wikimedia\Rdbms\DatabaseSqlite\insertId
insertId()
This must be called after nextSequenceVal.
Definition: DatabaseSqlite.php:467
Wikimedia\Rdbms\DatabaseSqlite\makeSelectOptions
makeSelectOptions( $options)
Filter the options used in SELECT statements.
Definition: DatabaseSqlite.php:579
Wikimedia\Rdbms\DatabaseSqlite\freeResult
freeResult( $res)
Definition: DatabaseSqlite.php:348
Wikimedia\Rdbms\DatabaseSqlite\lastErrno
lastErrno()
Definition: DatabaseSqlite.php:505
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Wikimedia\Rdbms\DatabaseSqlite\indexUnique
indexUnique( $table, $index, $fname=__METHOD__)
Definition: DatabaseSqlite.php:552
Wikimedia\Rdbms\DBConnectionError
Definition: DBConnectionError.php:26
Wikimedia\Rdbms\DatabaseSqlite\wasReadOnlyError
wasReadOnlyError()
Definition: DatabaseSqlite.php:720
Wikimedia\Rdbms\Database\$server
string $server
Server that this instance is currently connected to.
Definition: Database.php:79
$keys
$keys
Definition: testCompression.php:67
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1987
Wikimedia\Rdbms\DatabaseSqlite\buildConcat
buildConcat( $stringList)
Build a concatenation list to feed into a SQL query.
Definition: DatabaseSqlite.php:948
Wikimedia\Rdbms\Database\select
select( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
Definition: Database.php:1649
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Wikimedia\Rdbms\DatabaseSqlite\isWriteQuery
isWriteQuery( $sql)
Determine whether a query writes to the DB.
Definition: DatabaseSqlite.php:314
Wikimedia\Rdbms\DatabaseSqlite\wasConnectionError
wasConnectionError( $errno)
Do not use this method outside of Database/DBError classes.
Definition: DatabaseSqlite.php:724
LockManager\LOCK_EX
const LOCK_EX
Definition: LockManager.php:69
Wikimedia\Rdbms\DatabaseSqlite\__construct
__construct(array $p)
Additional params include:
Definition: DatabaseSqlite.php:70
Wikimedia\Rdbms\DatabaseSqlite\decodeBlob
decodeBlob( $b)
Definition: DatabaseSqlite.php:802
Wikimedia\Rdbms\DatabaseSqlite\dropTable
dropTable( $tableName, $fName=__METHOD__)
Override due to no CASCADE support.
Definition: DatabaseSqlite.php:1062
Wikimedia\Rdbms\DatabaseSqlite\checkForEnabledSearch
checkForEnabledSearch()
Check if the searchindext table is FTS enabled.
Definition: DatabaseSqlite.php:259
Wikimedia\Rdbms\DatabaseSqlite\duplicateTableStructure
duplicateTableStructure( $oldName, $newName, $temporary=false, $fname=__METHOD__)
Definition: DatabaseSqlite.php:968
Wikimedia\Rdbms\DatabaseSqlite\numFields
numFields( $res)
Definition: DatabaseSqlite.php:419
Wikimedia\Rdbms\DatabaseSqlite\tableName
tableName( $name, $format='quoted')
Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks.
Definition: DatabaseSqlite.php:453
array
the array() calling protocol came about after MediaWiki 1.4rc1.
Wikimedia\Rdbms\DatabaseSqlite\indexInfo
indexInfo( $table, $index, $fname=__METHOD__)
Returns information about an index Returns false if the index does not exist.
Definition: DatabaseSqlite.php:532
Wikimedia\Rdbms\DatabaseSqlite\textFieldSize
textFieldSize( $table, $field)
Returns the size of a text field, or -1 for "unlimited" In SQLite this is SQLITE_MAX_LENGTH,...
Definition: DatabaseSqlite.php:688
Wikimedia\Rdbms\Blob
Definition: Blob.php:5
Wikimedia\Rdbms\Database\$dbName
string $dbName
Database that this instance is currently connected to.
Definition: Database.php:85