From dbad19adc92315b671fe9d76dafdeb3d9e84ca47 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 26 Aug 2010 23:10:11 +0000 Subject: [PATCH] Move all abstract stuff that DatabaseBase children must implement to new interface DatabaseType. Puts all of the 'must implement' things in one place. Also lets me use abstract statics, as a workaround for r71441 --- includes/AutoLoader.php | 1 + includes/db/Database.php | 142 +---------------------------- includes/db/DatabaseType.php | 168 +++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+), 141 deletions(-) create mode 100644 includes/db/DatabaseType.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 97fbeda5df..d3cec5d39f 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -358,6 +358,7 @@ $wgAutoloadLocalClasses = array( 'DatabasePostgres' => 'includes/db/DatabasePostgres.php', 'DatabaseSqlite' => 'includes/db/DatabaseSqlite.php', 'DatabaseSqliteStandalone' => 'includes/db/DatabaseSqlite.php', + 'DatabaseType' => 'includes/db/DatabaseType.php', 'DBConnectionError' => 'includes/db/Database.php', 'DBError' => 'includes/db/Database.php', 'DBObject' => 'includes/db/Database.php', diff --git a/includes/db/Database.php b/includes/db/Database.php index 0dffcdb09a..0fd4ea374e 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -19,7 +19,7 @@ define( 'DEADLOCK_DELAY_MAX', 1500000 ); * Database abstraction object * @ingroup Database */ -abstract class DatabaseBase { +abstract class DatabaseBase implements DatabaseType { #------------------------------------------------------------------------------ # Variables @@ -276,11 +276,6 @@ abstract class DatabaseBase { } } - /** - * Get the type of the DBMS, as it appears in $wgDBtype. - */ - abstract function getType(); - #------------------------------------------------------------------------------ # Other functions #------------------------------------------------------------------------------ @@ -349,16 +344,6 @@ abstract class DatabaseBase { return new DatabaseMysql( $server, $user, $password, $dbName, $failFunction, $flags ); } - /** - * Usually aborts on failure - * If the failFunction is set to a non-zero integer, returns success - * @param $server String: database server host - * @param $user String: database user name - * @param $password String: database user password - * @param $dbName String: database name - */ - abstract function open( $server, $user, $password, $dbName ); - protected function installErrorHandler() { $this->mPHPError = false; $this->htmlErrors = ini_set( 'html_errors', '0' ); @@ -540,14 +525,6 @@ abstract class DatabaseBase { return $this->resultObject( $ret ); } - /** - * The DBMS-dependent part of query() - * @param $sql String: SQL query. - * @return Result object to feed to fetchObject, fetchRow, ...; or false on failure - * @private - */ - /*private*/ abstract function doQuery( $sql ); - /** * @param $error String * @param $errno Integer @@ -675,87 +652,6 @@ abstract class DatabaseBase { # be freed by PHP when the variable goes out of scope anyway. } - /** - * Fetch the next row from the given result object, in object form. - * Fields can be retrieved with $row->fieldname, with fields acting like - * member variables. - * - * @param $res SQL result object as returned from DatabaseBase::query(), etc. - * @return Row object - * @throws DBUnexpectedError Thrown if the database returns an error - */ - abstract function fetchObject( $res ); - - /** - * Fetch the next row from the given result object, in associative array - * form. Fields are retrieved with $row['fieldname']. - * - * @param $res SQL result object as returned from DatabaseBase::query(), etc. - * @return Row object - * @throws DBUnexpectedError Thrown if the database returns an error - */ - abstract function fetchRow( $res ); - - /** - * Get the number of rows in a result object - * @param $res Mixed: A SQL result - */ - abstract function numRows( $res ); - - /** - * Get the number of fields in a result object - * See documentation for mysql_num_fields() - * @param $res Mixed: A SQL result - */ - abstract function numFields( $res ); - - /** - * Get a field name in a result object - * See documentation for mysql_field_name(): - * http://www.php.net/mysql_field_name - * @param $res Mixed: A SQL result - * @param $n Integer - */ - abstract function fieldName( $res, $n ); - - /** - * Get the inserted value of an auto-increment row - * - * The value inserted should be fetched from nextSequenceValue() - * - * Example: - * $id = $dbw->nextSequenceValue('page_page_id_seq'); - * $dbw->insert('page',array('page_id' => $id)); - * $id = $dbw->insertId(); - */ - abstract function insertId(); - - /** - * Change the position of the cursor in a result object - * See mysql_data_seek() - * @param $res Mixed: A SQL result - * @param $row Mixed: Either MySQL row or ResultWrapper - */ - abstract function dataSeek( $res, $row ); - - /** - * Get the last error number - * See mysql_errno() - */ - abstract function lastErrno(); - - /** - * Get a description of the last error - * See mysql_error() for more details - */ - abstract function lastError(); - - /** - * Get the number of rows affected by the last write query - * See mysql_affected_rows() for more details - */ - abstract function affectedRows(); - /** * Simple UPDATE wrapper * Usually aborts on failure @@ -1067,15 +963,6 @@ abstract class DatabaseBase { return (bool)$res; } - /** - * mysql_fetch_field() wrapper - * Returns false if the field doesn't exist - * - * @param $table - * @param $field - */ - abstract function fieldInfo( $table, $field ); - /** * mysql_field_type() wrapper */ @@ -1554,13 +1441,6 @@ abstract class DatabaseBase { } } - /** - * Wrapper for addslashes() - * @param $s String: to be slashed. - * @return String: slashed string. - */ - abstract function strencode( $s ); - /** * If it's a string, adds quotes and backslashes * Otherwise returns as-is @@ -2149,26 +2029,6 @@ abstract class DatabaseBase { return $valuename; } - /** - * Returns a wikitext link to the DB's website, e.g., - * return "[http://www.mysql.com/ MySQL]"; - * Should at least contain plain text, if for some reason - * your database has no website. - * - * @return String: wikitext of a link to the server software's web site - */ - public static function getSoftwareLink() { - throw new MWException( "A child class of DatabaseBase didn't implement getSoftwareLink(), shame on them" ); - } - - /** - * A string describing the current software version, like from - * mysql_get_server_info(). Will be listed on Special:Version, etc. - * - * @return String: Version information from the database - */ - abstract function getServerVersion(); - /** * Ping the server and try to reconnect if it there is no connection * diff --git a/includes/db/DatabaseType.php b/includes/db/DatabaseType.php new file mode 100644 index 0000000000..2ad60bff2b --- /dev/null +++ b/includes/db/DatabaseType.php @@ -0,0 +1,168 @@ +fieldname, with fields acting like + * member variables. + * + * @param $res SQL result object as returned from DatabaseBase::query(), etc. + * @return Row object + * @throws DBUnexpectedError Thrown if the database returns an error + */ + public function fetchObject( $res ); + + /** + * Fetch the next row from the given result object, in associative array + * form. Fields are retrieved with $row['fieldname']. + * + * @param $res SQL result object as returned from DatabaseBase::query(), etc. + * @return Row object + * @throws DBUnexpectedError Thrown if the database returns an error + */ + public function fetchRow( $res ); + + /** + * Get the number of rows in a result object + * + * @param $res Mixed: A SQL result + * @return int + */ + public function numRows( $res ); + + /** + * Get the number of fields in a result object + * @see http://www.php.net/mysql_num_fields + * + * @param $res Mixed: A SQL result + * @return int + */ + public function numFields( $res ); + + /** + * Get a field name in a result object + * @see http://www.php.net/mysql_field_name + * + * @param $res Mixed: A SQL result + * @param $n Integer + * @return string + */ + public function fieldName( $res, $n ); + + /** + * Get the inserted value of an auto-increment row + * + * The value inserted should be fetched from nextSequenceValue() + * + * Example: + * $id = $dbw->nextSequenceValue('page_page_id_seq'); + * $dbw->insert('page',array('page_id' => $id)); + * $id = $dbw->insertId(); + * + * @return int + */ + public function insertId(); + + /** + * Change the position of the cursor in a result object + * @see http://www.php.net/mysql_data_seek + * + * @param $res Mixed: A SQL result + * @param $row Mixed: Either MySQL row or ResultWrapper + */ + public function dataSeek( $res, $row ); + + /** + * Get the last error number + * @see http://www.php.net/mysql_errno + * + * @return int + */ + public function lastErrno(); + + /** + * Get a description of the last error + * @see http://www.php.net/mysql_error + * + * @return string + */ + public function lastError(); + + /** + * mysql_fetch_field() wrapper + * Returns false if the field doesn't exist + * + * @param $table string: table name + * @param $field string: field name + */ + public function fieldInfo( $table, $field ); + + /** + * Get the number of rows affected by the last write query + * @see http://www.php.net/mysql_affected_rows + * + * @return int + */ + public function affectedRows(); + + /** + * Wrapper for addslashes() + * + * @param $s string: to be slashed. + * @return string: slashed string. + */ + public function strencode( $s ); + + /** + * Returns a wikitext link to the DB's website, e.g., + * return "[http://www.mysql.com/ MySQL]"; + * Should at least contain plain text, if for some reason + * your database has no website. + * + * @return string: wikitext of a link to the server software's web site + */ + public static function getSoftwareLink(); + + /** + * A string describing the current software version, like from + * mysql_get_server_info(). Will be listed on Special:Version, etc. + * + * @return string: Version information from the database + */ + public function getServerVersion(); +} -- 2.20.1