Go to the documentation of this file.
26 $this->assertEquals(
$db->getLastSqls(), $sqlText );
37 isset( $sql[
'conds'] ) ? $sql[
'conds'] : [],
39 isset( $sql[
'options'] ) ? $sql[
'options'] : [],
40 isset( $sql[
'join_conds'] ) ? $sql[
'join_conds'] : []
50 'fields' => [
'field',
'alias' =>
'field2' ],
51 'conds' => [
'alias' =>
'text' ],
53 "SELECT field,field2 AS alias " .
55 "WHERE alias = 'text'"
60 'fields' => [
'field',
'alias' =>
'field2' ],
61 'conds' => [
'alias' =>
'text' ],
62 'options' => [
'LIMIT' => 1,
'ORDER BY' =>
'field' ],
64 "SELECT field,field2 AS alias " .
66 "WHERE alias = 'text' " .
72 'tables' => [
'table',
't2' =>
'table2' ],
73 'fields' => [
'tid',
'field',
'alias' =>
'field2',
't2.id' ],
74 'conds' => [
'alias' =>
'text' ],
75 'options' => [
'LIMIT' => 1,
'ORDER BY' =>
'field' ],
76 'join_conds' => [
't2' => [
77 'LEFT JOIN',
'tid = t2.id'
80 "SELECT tid,field,field2 AS alias,t2.id " .
81 "FROM table LEFT JOIN table2 t2 ON ((tid = t2.id)) " .
82 "WHERE alias = 'text' " .
88 'tables' => [
'table',
't2' =>
'table2' ],
89 'fields' => [
'tid',
'field',
'alias' =>
'field2',
't2.id' ],
90 'conds' => [
'alias' =>
'text' ],
91 'options' => [
'LIMIT' => 1,
'GROUP BY' =>
'field',
'HAVING' =>
'COUNT(*) > 1' ],
92 'join_conds' => [
't2' => [
93 'LEFT JOIN',
'tid = t2.id'
96 "SELECT tid,field,field2 AS alias,t2.id " .
97 "FROM table LEFT JOIN table2 t2 ON ((tid = t2.id)) " .
98 "WHERE alias = 'text' " .
99 "GROUP BY field HAVING COUNT(*) > 1 " .
104 'tables' => [
'table',
't2' =>
'table2' ],
105 'fields' => [
'tid',
'field',
'alias' =>
'field2',
't2.id' ],
106 'conds' => [
'alias' =>
'text' ],
109 'GROUP BY' => [
'field',
'field2' ],
110 'HAVING' => [
'COUNT(*) > 1',
'field' => 1 ]
112 'join_conds' => [
't2' => [
113 'LEFT JOIN',
'tid = t2.id'
116 "SELECT tid,field,field2 AS alias,t2.id " .
117 "FROM table LEFT JOIN table2 t2 ON ((tid = t2.id)) " .
118 "WHERE alias = 'text' " .
119 "GROUP BY field,field2 HAVING (COUNT(*) > 1) AND field = '1' " .
124 'tables' => [
'table' ],
125 'fields' => [
'alias' =>
'field' ],
126 'conds' => [
'alias' => [ 1, 2, 3, 4 ] ],
128 "SELECT field AS alias " .
130 "WHERE alias IN ('1','2','3','4')"
145 isset( $sql[
'options'] ) ? $sql[
'options'] : []
155 'values' => [
'field' =>
'text',
'field2' =>
'text2' ],
156 'conds' => [
'alias' =>
'text' ],
159 "SET field = 'text'" .
160 ",field2 = 'text2' " .
161 "WHERE alias = 'text'"
166 'values' => [
'field = other',
'field2' =>
'text2' ],
167 'conds' => [
'id' =>
'1' ],
170 "SET field = other" .
171 ",field2 = 'text2' " .
177 'values' => [
'field = other',
'field2' =>
'text2' ],
181 "SET field = other" .
205 'conds' => [
'alias' =>
'text' ],
207 "DELETE FROM table " .
208 "WHERE alias = 'text'"
228 $sql[
'uniqueIndexes'],
239 'table' =>
'upsert_table',
240 'rows' => [
'field' =>
'text',
'field2' =>
'text2' ],
241 'uniqueIndexes' => [
'field' ],
242 'set' => [
'field' =>
'set' ],
245 "UPDATE upsert_table " .
246 "SET field = 'set' " .
247 "WHERE ((field = 'text')); " .
248 "INSERT IGNORE INTO upsert_table " .
250 "VALUES ('text','text2'); " .
276 'delTable' =>
'table',
277 'joinTable' =>
'table_join',
279 'joinVar' =>
'field_join',
280 'conds' => [
'alias' =>
'text' ],
282 "DELETE FROM table " .
284 "SELECT field_join FROM table_join WHERE alias = 'text'" .
289 'delTable' =>
'table',
290 'joinTable' =>
'table_join',
292 'joinVar' =>
'field_join',
295 "DELETE FROM table " .
297 "SELECT field_join FROM table_join " .
312 isset( $sql[
'options'] ) ? $sql[
'options'] : []
322 'rows' => [
'field' =>
'text',
'field2' => 2 ],
324 "INSERT INTO table " .
326 "VALUES ('text','2')"
331 'rows' => [
'field' =>
'text',
'field2' => 2 ],
332 'options' =>
'IGNORE',
334 "INSERT IGNORE INTO table " .
336 "VALUES ('text','2')"
342 [
'field' =>
'text',
'field2' => 2 ],
343 [
'field' =>
'multi',
'field2' => 3 ],
345 'options' =>
'IGNORE',
347 "INSERT IGNORE INTO table " .
367 isset( $sql[
'insertOptions'] ) ? $sql[
'insertOptions'] : [],
368 isset( $sql[
'selectOptions'] ) ? $sql[
'selectOptions'] : []
373 $dbWeb->forceNextResult( [
374 array_flip( array_keys( $sql[
'varMap'] ) )
376 $dbWeb->insertSelect(
382 isset( $sql[
'insertOptions'] ) ? $sql[
'insertOptions'] : [],
383 isset( $sql[
'selectOptions'] ) ? $sql[
'selectOptions'] : []
385 $this->
assertLastSqlDb( implode(
'; ', [ $sqlSelect, $sqlInsert ] ), $dbWeb );
392 'destTable' =>
'insert_table',
393 'srcTable' =>
'select_table',
394 'varMap' => [
'field_insert' =>
'field_select',
'field' =>
'field2' ],
397 "INSERT INTO insert_table " .
398 "(field_insert,field) " .
399 "SELECT field_select,field2 " .
401 "SELECT field_select AS field_insert,field2 AS field " .
402 "FROM select_table WHERE * FOR UPDATE",
403 "INSERT INTO insert_table (field_insert,field) VALUES ('0','1')"
407 'destTable' =>
'insert_table',
408 'srcTable' =>
'select_table',
409 'varMap' => [
'field_insert' =>
'field_select',
'field' =>
'field2' ],
410 'conds' => [
'field' => 2 ],
412 "INSERT INTO insert_table " .
413 "(field_insert,field) " .
414 "SELECT field_select,field2 " .
415 "FROM select_table " .
417 "SELECT field_select AS field_insert,field2 AS field FROM " .
418 "select_table WHERE field = '2' FOR UPDATE",
419 "INSERT INTO insert_table (field_insert,field) VALUES ('0','1')"
423 'destTable' =>
'insert_table',
424 'srcTable' =>
'select_table',
425 'varMap' => [
'field_insert' =>
'field_select',
'field' =>
'field2' ],
426 'conds' => [
'field' => 2 ],
427 'insertOptions' =>
'IGNORE',
428 'selectOptions' => [
'ORDER BY' =>
'field' ],
430 "INSERT IGNORE INTO insert_table " .
431 "(field_insert,field) " .
432 "SELECT field_select,field2 " .
433 "FROM select_table " .
434 "WHERE field = '2' " .
436 "SELECT field_select AS field_insert,field2 AS field " .
437 "FROM select_table WHERE field = '2' ORDER BY field FOR UPDATE",
438 "INSERT IGNORE INTO insert_table (field_insert,field) VALUES ('0','1')"
450 $sql[
'uniqueIndexes'],
461 'table' =>
'replace_table',
462 'uniqueIndexes' => [
'field' ],
463 'rows' => [
'field' =>
'text',
'field2' =>
'text2' ],
465 "DELETE FROM replace_table " .
466 "WHERE ( field='text' ); " .
467 "INSERT INTO replace_table " .
469 "VALUES ('text','text2')"
473 'table' =>
'module_deps',
474 'uniqueIndexes' => [ [
'md_module',
'md_skin' ] ],
476 'md_module' =>
'module',
481 "DELETE FROM module_deps " .
482 "WHERE ( md_module='module' AND md_skin='skin' ); " .
483 "INSERT INTO module_deps " .
484 "(md_module,md_skin,md_deps) " .
485 "VALUES ('module','skin','deps')"
489 'table' =>
'module_deps',
490 'uniqueIndexes' => [ [
'md_module',
'md_skin' ] ],
493 'md_module' =>
'module',
497 'md_module' =>
'module2',
498 'md_skin' =>
'skin2',
499 'md_deps' =>
'deps2',
503 "DELETE FROM module_deps " .
504 "WHERE ( md_module='module' AND md_skin='skin' ); " .
505 "INSERT INTO module_deps " .
506 "(md_module,md_skin,md_deps) " .
507 "VALUES ('module','skin','deps'); " .
508 "DELETE FROM module_deps " .
509 "WHERE ( md_module='module2' AND md_skin='skin2' ); " .
510 "INSERT INTO module_deps " .
511 "(md_module,md_skin,md_deps) " .
512 "VALUES ('module2','skin2','deps2')"
516 'table' =>
'module_deps',
517 'uniqueIndexes' => [
'md_module',
'md_skin' ],
520 'md_module' =>
'module',
524 'md_module' =>
'module2',
525 'md_skin' =>
'skin2',
526 'md_deps' =>
'deps2',
530 "DELETE FROM module_deps " .
531 "WHERE ( md_module='module' ) OR ( md_skin='skin' ); " .
532 "INSERT INTO module_deps " .
533 "(md_module,md_skin,md_deps) " .
534 "VALUES ('module','skin','deps'); " .
535 "DELETE FROM module_deps " .
536 "WHERE ( md_module='module2' ) OR ( md_skin='skin2' ); " .
537 "INSERT INTO module_deps " .
538 "(md_module,md_skin,md_deps) " .
539 "VALUES ('module2','skin2','deps2')"
543 'table' =>
'module_deps',
544 'uniqueIndexes' => [],
546 'md_module' =>
'module',
551 "INSERT INTO module_deps " .
552 "(md_module,md_skin,md_deps) " .
553 "VALUES ('module','skin','deps')"
575 'table' =>
'replace_table',
576 'rows' => [
'field' =>
'text',
'field2' =>
'text2' ],
578 "REPLACE INTO replace_table " .
580 "VALUES ('text','text2')"
590 $this->assertEquals( trim( $this->
database->conditional(
601 'conds' => [
'field' =>
'text' ],
605 "(CASE WHEN field = 'text' THEN 1 ELSE NULL END)"
609 'conds' => [
'field' =>
'text',
'field2' =>
'anothertext' ],
613 "(CASE WHEN field = 'text' AND field2 = 'anothertext' THEN 1 ELSE NULL END)"
617 'conds' =>
'field=1',
621 "(CASE WHEN field=1 THEN 1 ELSE NULL END)"
631 $this->assertEquals( trim( $this->
database->buildConcat(
639 [
'field',
'field2' ],
640 "CONCAT(field,field2)"
643 [
"'test'",
'field2' ],
644 "CONCAT('test',field2)"
654 $this->assertEquals( trim( $this->
database->buildLike(
663 "LIKE 'text' ESCAPE '`'"
667 "LIKE 'text%' ESCAPE '`'"
670 [
'text',
new LikeMatch(
'%' ),
'text2' ],
671 "LIKE 'text%text2' ESCAPE '`'"
675 "LIKE 'text_' ESCAPE '`'"
679 "LIKE 'more`_text' ESCAPE '`'"
682 [
'C:\\Windows\\',
new LikeMatch(
'%' ) ],
683 "LIKE 'C:\\Windows\\%' ESCAPE '`'"
686 [
'accent`_test`',
new LikeMatch(
'%' ) ],
687 "LIKE 'accent```_test``%' ESCAPE '`'"
697 $this->assertEquals( trim( $this->
database->unionQueries(
707 'sqls' => [
'RAW SQL',
'RAW2SQL' ],
710 "(RAW SQL) UNION ALL (RAW2SQL)"
714 'sqls' => [
'RAW SQL',
'RAW2SQL' ],
717 "(RAW SQL) UNION (RAW2SQL)"
721 'sqls' => [
'RAW SQL',
'RAW2SQL',
'RAW3SQL' ],
724 "(RAW SQL) UNION (RAW2SQL) UNION (RAW3SQL)"
733 $this->
database->begin( __METHOD__ );
734 $this->
database->commit( __METHOD__ );
742 $this->
database->begin( __METHOD__ );
743 $this->
database->rollback( __METHOD__ );
751 $this->
database->setExistingTables( [
'table' ] );
752 $this->
database->dropTable(
'table', __METHOD__ );
761 $this->
database->dropTable(
'non_existing', __METHOD__ )
770 $this->assertEquals( trim( $this->
database->makeList(
778 [
'value',
'value2' ],
783 [
'field',
'field2' ],
788 [
'field' =>
'value',
'field2' =>
'value2' ],
790 "field = 'value' AND field2 = 'value2'"
793 [
'field' =>
null,
"field2 != 'value2'" ],
795 "field IS NULL AND (field2 != 'value2')"
798 [
'field' => [
'value',
null,
'value2' ],
'field2' =>
'value2' ],
800 "(field IN ('value','value2') OR field IS NULL) AND field2 = 'value2'"
803 [
'field' => [ null ],
'field2' => null ],
805 "field IS NULL AND field2 IS NULL"
808 [
'field' =>
'value',
'field2' =>
'value2' ],
810 "field = 'value' OR field2 = 'value2'"
813 [
'field' =>
'value',
'field2' => null ],
815 "field = 'value' OR field2 IS NULL"
818 [
'field' => [
'value',
'value2' ],
'field2' => [
'value' ] ],
820 "field IN ('value','value2') OR field2 = 'value'"
823 [
'field' => [
null,
'value',
null,
'value2' ],
"field2 != 'value2'" ],
825 "(field IN ('value','value2') OR field IS NULL) OR (field2 != 'value2')"
828 [
'field' =>
'value',
'field2' =>
'value2' ],
830 "field = 'value',field2 = 'value2'"
833 [
'field' =>
'value',
'field2' => null ],
835 "field = 'value',field2 = NULL"
838 [
'field' =>
'value',
"field2 != 'value2'" ],
840 "field = 'value',field2 != 'value2'"
846 $temp1 = $this->
database->tableName(
'tmp_table_1' );
847 $temp2 = $this->
database->tableName(
'tmp_table_2' );
848 $temp3 = $this->
database->tableName(
'tmp_table_3' );
850 $this->
database->query(
"CREATE TEMPORARY TABLE $temp1 LIKE orig_tbl", __METHOD__ );
851 $this->
database->query(
"CREATE TEMPORARY TABLE $temp2 LIKE orig_tbl", __METHOD__ );
852 $this->
database->query(
"CREATE TEMPORARY TABLE $temp3 LIKE orig_tbl", __METHOD__ );
854 $this->assertTrue( $this->
database->tableExists(
"tmp_table_1", __METHOD__ ) );
855 $this->assertTrue( $this->
database->tableExists(
"tmp_table_2", __METHOD__ ) );
856 $this->assertTrue( $this->
database->tableExists(
"tmp_table_3", __METHOD__ ) );
858 $this->
database->dropTable(
'tmp_table_1', __METHOD__ );
859 $this->
database->dropTable(
'tmp_table_2', __METHOD__ );
860 $this->
database->dropTable(
'tmp_table_3', __METHOD__ );
862 $this->assertFalse( $this->
database->tableExists(
"tmp_table_1", __METHOD__ ) );
863 $this->assertFalse( $this->
database->tableExists(
"tmp_table_2", __METHOD__ ) );
864 $this->assertFalse( $this->
database->tableExists(
"tmp_table_3", __METHOD__ ) );
866 $this->
database->query(
"CREATE TEMPORARY TABLE tmp_table_1 LIKE orig_tbl", __METHOD__ );
867 $this->
database->query(
"CREATE TEMPORARY TABLE 'tmp_table_2' LIKE orig_tbl", __METHOD__ );
868 $this->
database->query(
"CREATE TEMPORARY TABLE `tmp_table_3` LIKE orig_tbl", __METHOD__ );
870 $this->assertTrue( $this->
database->tableExists(
"tmp_table_1", __METHOD__ ) );
871 $this->assertTrue( $this->
database->tableExists(
"tmp_table_2", __METHOD__ ) );
872 $this->assertTrue( $this->
database->tableExists(
"tmp_table_3", __METHOD__ ) );
874 $this->
database->query(
"DROP TEMPORARY TABLE tmp_table_1 LIKE orig_tbl", __METHOD__ );
875 $this->
database->query(
"DROP TEMPORARY TABLE 'tmp_table_2' LIKE orig_tbl", __METHOD__ );
876 $this->
database->query(
"DROP TABLE `tmp_table_3` LIKE orig_tbl", __METHOD__ );
878 $this->assertFalse( $this->
database->tableExists(
"tmp_table_1", __METHOD__ ) );
879 $this->assertFalse( $this->
database->tableExists(
"tmp_table_2", __METHOD__ ) );
880 $this->assertFalse( $this->
database->tableExists(
"tmp_table_3", __METHOD__ ) );
static provideUnionQueries()
static provideNativeReplace()
testBuildConcat( $stringList, $sqlText)
provideBuildConcat Database::buildConcat
DatabaseTestHelper $database
static provideDeleteJoin()
testDropTable()
Database::dropTable.
testMakeList( $list, $mode, $sqlText)
provideMakeList Database::makeList
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
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
static provideBuildConcat()
testUnionQueries( $sql, $sqlText)
provideUnionQueries Database::unionQueries
testTransactionCommit()
Database::commit.
testDeleteJoin( $sql, $sqlText)
provideDeleteJoin Database::deleteJoin
testUpsert( $sql, $sqlText)
provideUpsert Database::upsert
testConditional( $sql, $sqlText)
provideConditional Database::conditional
testDropNonExistingTable()
Database::dropTable.
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 database
testInsert( $sql, $sqlText)
provideInsert Database::insert
testInsertSelect( $sql, $sqlTextNative, $sqlSelect, $sqlInsert)
provideInsertSelect Database::insertSelect
testUpdate( $sql, $sqlText)
provideUpdate Database::update
testDelete( $sql, $sqlText)
provideDelete Database::delete
testTransactionRollback()
Database::rollback.
Helper for testing the methods from the Database class.
testReplace( $sql, $sqlText)
provideReplace Database::replace
testNativeReplace( $sql, $sqlText)
provideNativeReplace Database::nativeReplace
Test the abstract database layer This is a non DBMS depending test.
static provideConditional()
testBuildLike( $array, $sqlText)
provideBuildLike Database::buildLike
testSelect( $sql, $sqlText)
provideSelect Database::select
assertLastSqlDb( $sqlText, $db)
static provideInsertSelect()
static provideBuildLike()