From: Aaron Schulz Date: Thu, 22 Mar 2018 15:33:59 +0000 (-0700) Subject: rdbms: IDatabase interface cleanups X-Git-Tag: 1.31.0-rc.0~310^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=856c6769cd9502a0872c0f8db74ec0c43025ca27 rdbms: IDatabase interface cleanups * Move schema-change related methods listTables(), indexUnique(), and fieldInfo() to IMaintainableDatabase * Deprecate doneWrites() * Remove reportQueryError() and reportConnectionError(), leaving them to Database Bug: T190396 Change-Id: I96f298d5a6eca67f5a289f205406bf3135ece62d --- diff --git a/includes/libs/rdbms/database/DBConnRef.php b/includes/libs/rdbms/database/DBConnRef.php index c0855dfc2a..f6837305b7 100644 --- a/includes/libs/rdbms/database/DBConnRef.php +++ b/includes/libs/rdbms/database/DBConnRef.php @@ -211,10 +211,6 @@ class DBConnRef implements IDatabase { return $this->__call( __FUNCTION__, func_get_args() ); } - public function fieldInfo( $table, $field ) { - return $this->__call( __FUNCTION__, func_get_args() ); - } - public function affectedRows() { return $this->__call( __FUNCTION__, func_get_args() ); } @@ -231,18 +227,10 @@ class DBConnRef implements IDatabase { return $this->__call( __FUNCTION__, func_get_args() ); } - public function reportConnectionError( $error = 'Unknown error' ) { - return $this->__call( __FUNCTION__, func_get_args() ); - } - public function query( $sql, $fname = __METHOD__, $tempIgnore = false ) { return $this->__call( __FUNCTION__, func_get_args() ); } - public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) { - return $this->__call( __FUNCTION__, func_get_args() ); - } - public function freeResult( $res ) { return $this->__call( __FUNCTION__, func_get_args() ); } @@ -304,10 +292,6 @@ class DBConnRef implements IDatabase { return $this->__call( __FUNCTION__, func_get_args() ); } - public function indexUnique( $table, $index ) { - return $this->__call( __FUNCTION__, func_get_args() ); - } - public function insert( $table, $a, $fname = __METHOD__, $options = [] ) { return $this->__call( __FUNCTION__, func_get_args() ); } @@ -543,10 +527,6 @@ class DBConnRef implements IDatabase { return $this->__call( __FUNCTION__, func_get_args() ); } - public function listTables( $prefix = null, $fname = __METHOD__ ) { - return $this->__call( __FUNCTION__, func_get_args() ); - } - public function timestamp( $ts = 0 ) { return $this->__call( __FUNCTION__, func_get_args() ); } diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index c3e36dabda..f8b5e42b52 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -912,6 +912,10 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware */ abstract protected function closeConnection(); + /** + * @param string $error Fallback error message, used if none is given by DB + * @throws DBConnectionError + */ public function reportConnectionError( $error = 'Unknown error' ) { $myError = $this->lastError(); if ( $myError ) { @@ -1287,6 +1291,17 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware return false; } + /** + * Report a query error. Log the error, and if neither the object ignore + * flag nor the $tempIgnore flag is set, throw a DBQueryError. + * + * @param string $error + * @param int $errno + * @param string $sql + * @param string $fname + * @param bool $tempIgnore + * @throws DBQueryError + */ public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) { if ( $this->ignoreErrors() || $tempIgnore ) { $this->queryLogger->debug( "SQL ERROR (ignored): $error\n" ); diff --git a/includes/libs/rdbms/database/IDatabase.php b/includes/libs/rdbms/database/IDatabase.php index 47954b6e9e..447c13e17d 100644 --- a/includes/libs/rdbms/database/IDatabase.php +++ b/includes/libs/rdbms/database/IDatabase.php @@ -228,6 +228,7 @@ interface IDatabase { * Should return true if unsure. * * @return bool + * @deprecated Since 1.31; use lastDoneWrites() */ public function doneWrites(); @@ -454,17 +455,6 @@ interface IDatabase { */ public function lastError(); - /** - * mysql_fetch_field() wrapper - * Returns false if the field doesn't exist - * - * @param string $table Table name - * @param string $field Field name - * - * @return Field - */ - public function fieldInfo( $table, $field ); - /** * Get the number of rows affected by the last write query * @see https://secure.php.net/mysql_affected_rows @@ -503,12 +493,6 @@ interface IDatabase { */ public function close(); - /** - * @param string $error Fallback error message, used if none is given by DB - * @throws DBConnectionError - */ - public function reportConnectionError( $error = 'Unknown error' ); - /** * Run an SQL query and return the result. Normally throws a DBQueryError * on failure. If errors are ignored, returns false instead. @@ -537,19 +521,6 @@ interface IDatabase { */ public function query( $sql, $fname = __METHOD__, $tempIgnore = false ); - /** - * Report a query error. Log the error, and if neither the object ignore - * flag nor the $tempIgnore flag is set, throw a DBQueryError. - * - * @param string $error - * @param int $errno - * @param string $sql - * @param string $fname - * @param bool $tempIgnore - * @throws DBQueryError - */ - public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ); - /** * Free a result object returned by query() or select(). It's usually not * necessary to call this, just use unset() or let the variable holding @@ -898,16 +869,6 @@ interface IDatabase { */ public function tableExists( $table, $fname = __METHOD__ ); - /** - * Determines if a given index is unique - * - * @param string $table - * @param string $index - * - * @return bool - */ - public function indexUnique( $table, $index ); - /** * INSERT wrapper, inserts an array into a table. * @@ -1745,16 +1706,6 @@ interface IDatabase { */ public function flushSnapshot( $fname = __METHOD__ ); - /** - * List all tables on the database - * - * @param string $prefix Only show tables with this prefix, e.g. mw_ - * @param string $fname Calling function name - * @throws DBError - * @return array - */ - public function listTables( $prefix = null, $fname = __METHOD__ ); - /** * Convert a timestamp in one of the formats accepted by wfTimestamp() * to the format used for inserting into timestamp fields in this DBMS. diff --git a/includes/libs/rdbms/database/IMaintainableDatabase.php b/includes/libs/rdbms/database/IMaintainableDatabase.php index d0c398e3e8..18e3cbbc46 100644 --- a/includes/libs/rdbms/database/IMaintainableDatabase.php +++ b/includes/libs/rdbms/database/IMaintainableDatabase.php @@ -275,6 +275,37 @@ interface IMaintainableDatabase extends IDatabase { * @since 1.29 */ public function unlockTables( $method ); + + /** + * List all tables on the database + * + * @param string $prefix Only show tables with this prefix, e.g. mw_ + * @param string $fname Calling function name + * @throws DBError + * @return array + */ + public function listTables( $prefix = null, $fname = __METHOD__ ); + + /** + * Determines if a given index is unique + * + * @param string $table + * @param string $index + * + * @return bool + */ + public function indexUnique( $table, $index ); + + /** + * mysql_fetch_field() wrapper + * Returns false if the field doesn't exist + * + * @param string $table Table name + * @param string $field Field name + * + * @return Field + */ + public function fieldInfo( $table, $field ); } class_alias( IMaintainableDatabase::class, 'IMaintainableDatabase' ); diff --git a/includes/libs/rdbms/database/MaintainableDBConnRef.php b/includes/libs/rdbms/database/MaintainableDBConnRef.php index 6c94eb9a34..ff4b050967 100644 --- a/includes/libs/rdbms/database/MaintainableDBConnRef.php +++ b/includes/libs/rdbms/database/MaintainableDBConnRef.php @@ -80,6 +80,18 @@ class MaintainableDBConnRef extends DBConnRef implements IMaintainableDatabase { public function unlockTables( $method ) { return $this->__call( __FUNCTION__, func_get_args() ); } + + public function indexUnique( $table, $index ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } + + public function listTables( $prefix = null, $fname = __METHOD__ ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } + + public function fieldInfo( $table, $field ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } } class_alias( MaintainableDBConnRef::class, 'MaintainableDBConnRef' );