11 $p[
'dbFilePath'] =
':memory:';
14 return Database::factory(
'SqliteMock', $p );
27 return parent::replaceVars(
$s );
44 $this->markTestSkipped(
'No SQLite support detected' );
47 if ( version_compare( $this->db->getServerVersion(),
'3.6.0',
'<' ) ) {
48 $this->markTestSkipped(
"SQLite at least 3.6 required, {$this->db->getServerVersion()} found" );
54 return preg_replace(
'/\s+/',
' ', $this->db->replaceVars( $sql ) );
58 $this->assertNotNull(
$res );
60 foreach (
$res as $row ) {
61 foreach ( $expected[$i] as $key =>
$value ) {
62 $this->assertTrue( isset( $row->$key ) );
63 $this->assertEquals(
$value, $row->$key );
67 $this->assertEquals( count( $expected ), $i,
'Unexpected number of rows' );
76 'foo bar',
"'foo bar'"
79 'foo\'bar',
"'foo''bar'"
103 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
104 $this->assertEquals( $expected,
$db->
addQuotes(
$value ),
'string not quoted as expected' );
109 $this->assertTrue( $re !==
false,
'query failed' );
111 $row = $re->fetchRow();
117 $this->assertEquals(
$value, $row[0],
'string mangled by the database' );
119 $this->fail(
'query returned no result' );
127 $this->assertEquals(
'foo', $this->
replaceVars(
'foo' ),
"Don't break anything accidentally" );
130 "CREATE TABLE /**/foo (foo_key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
131 .
"foo_bar TEXT, foo_name TEXT NOT NULL DEFAULT '', foo_int INTEGER, foo_int2 INTEGER );",
133 "CREATE TABLE /**/foo (foo_key int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, "
134 .
"foo_bar char(13), foo_name varchar(255) binary NOT NULL DEFAULT '', "
135 .
"foo_int tinyint ( 8 ), foo_int2 int(16) ) ENGINE=MyISAM;"
140 "CREATE TABLE foo ( foo1 REAL, foo2 REAL, foo3 REAL );",
142 "CREATE TABLE foo ( foo1 FLOAT, foo2 DOUBLE( 1,10), foo3 DOUBLE PRECISION );"
146 $this->assertEquals(
"CREATE TABLE foo ( foo_binary1 BLOB, foo_binary2 BLOB );",
147 $this->
replaceVars(
"CREATE TABLE foo ( foo_binary1 binary(16), foo_binary2 varbinary(32) );" )
150 $this->assertEquals(
"CREATE TABLE text ( text_foo TEXT );",
151 $this->
replaceVars(
"CREATE TABLE text ( text_foo tinytext );" ),
155 $this->assertEquals(
"CREATE TABLE foo ( foobar INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL );",
156 $this->
replaceVars(
"CREATE TABLE foo ( foobar INT PRIMARY KEY NOT NULL AUTO_INCREMENT );" )
158 $this->assertEquals(
"CREATE TABLE foo ( foobar INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL );",
159 $this->
replaceVars(
"CREATE TABLE foo ( foobar INT PRIMARY KEY AUTO_INCREMENT NOT NULL );" )
162 $this->assertEquals(
"CREATE TABLE enums( enum1 TEXT, myenum TEXT)",
163 $this->
replaceVars(
"CREATE TABLE enums( enum1 ENUM('A', 'B'), myenum ENUM ('X', 'Y'))" )
166 $this->assertEquals(
"ALTER TABLE foo ADD COLUMN foo_bar INTEGER DEFAULT 42",
167 $this->
replaceVars(
"ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" )
170 $this->assertEquals(
"DROP INDEX foo",
171 $this->
replaceVars(
"DROP INDEX /*i*/foo ON /*_*/bar" )
174 $this->assertEquals(
"DROP INDEX foo -- dropping index",
175 $this->
replaceVars(
"DROP INDEX /*i*/foo ON /*_*/bar -- dropping index" )
177 $this->assertEquals(
"INSERT OR IGNORE INTO foo VALUES ('bar')",
178 $this->
replaceVars(
"INSERT OR IGNORE INTO foo VALUES ('bar')" )
187 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
189 $this->assertEquals(
'sqlite_master',
$db->
tableName(
'sqlite_master' ) );
191 $this->assertEquals(
'sqlite_master',
$db->
tableName(
'sqlite_master' ) );
192 $this->assertEquals(
'foobar',
$db->
tableName(
'bar' ) );
199 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
200 $db->
query(
'CREATE TABLE foo(foo, barfoo)' );
201 $db->
query(
'CREATE INDEX index1 ON foo(foo)' );
202 $db->
query(
'CREATE UNIQUE INDEX index2 ON foo(barfoo)' );
205 $this->assertEquals(
'CREATE TABLE "bar"(foo, barfoo)',
207 'Normal table duplication'
209 $indexList =
$db->
query(
'PRAGMA INDEX_LIST("bar")' );
210 $index = $indexList->next();
211 $this->assertEquals(
'bar_index1', $index->name );
212 $this->assertEquals(
'0', $index->unique );
213 $index = $indexList->next();
214 $this->assertEquals(
'bar_index2', $index->name );
215 $this->assertEquals(
'1', $index->unique );
218 $this->assertEquals(
'CREATE TABLE "baz"(foo, barfoo)',
219 $db->
selectField(
'sqlite_temp_master',
'sql', [
'name' =>
'baz' ] ),
220 'Creation of temporary duplicate'
222 $indexList =
$db->
query(
'PRAGMA INDEX_LIST("baz")' );
223 $index = $indexList->next();
224 $this->assertEquals(
'baz_index1', $index->name );
225 $this->assertEquals(
'0', $index->unique );
226 $index = $indexList->next();
227 $this->assertEquals(
'baz_index2', $index->name );
228 $this->assertEquals(
'1', $index->unique );
229 $this->assertEquals( 0,
230 $db->
selectField(
'sqlite_master',
'COUNT(*)', [
'name' =>
'baz' ] ),
231 'Create a temporary duplicate only'
239 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
241 $this->markTestSkipped(
'FTS3 not supported, cannot create virtual tables' );
243 $db->
query(
'CREATE VIRTUAL TABLE "foo" USING FTS3(foobar)' );
246 $this->assertEquals(
'CREATE VIRTUAL TABLE "bar" USING FTS3(foobar)',
248 'Duplication of virtual tables'
252 $this->assertEquals(
'CREATE VIRTUAL TABLE "baz" USING FTS3(foobar)',
254 "Can't create temporary virtual tables, should fall back to non-temporary duplication"
262 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
263 $db->
query(
'CREATE TABLE a (a_1)', __METHOD__ );
264 $db->
query(
'CREATE TABLE b (b_1, b_2)', __METHOD__ );
273 [
'b_1' => 2,
'b_2' =>
'a' ],
274 [
'b_1' => 3,
'b_2' =>
'b' ],
278 $db->
deleteJoin(
'a',
'b',
'a_1',
'b_1', [
'b_2' =>
'a' ], __METHOD__ );
292 if ( $result !==
true ) {
293 $this->fail( $result );
295 $this->assertTrue(
true );
317 'user_newtalk.user_last_timestamp',
320 $currentDB = DatabaseSqlite::newStandaloneInstance(
':memory:' );
321 $currentDB->sourceFile(
"$IP/maintenance/tables.sql" );
323 $profileToDb =
false;
326 if (
$out ===
'db' ) {
328 } elseif ( is_array(
$out ) && in_array(
'db',
$out ) ) {
333 if ( $profileToDb ) {
334 $currentDB->sourceFile(
"$IP/maintenance/sqlite/archives/patch-profiling.sql" );
336 $currentTables = $this->
getTables( $currentDB );
337 sort( $currentTables );
339 foreach ( $versions as $version ) {
340 $versions =
"upgrading from $version to $wgVersion";
343 $this->assertEquals( $currentTables,
$tables,
"Different tables $versions" );
344 foreach (
$tables as $table ) {
345 $currentCols = $this->
getColumns( $currentDB, $table );
348 array_keys( $currentCols ),
350 "Mismatching columns for table \"$table\" $versions"
352 foreach ( $currentCols as $name => $column ) {
356 (
bool)$cols[$name]->pk,
357 "PRIMARY KEY status does not match for column $fullName $versions"
359 if ( !in_array(
$fullName, $ignoredColumns ) ) {
361 (
bool)$column->notnull,
362 (
bool)$cols[$name]->notnull,
363 "NOT NULL status does not match for column $fullName $versions"
367 $cols[$name]->dflt_value,
368 "Default values does not match for column $fullName $versions"
372 $currentIndexes = $this->
getIndexes( $currentDB, $table );
375 array_keys( $currentIndexes ),
376 array_keys( $indexes ),
377 "mismatching indexes for table \"$table\" $versions"
388 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
390 $databaseCreation =
$db->
query(
'CREATE TABLE a ( a_1 )', __METHOD__ );
391 $this->assertInstanceOf(
'ResultWrapper', $databaseCreation,
"Database creation" );
393 $insertion =
$db->
insert(
'a', [
'a_1' => 10 ], __METHOD__ );
394 $this->assertTrue( $insertion,
"Insertion worked" );
396 $this->assertInternalType(
'integer',
$db->
insertId(),
"Actual typecheck" );
397 $this->assertTrue(
$db->
close(),
"closing database" );
401 static $maint =
null;
402 if ( $maint ===
null ) {
404 $maint->loadParamsAndArgs(
null, [
'quiet' => 1 ] );
408 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
409 $db->
sourceFile(
"$IP/tests/phpunit/data/db/sqlite/tables-$version.sql" );
411 $updater->doUpdates( [
'core' ] );
423 'searchindex_content',
424 'searchindex_segments',
425 'searchindex_segdir',
427 'searchindex_docsize',
430 foreach ( $excluded as
$t ) {
433 $list = array_flip( $list );
442 $this->assertNotNull(
$res );
443 foreach (
$res as $col ) {
444 $cols[$col->name] = $col;
454 $this->assertNotNull(
$res );
455 foreach (
$res as $index ) {
456 $res2 =
$db->
query(
"PRAGMA index_info({$index->name})" );
457 $this->assertNotNull( $res2 );
458 $index->columns = [];
459 foreach ( $res2 as $col ) {
460 $index->columns[] = $col;
462 $indexes[$index->name] = $index;
471 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
473 $row =
$res->fetchRow();
474 $this->assertFalse( (
bool)$row[
'a'] );
481 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
483 $databaseCreation =
$db->
query(
'CREATE TABLE a ( a_1 )', __METHOD__ );
484 $this->assertInstanceOf(
'ResultWrapper', $databaseCreation,
"Failed to create table a" );
486 $this->assertEquals( 0,
$db->
numFields(
$res ),
"expects to get 0 fields for an empty table" );
487 $insertion =
$db->
insert(
'a', [
'a_1' => 10 ], __METHOD__ );
488 $this->assertTrue( $insertion,
"Insertion failed" );
492 $this->assertTrue(
$db->
close(),
"closing database" );
496 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
500 $this->assertContains(
'SQLite ', $toString );
$wgVersion
MediaWiki version number.
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
replaceVars( $s)
Override parent visibility to public.
query( $sql, $fname='', $tempIgnore=false)
Run an SQL query and return the result.
static newInstance(array $p=[])
testCaseInsensitiveLike()
testDuplicateTableStructureVirtual()
DatabaseSqlite::duplicateTableStructure.
testInsertIdType()
DatabaseSqlite::insertId.
assertResultIs( $expected, $res)
testAddQuotes( $value, $expected)
provideAddQuotes() DatabaseSqlite::addQuotes
testUpgrades()
Runs upgrades of older databases and compares results with current schema.
static provideAddQuotes()
testReplaceVars()
DatabaseSqlite::replaceVars.
testTableName()
DatabaseSqlite::tableName.
testNumFields()
DatabaseSqlite::numFields.
testDuplicateTableStructure()
DatabaseSqlite::duplicateTableStructure.
testDeleteJoin()
DatabaseSqlite::deleteJoin.
static newForDB(Database $db, $shared=false, $maintenance=null)
Fake maintenance wrapper, mostly used for the web installer/updater.
static isPresent()
Checks whether PHP has SQLite support.
static checkSqlSyntax( $files)
Checks given files for correctness of SQL syntax.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
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
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out