From: Aaron Schulz Date: Thu, 11 Apr 2019 04:37:06 +0000 (-0700) Subject: rdbms: add limitResults() to IDatabase X-Git-Tag: 1.34.0-rc.0~2044^2 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=993cb724a362784eab10d920bde074906aee7b8a;p=lhc%2Fweb%2Fwiklou.git rdbms: add limitResults() to IDatabase Change-Id: Iec39db0b34a48cce0367fb91acb234a81715d145 --- diff --git a/includes/libs/rdbms/database/DBConnRef.php b/includes/libs/rdbms/database/DBConnRef.php index f3ab1c5842..a06ce76fa5 100644 --- a/includes/libs/rdbms/database/DBConnRef.php +++ b/includes/libs/rdbms/database/DBConnRef.php @@ -46,8 +46,8 @@ class DBConnRef implements IDatabase { function __call( $name, array $arguments ) { if ( $this->conn === null ) { - list( $db, $groups, $wiki, $flags ) = $this->params; - $this->conn = $this->lb->getConnection( $db, $groups, $wiki, $flags ); + list( $index, $groups, $wiki, $flags ) = $this->params; + $this->conn = $this->lb->getConnection( $index, $groups, $wiki, $flags ); } return $this->conn->$name( ...$arguments ); @@ -304,6 +304,10 @@ class DBConnRef implements IDatabase { return $this->__call( __FUNCTION__, func_get_args() ); } + public function limitResult( $sql, $limit, $offset = false ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } + public function selectRow( $table, $vars, $conds, $fname = __METHOD__, $options = [], $join_conds = [] diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index ba97887f71..beca66363b 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -3191,34 +3191,16 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $this->query( $sql, $fname ); } - /** - * Construct a LIMIT query with optional offset. This is used for query - * pages. The SQL should be adjusted so that only the first $limit rows - * are returned. If $offset is provided as well, then the first $offset - * rows should be discarded, and the next $limit rows should be returned. - * If the result of the query is not ordered, then the rows to be returned - * are theoretically arbitrary. - * - * $sql is expected to be a SELECT, if that makes a difference. - * - * The version provided by default works in MySQL and SQLite. It will very - * likely need to be overridden for most other DBMSes. - * - * @param string $sql SQL query we will append the limit too - * @param int $limit The SQL limit - * @param int|bool $offset The SQL offset (default false) - * @throws DBUnexpectedError - * @return string - */ public function limitResult( $sql, $limit, $offset = false ) { if ( !is_numeric( $limit ) ) { throw new DBUnexpectedError( $this, "Invalid non-numeric limit passed to limitResult()\n" ); } - + // This version works in MySQL and SQLite. It will very likely need to be + // overridden for most other RDBMS subclasses. return "$sql LIMIT " - . ( ( is_numeric( $offset ) && $offset != 0 ) ? "{$offset}," : "" ) - . "{$limit} "; + . ( ( is_numeric( $offset ) && $offset != 0 ) ? "{$offset}," : "" ) + . "{$limit} "; } public function unionSupportsOrderAndLimit() { diff --git a/includes/libs/rdbms/database/IDatabase.php b/includes/libs/rdbms/database/IDatabase.php index e25b4d29f7..592c9be29b 100644 --- a/includes/libs/rdbms/database/IDatabase.php +++ b/includes/libs/rdbms/database/IDatabase.php @@ -1112,6 +1112,25 @@ interface IDatabase { $options = [], $join_conds = [] ); + /** + * Construct a LIMIT query with optional offset. This is used for query + * pages. The SQL should be adjusted so that only the first $limit rows + * are returned. If $offset is provided as well, then the first $offset + * rows should be discarded, and the next $limit rows should be returned. + * If the result of the query is not ordered, then the rows to be returned + * are theoretically arbitrary. + * + * $sql is expected to be a SELECT, if that makes a difference. + * + * @param string $sql SQL query we will append the limit too + * @param int $limit The SQL limit + * @param int|bool $offset The SQL offset (default false) + * @throws DBUnexpectedError + * @return string + * @since 1.34 + */ + public function limitResult( $sql, $limit, $offset = false ); + /** * Returns true if DBs are assumed to be on potentially different servers *