Make some Database methods optional to override
authorAryeh Gregor <simetrical@users.mediawiki.org>
Tue, 16 Jun 2009 20:22:11 +0000 (20:22 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Tue, 16 Jun 2009 20:22:11 +0000 (20:22 +0000)
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.

includes/db/Database.php
includes/db/DatabaseIbm_db2.php
includes/db/DatabaseMssql.php
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php
includes/db/DatabaseSqlite.php

index 86ff1fc..622f5df 100644 (file)
@@ -360,7 +360,10 @@ abstract class DatabaseBase {
         *
         * @return Bool operation success. true if already closed.
         */
-       abstract function close();
+       function close() {
+               # Stub, should probably be overridden
+               return true;
+       }
 
        /**
         * @param $error String: fallback error message, used if none is given by MySQL
@@ -637,7 +640,10 @@ abstract class DatabaseBase {
         * Free a result object
         * @param $res Mixed: A SQL result
         */
-       abstract function freeResult( $res );
+       function freeResult( $res ) {
+               # Stub.  Might not really need to be overridden, since results should
+               # be freed by PHP when the variable goes out of scope anyway.
+       }
 
        /**
         * Fetch the next row from the given result object, in object form.
@@ -1252,8 +1258,16 @@ abstract class DatabaseBase {
 
        /**
         * Change the current database
+        *
+        * @return bool Success or failure
         */
-       abstract function selectDB( $db );
+       function selectDB( $db ) {
+               # Stub.  Shouldn't cause serious problems if it's not overridden, but
+               # if your database engine supports a concept similar to MySQL's
+               # databases you may as well.  TODO: explain what exactly will fail if
+               # this is not overridden.
+               return true;
+       }
 
        /**
         * Get the current DB name
@@ -1921,8 +1935,13 @@ abstract class DatabaseBase {
 
        /**
         * Ping the server and try to reconnect if it there is no connection
+        *
+        * @return bool Success or failure
         */
-       abstract function ping();
+       function ping() {
+               # Stub.  Not essential to override.
+               return true;
+       }
 
        /**
         * Get slave lag.
index 7fdfd3a..382b5e2 100644 (file)
@@ -1462,15 +1462,6 @@ EOF;
                return "[http://www.ibm.com/software/data/db2/express/?s_cmp=ECDDWW01&s_tact=MediaWiki IBM DB2]";
        }
        
-       /**
-        * Does nothing
-        * @param object $db
-        * @return bool true
-        */
-       public function selectDB( $db ) {
-               return true;
-       }
-       
        /**
         * Returns an SQL expression for a simple conditional.
         * Uses CASE on DB2
index 66f6757..b470690 100644 (file)
@@ -935,11 +935,6 @@ class DatabaseMssql extends DatabaseBase {
         */
        public function setTimeout($timeout) { return; }
 
-       function ping() {
-               wfDebug("Function ping() not written for MSSQL yet");
-               return true;
-       }
-
        /**
         * How lagged is this slave?
         */
index c2df310..66ffe3d 100644 (file)
@@ -950,11 +950,6 @@ class DatabaseOracle extends DatabaseBase {
                return $s;
        }
 
-       /* For now, does nothing */
-       function selectDB( $db ) {
-               return true;
-       }
-
        function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) {
                if (is_array($table)) 
                        foreach ($table as $tab)
@@ -1052,11 +1047,6 @@ class DatabaseOracle extends DatabaseBase {
                // @todo fixme no-op
        }
 
-       function ping() {
-               wfDebug( "Function ping() not written for DatabaseOracle.php yet");
-               return true;
-       }
-
        /**
         * How lagged is this slave?
         *
index d477834..6a99fd5 100644 (file)
@@ -1324,11 +1324,6 @@ END;
                return '"' . preg_replace( '/"/', '""', $s) . '"';
        }
 
-       /* For now, does nothing */
-       function selectDB( $db ) {
-               return true;
-       }
-
        /**
         * Postgres specific version of replaceVars.
         * Calls the parent version in Database.php
@@ -1396,11 +1391,6 @@ END;
                // @todo fixme no-op
        }
 
-       function ping() {
-               wfDebug( "Function ping() not written for DatabasePostgres.php yet");
-               return true;
-       }
-
        /**
         * How lagged is this slave?
         *
index 5907b46..1678633 100644 (file)
@@ -389,29 +389,11 @@ class DatabaseSqlite extends DatabaseBase {
 
        function quote_ident($s) { return $s; }
 
-       /**
-        * Not possible in SQLite
-        * We have ATTACH_DATABASE but that requires database selectors before the 
-        * table names and in any case is really a different concept to MySQL's USE
-        */
-       function selectDB($db) {
-               if ( $db != $this->mName ) {
-                       throw new MWException( 'selectDB is not implemented in SQLite' );
-               }
-       }
-
        /**
         * not done
         */
        public function setTimeout($timeout) { return; }
 
-       /**
-        * No-op for a non-networked database
-        */
-       function ping() {
-               return true;
-       }
-
        /**
         * How lagged is this slave?
         */