From: Aryeh Gregor Date: Tue, 16 Jun 2009 20:22:11 +0000 (+0000) Subject: Make some Database methods optional to override X-Git-Tag: 1.31.0-rc.0~41343 X-Git-Url: http://git.cyclocoop.org/data/%24self?a=commitdiff_plain;h=2b83b919062a785211948deba0acefdd75f59119;p=lhc%2Fweb%2Fwiklou.git 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. --- diff --git a/includes/db/Database.php b/includes/db/Database.php index 86ff1fc541..622f5df205 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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. diff --git a/includes/db/DatabaseIbm_db2.php b/includes/db/DatabaseIbm_db2.php index 7fdfd3aa8a..382b5e2c4d 100644 --- a/includes/db/DatabaseIbm_db2.php +++ b/includes/db/DatabaseIbm_db2.php @@ -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 diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index 66f67576e7..b470690d6e 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -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? */ diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index c2df310938..66ffe3de97 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -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? * diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index d477834619..6a99fd5775 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -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? * diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 5907b46a1a..1678633daf 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -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? */