14 protected function setUp() {
21 if ( $this->functionTest ) {
23 $this->functionTest =
false;
31 if ( $this->db->getType() ===
'sqlite' || $this->db->getType() ===
'oracle' ) {
34 $this->assertEquals( $check, $this->db->addQuotes(
null ) );
38 # returning just "1234" should be ok too, though...
42 $this->db->addQuotes( 1234 ) );
46 # returning just "1234.5678" would be ok too, though
49 $this->db->addQuotes( 1234.5678 ) );
55 $this->db->addQuotes(
'string' ) );
59 $check =
"'string''s cause trouble'";
60 if ( $this->db->getType() ===
'mysql' ) {
61 $check =
"'string\'s cause trouble'";
65 $this->db->addQuotes(
"string's cause trouble" ) );
68 private function getSharedTableName( $table, $database, $prefix, $format =
'quoted' ) {
69 global $wgSharedDB, $wgSharedTables, $wgSharedPrefix;
71 $oldName = $wgSharedDB;
72 $oldTables = $wgSharedTables;
73 $oldPrefix = $wgSharedPrefix;
75 $wgSharedDB = $database;
76 $wgSharedTables =
array( $table );
77 $wgSharedPrefix = $prefix;
79 $ret = $this->db->tableName( $table, $format );
81 $wgSharedDB = $oldName;
82 $wgSharedTables = $oldTables;
83 $wgSharedPrefix = $oldPrefix;
88 private function prefixAndQuote( $table, $database =
null, $prefix =
null, $format =
'quoted' ) {
89 if ( $this->db->getType() ===
'sqlite' || $format !==
'quoted' ) {
91 } elseif ( $this->db->getType() ===
'mysql' ) {
93 } elseif ( $this->db->getType() ===
'oracle' ) {
99 if ( $database !==
null ) {
100 if ( $this->db->getType() ===
'oracle' ) {
101 $database = $quote . $database .
'.';
103 $database = $quote . $database . $quote .
'.';
107 if ( $prefix ===
null ) {
111 if ( $this->db->getType() ===
'oracle' ) {
112 return strtoupper( $database . $quote . $prefix . $table );
114 return $database . $quote . $prefix . $table . $quote;
121 $this->db->tableName(
'tablename' )
128 $this->db->tableName(
'tablename',
'raw' )
146 $this->
prefixAndQuote(
'tablename',
'sharedatabase',
'sh_',
'raw' ),
151 $this->
prefixAndQuote(
'tablename',
'sharedatabase',
null,
'raw' ),
159 $this->db->tableName(
'databasename.tablename' )
166 $this->db->tableName(
'databasename.tablename',
'raw' )
171 $sql = $this->db->fillPrepared(
172 'SELECT * FROM interwiki',
array() );
174 "SELECT * FROM interwiki",
179 $sql = $this->db->fillPrepared(
180 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
181 array( 4,
"Snicker's_paradox" ) );
183 $check =
"SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker''s_paradox'";
184 if ( $this->db->getType() ===
'mysql' ) {
185 $check =
"SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'";
187 $this->assertEquals( $check, $sql );
191 $sql = $this->db->fillPrepared(
192 'SELECT user_id FROM ! WHERE user_name=?',
193 array(
'"user"',
"Slash's Dot" ) );
195 $check =
"SELECT user_id FROM \"user\" WHERE user_name='Slash''s Dot'";
196 if ( $this->db->getType() ===
'mysql' ) {
197 $check =
"SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'";
199 $this->assertEquals( $check, $sql );
203 $sql = $this->db->fillPrepared(
204 "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
205 array(
'"user"',
"Slash's Dot" ) );
207 "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
213 $this->markTestSkipped(
'MySQL or Postgres required' );
217 $this->functionTest =
true;
218 $this->assertTrue( $this->db->sourceFile(
"$IP/tests/phpunit/data/db/{$this->db->getType()}/functions.sql" ) );
219 $res = $this->db->query(
'SELECT mw_test_function() AS test', __METHOD__ );
220 $this->assertEquals( 42,
$res->fetchObject()->test );
224 $this->db->query(
'DROP FUNCTION IF EXISTS mw_test_function'
225 . ( $this->db->getType() ==
'postgres' ?
'()' :
'' )
230 $res = $this->db->select(
'page',
'*',
array(
'page_id' => 1 ) );
231 $this->assertFalse( $this->db->tableExists(
'foobarbaz' ) );
232 $this->assertInternalType(
'int',
$res->numRows() );