22 if ( $this->functionTest ) {
24 $this->functionTest =
false;
32 if ( $this->db->getType() ===
'sqlite' || $this->db->getType() ===
'oracle' ) {
35 $this->assertEquals( $check, $this->db->addQuotes( null ) );
39 # returning just "1234" should be ok too, though...
43 $this->db->addQuotes( 1234 ) );
47 # returning just "1234.5678" would be ok too, though
50 $this->db->addQuotes( 1234.5678 ) );
56 $this->db->addQuotes(
'string' ) );
60 $check =
"'string''s cause trouble'";
61 if ( $this->db->getType() ===
'mysql' ) {
62 $check =
"'string\'s cause trouble'";
66 $this->db->addQuotes(
"string's cause trouble" ) );
76 $wgSharedDB = $database;
77 $wgSharedTables = [ $table ];
78 $wgSharedPrefix = $prefix;
80 $ret = $this->db->tableName( $table, $format );
82 $wgSharedDB = $oldName;
83 $wgSharedTables = $oldTables;
84 $wgSharedPrefix = $oldPrefix;
89 private function prefixAndQuote( $table, $database = null, $prefix = null, $format =
'quoted' ) {
90 if ( $this->db->getType() ===
'sqlite' || $format !==
'quoted' ) {
92 } elseif ( $this->db->getType() ===
'mysql' ) {
94 } elseif ( $this->db->getType() ===
'oracle' ) {
100 if ( $database !== null ) {
101 if ( $this->db->getType() ===
'oracle' ) {
102 $database = $quote . $database .
'.';
104 $database = $quote . $database . $quote .
'.';
108 if ( $prefix === null ) {
112 if ( $this->db->getType() ===
'oracle' ) {
113 return strtoupper( $database . $quote . $prefix . $table );
115 return $database . $quote . $prefix . $table . $quote;
122 $this->db->tableName(
'tablename' )
129 $this->db->tableName(
'tablename',
'raw' )
147 $this->
prefixAndQuote(
'tablename',
'sharedatabase',
'sh_',
'raw' ),
152 $this->
prefixAndQuote(
'tablename',
'sharedatabase', null,
'raw' ),
160 $this->db->tableName(
'databasename.tablename' )
167 $this->db->tableName(
'databasename.tablename',
'raw' )
172 $sql = $this->db->fillPrepared(
173 'SELECT * FROM interwiki', [] );
175 "SELECT * FROM interwiki",
180 $sql = $this->db->fillPrepared(
181 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
182 [ 4,
"Snicker's_paradox" ] );
184 $check =
"SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker''s_paradox'";
185 if ( $this->db->getType() ===
'mysql' ) {
186 $check =
"SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'";
188 $this->assertEquals( $check, $sql );
192 $sql = $this->db->fillPrepared(
193 'SELECT user_id FROM ! WHERE user_name=?',
194 [
'"user"',
"Slash's Dot" ] );
196 $check =
"SELECT user_id FROM \"user\" WHERE user_name='Slash''s Dot'";
197 if ( $this->db->getType() ===
'mysql' ) {
198 $check =
"SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'";
200 $this->assertEquals( $check, $sql );
204 $sql = $this->db->fillPrepared(
205 "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
206 [
'"user"',
"Slash's Dot" ] );
208 "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
213 if ( !in_array(
wfGetDB(
DB_MASTER )->getType(), [
'mysql',
'postgres' ] ) ) {
214 $this->markTestSkipped(
'MySQL or Postgres required' );
218 $this->functionTest =
true;
220 $this->db->sourceFile(
"$IP/tests/phpunit/data/db/{$this->db->getType()}/functions.sql" )
222 $res = $this->db->query(
'SELECT mw_test_function() AS test', __METHOD__ );
223 $this->assertEquals( 42, $res->fetchObject()->test );
227 $this->db->query(
'DROP FUNCTION IF EXISTS mw_test_function'
228 . ( $this->db->getType() ==
'postgres' ?
'()' :
'' )
233 $res = $this->db->select(
'page',
'*', [
'page_id' => 1 ] );
234 $this->assertFalse( $this->db->tableExists(
'foobarbaz' ) );
235 $this->assertInternalType(
'int',
$res->numRows() );
248 $this->assertFalse( $flagSet,
'DBO_TRX off in callback' );
250 $this->assertTrue(
$called,
'Callback reached' );
257 $this->assertFalse( $flagSet,
'DBO_TRX off in callback' );
279 $this->assertTrue(
$called,
'Callback reached' );
290 $this->assertTrue(
$called,
'Callback reached' );
testAddQuotesNull()
DatabaseBase::dropTable.
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
clearFlag($flag)
Clear a flag for this connection.
prefixAndQuote($table, $database=null, $prefix=null, $format= 'quoted')
getSharedTableName($table, $database, $prefix, $format= 'quoted')
testTableNameRawForeign()
when a variable name is used in a it is silently declared as a new local masking the global
testFillPreparedQuestion()
testUnknownTableCorruptsResults()
getFlag($flag)
Returns a boolean whether the flag $flag is set for this connection.
$wgSharedDB
Shared database for multiple wikis.
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
setFlag($flag)
Set a flag for this connection.
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
testAddQuotesStringQuote()
onTransactionResolution(callable $callback)
Run a callback as soon as the current transaction commits or rolls back.
onTransactionIdle(callable $callback)
Run a callback as soon as there is no transaction pending.
begin($fname=__METHOD__)
Begin a transaction.
commit($fname=__METHOD__, $flush= '')
Commits a transaction previously started using begin().
rollback($fname=__METHOD__, $flush= '')
Rollback a transaction previously started using begin().
testTransactionResolution()