r51795 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51794‎ | r51795 | r51796 >
Date:17:59, 12 June 2009
Author:simetrical
Status:ok (Comments)
Tags:
Comment:
Make Database into abstract class DatabaseBase

All other databases were changed to extend DatabaseBase instead of
Database. Database was kept as an alias for DatabaseMysql for
compatibility. Existing explicit references to Database that I could
find were changed to DatabaseMysql for the sake of clarity.

Should cause no functional changes.
Modified paths:
  • /trunk/extensions/BoardVote/BoardVote_body.php (modified) (history)
  • /trunk/extensions/MWSearch/luceneUpdate.php (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseIbm_db2.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMssql.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)
  • /trunk/phase3/t/inc/Database.t (modified) (history)
  • /trunk/phase3/tests/MediaWiki_TestCase.php (modified) (history)
  • /trunk/tools/WikipediaStatistics/index.php (modified) (history)
  • /trunk/tools/switch-master/MasterSwitcher.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/MediaWiki_TestCase.php
@@ -8,7 +8,7 @@
99 protected function buildTestDatabase( $tables ) {
1010 global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
1111 $wgDBprefix = 'parsertest_';
12 - $db = new Database(
 12+ $db = new DatabaseMysql(
1313 $wgDBserver,
1414 $wgDBadminuser,
1515 $wgDBadminpassword,
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -153,7 +153,7 @@
154154 /**
155155 * @ingroup Database
156156 */
157 -class DatabaseOracle extends Database {
 157+class DatabaseOracle extends DatabaseBase {
158158 var $mInsertId = NULL;
159159 var $mLastResult = NULL;
160160 var $numeric_version = NULL;
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -68,7 +68,7 @@
6969 /**
7070 * @ingroup Database
7171 */
72 -class DatabasePostgres extends Database {
 72+class DatabasePostgres extends DatabaseBase {
7373 var $mInsertId = NULL;
7474 var $mLastResult = NULL;
7575 var $numeric_version = NULL;
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php
@@ -102,7 +102,7 @@
103103 * Primary database interface
104104 * @ingroup Database
105105 */
106 -class DatabaseIbm_db2 extends Database {
 106+class DatabaseIbm_db2 extends DatabaseBase {
107107 /*
108108 * Inherited members
109109 protected $mLastQuery = '';
Index: trunk/phase3/includes/db/Database.php
@@ -19,7 +19,7 @@
2020 * Database abstraction object
2121 * @ingroup Database
2222 */
23 -class Database {
 23+abstract class DatabaseBase {
2424
2525 #------------------------------------------------------------------------------
2626 # Variables
@@ -307,7 +307,7 @@
308308 }
309309
310310 /**
311 - * Same as new Database( ... ), kept for backward compatibility
 311+ * Same as new DatabaseMysql( ... ), kept for backward compatibility
312312 * @param $server String: database server host
313313 * @param $user String: database user name
314314 * @param $password String: database user password
@@ -317,7 +317,7 @@
318318 */
319319 static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 )
320320 {
321 - return new Database( $server, $user, $password, $dbName, $failFunction, $flags );
 321+ return new DatabaseMysql( $server, $user, $password, $dbName, $failFunction, $flags );
322322 }
323323
324324 /**
@@ -2426,10 +2426,15 @@
24272427 * @ingroup Database
24282428 * @see Database
24292429 */
2430 -class DatabaseMysql extends Database {
 2430+class DatabaseMysql extends DatabaseBase {
24312431 # Inherit all
24322432 }
24332433
 2434+/**
 2435+ * Legacy support: Database == DatabaseMysql
 2436+ */
 2437+class Database extends DatabaseMysql {}
 2438+
24342439 /******************************************************************************
24352440 * Utility classes
24362441 *****************************************************************************/
Index: trunk/phase3/includes/db/DatabaseMssql.php
@@ -10,7 +10,7 @@
1111 /**
1212 * @ingroup Database
1313 */
14 -class DatabaseMssql extends Database {
 14+class DatabaseMssql extends DatabaseBase {
1515
1616 var $mAffectedRows;
1717 var $mLastResult;
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -10,7 +10,7 @@
1111 /**
1212 * @ingroup Database
1313 */
14 -class DatabaseSqlite extends Database {
 14+class DatabaseSqlite extends DatabaseBase {
1515
1616 var $mAffectedRows;
1717 var $mLastResult;
Index: trunk/phase3/includes/AutoLoader.php
@@ -303,6 +303,7 @@
304304 'Blob' => 'includes/db/Database.php',
305305 'ChronologyProtector' => 'includes/db/LBFactory.php',
306306 'Database' => 'includes/db/Database.php',
 307+ 'DatabaseBase' => 'includes/db/Database.php',
307308 'DatabaseMssql' => 'includes/db/DatabaseMssql.php',
308309 'DatabaseMysql' => 'includes/db/Database.php',
309310 'DatabaseOracle' => 'includes/db/DatabaseOracle.php',
Index: trunk/phase3/t/inc/Database.t
@@ -12,7 +12,7 @@
1313
1414 plan( 9 );
1515
16 -$db = new Database( $wgDBserver, $wgDBuser, $wgDBpassword );
 16+$db = new DatabaseMysql( $wgDBserver, $wgDBuser, $wgDBpassword );
1717
1818 cmp_ok( $db->addQuotes( NULL ), '==',
1919 'NULL', 'Add quotes to NULL' );
Index: trunk/extensions/BoardVote/BoardVote_body.php
@@ -215,7 +215,7 @@
216216 if ( !$this->mDb ) {
217217 global $wgBoardVoteDBServer, $wgBoardVoteDB, $wgDBuser, $wgDBpassword;
218218
219 - $this->mDb = new Database( $wgBoardVoteDBServer, $wgDBuser, $wgDBpassword,
 219+ $this->mDb = new DatabaseMysql( $wgBoardVoteDBServer, $wgDBuser, $wgDBpassword,
220220 $wgBoardVoteDB, /*failfn*/false, /*flags*/0, /*prefix*/'' );
221221 if ( !$this->mDb->isOpen() ) {
222222 // This should be handled inside the constructor, but we'll check just in case
Index: trunk/extensions/MWSearch/luceneUpdate.php
@@ -122,7 +122,7 @@
123123
124124 function &streamingSlave( $db ) {
125125 global $wgDBname;
126 - $stream = new Database( $db->mServer, $db->mUser, $db->mPassword, $wgDBname );
 126+ $stream = new DatabaseMysql( $db->mServer, $db->mUser, $db->mPassword, $wgDBname );
127127 $stream->bufferResults( false );
128128
129129 $timeout = 3600 * 24;
Index: trunk/tools/WikipediaStatistics/index.php
@@ -112,7 +112,7 @@
113113 <pre><?php
114114
115115 if ( isset( $_POST['update'] ) ) {
116 - $dbr = new Database();
 116+ $dbr = new DatabaseMysql();
117117 $dateRange = array(
118118 sprintf(
119119 'rev_timestamp > %s',
Index: trunk/tools/switch-master/MasterSwitcher.php
@@ -143,7 +143,7 @@
144144
145145 function getConnection( $host ) {
146146 if ( !isset( $this->conns[$host] ) ) {
147 - $this->conns[$host] = new Database( $host, $this->rootUser, $this->rootPass );
 147+ $this->conns[$host] = new DatabaseMysql( $host, $this->rootUser, $this->rootPass );
148148 }
149149 return $this->conns[$host];
150150 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r51918Move some stuff from DatabaseBase to DatabaseMysql...simetrical18:39, 15 June 2009

Comments

#Comment by Tim Starling (talk | contribs)   04:22, 15 June 2009

Wimp. You could have at least renamed the file. Also I'd like to see the constructor parameters changed to a single associative array, along the lines of $wgDBservers. None of the Database::__construct() parameters make sense for SQLite, and $failFunction doesn't make sense for any DBMS in PHP 5+.

Status & tagging log