r51999 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51998‎ | r51999 | r52000 >
Date:20:22, 16 June 2009
Author:simetrical
Status:ok
Tags:
Comment:
Make some Database methods optional to override

Specifically freeResult(), selectDB(), close(), and ping(), as suggested
by Tim on code review for r51918. Where these were overridden by stubs
in subclasses, I deleted the stubs.
Modified paths:
  • /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)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -950,11 +950,6 @@
951951 return $s;
952952 }
953953
954 - /* For now, does nothing */
955 - function selectDB( $db ) {
956 - return true;
957 - }
958 -
959954 function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) {
960955 if (is_array($table))
961956 foreach ($table as $tab)
@@ -1052,11 +1047,6 @@
10531048 // @todo fixme no-op
10541049 }
10551050
1056 - function ping() {
1057 - wfDebug( "Function ping() not written for DatabaseOracle.php yet");
1058 - return true;
1059 - }
1060 -
10611051 /**
10621052 * How lagged is this slave?
10631053 *
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -1324,11 +1324,6 @@
13251325 return '"' . preg_replace( '/"/', '""', $s) . '"';
13261326 }
13271327
1328 - /* For now, does nothing */
1329 - function selectDB( $db ) {
1330 - return true;
1331 - }
1332 -
13331328 /**
13341329 * Postgres specific version of replaceVars.
13351330 * Calls the parent version in Database.php
@@ -1396,11 +1391,6 @@
13971392 // @todo fixme no-op
13981393 }
13991394
1400 - function ping() {
1401 - wfDebug( "Function ping() not written for DatabasePostgres.php yet");
1402 - return true;
1403 - }
1404 -
14051395 /**
14061396 * How lagged is this slave?
14071397 *
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php
@@ -1463,15 +1463,6 @@
14641464 }
14651465
14661466 /**
1467 - * Does nothing
1468 - * @param object $db
1469 - * @return bool true
1470 - */
1471 - public function selectDB( $db ) {
1472 - return true;
1473 - }
1474 -
1475 - /**
14761467 * Returns an SQL expression for a simple conditional.
14771468 * Uses CASE on DB2
14781469 *
Index: trunk/phase3/includes/db/Database.php
@@ -360,7 +360,10 @@
361361 *
362362 * @return Bool operation success. true if already closed.
363363 */
364 - abstract function close();
 364+ function close() {
 365+ # Stub, should probably be overridden
 366+ return true;
 367+ }
365368
366369 /**
367370 * @param $error String: fallback error message, used if none is given by MySQL
@@ -637,7 +640,10 @@
638641 * Free a result object
639642 * @param $res Mixed: A SQL result
640643 */
641 - abstract function freeResult( $res );
 644+ function freeResult( $res ) {
 645+ # Stub. Might not really need to be overridden, since results should
 646+ # be freed by PHP when the variable goes out of scope anyway.
 647+ }
642648
643649 /**
644650 * Fetch the next row from the given result object, in object form.
@@ -1252,8 +1258,16 @@
12531259
12541260 /**
12551261 * Change the current database
 1262+ *
 1263+ * @return bool Success or failure
12561264 */
1257 - abstract function selectDB( $db );
 1265+ function selectDB( $db ) {
 1266+ # Stub. Shouldn't cause serious problems if it's not overridden, but
 1267+ # if your database engine supports a concept similar to MySQL's
 1268+ # databases you may as well. TODO: explain what exactly will fail if
 1269+ # this is not overridden.
 1270+ return true;
 1271+ }
12581272
12591273 /**
12601274 * Get the current DB name
@@ -1921,8 +1935,13 @@
19221936
19231937 /**
19241938 * Ping the server and try to reconnect if it there is no connection
 1939+ *
 1940+ * @return bool Success or failure
19251941 */
1926 - abstract function ping();
 1942+ function ping() {
 1943+ # Stub. Not essential to override.
 1944+ return true;
 1945+ }
19271946
19281947 /**
19291948 * Get slave lag.
Index: trunk/phase3/includes/db/DatabaseMssql.php
@@ -935,11 +935,6 @@
936936 */
937937 public function setTimeout($timeout) { return; }
938938
939 - function ping() {
940 - wfDebug("Function ping() not written for MSSQL yet");
941 - return true;
942 - }
943 -
944939 /**
945940 * How lagged is this slave?
946941 */
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -390,29 +390,11 @@
391391 function quote_ident($s) { return $s; }
392392
393393 /**
394 - * Not possible in SQLite
395 - * We have ATTACH_DATABASE but that requires database selectors before the
396 - * table names and in any case is really a different concept to MySQL's USE
397 - */
398 - function selectDB($db) {
399 - if ( $db != $this->mName ) {
400 - throw new MWException( 'selectDB is not implemented in SQLite' );
401 - }
402 - }
403 -
404 - /**
405394 * not done
406395 */
407396 public function setTimeout($timeout) { return; }
408397
409398 /**
410 - * No-op for a non-networked database
411 - */
412 - function ping() {
413 - return true;
414 - }
415 -
416 - /**
417399 * How lagged is this slave?
418400 */
419401 public function getLag() {

Past revisions this follows-up on

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

Status & tagging log