From eda48c749ac5118b32f09fa01e057a81b24bec36 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 15 Nov 2021 12:41:37 +0100 Subject: [PATCH] Allow NULL as well for limit, not integer only Signed-off-by: Joas Schilling --- lib/private/DB/Connection.php | 11 ++++++++--- lib/private/DB/QueryBuilder/QueryBuilder.php | 12 ++++++++---- lib/public/DB/QueryBuilder/IQueryBuilder.php | 4 ++-- lib/public/IDBConnection.php | 4 ++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index cb7af4d51e29b..92f89dab5d2d9 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -184,15 +184,20 @@ public function __construct(array $params, Driver $driver, Configuration $config * Prepares an SQL statement. * * @param string $statement The SQL statement to prepare. - * @param int $limit - * @param int $offset + * @param int|null $limit + * @param int|null $offset * * @return Statement The prepared statement. * @throws Exception */ public function prepare($statement, $limit = null, $offset = null): Statement { - if ($limit === -1) { + if ($limit === -1 || $limit === null) { $limit = null; + } else { + $limit = (int) $limit; + } + if ($offset !== null) { + $offset = (int) $offset; } if (!is_null($limit)) { $platform = $this->getDatabasePlatform(); diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index 352829a56ae79..0a9590aa3d989 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -398,12 +398,12 @@ public function getParameterType($key) { /** * Sets the position of the first result to retrieve (the "offset"). * - * @param integer $firstResult The first result to return. + * @param int $firstResult The first result to return. * * @return $this This QueryBuilder instance. */ public function setFirstResult($firstResult) { - $this->queryBuilder->setFirstResult($firstResult); + $this->queryBuilder->setFirstResult((int) $firstResult); return $this; } @@ -425,12 +425,16 @@ public function getFirstResult() { * of the databases will just return an empty result set, Oracle will return * all entries. * - * @param integer $maxResults The maximum number of results to retrieve. + * @param int|null $maxResults The maximum number of results to retrieve. * * @return $this This QueryBuilder instance. */ public function setMaxResults($maxResults) { - $this->queryBuilder->setMaxResults($maxResults); + if ($maxResults === null) { + $this->queryBuilder->setMaxResults($maxResults); + } else { + $this->queryBuilder->setMaxResults((int) $maxResults); + } return $this; } diff --git a/lib/public/DB/QueryBuilder/IQueryBuilder.php b/lib/public/DB/QueryBuilder/IQueryBuilder.php index 269203ce152f9..fcba00b92b38f 100644 --- a/lib/public/DB/QueryBuilder/IQueryBuilder.php +++ b/lib/public/DB/QueryBuilder/IQueryBuilder.php @@ -256,7 +256,7 @@ public function getParameterType($key); /** * Sets the position of the first result to retrieve (the "offset"). * - * @param integer $firstResult The first result to return. + * @param int $firstResult The first result to return. * * @return $this This QueryBuilder instance. * @since 8.2.0 @@ -275,7 +275,7 @@ public function getFirstResult(); /** * Sets the maximum number of results to retrieve (the "limit"). * - * @param integer $maxResults The maximum number of results to retrieve. + * @param int|null $maxResults The maximum number of results to retrieve. * * @return $this This QueryBuilder instance. * @since 8.2.0 diff --git a/lib/public/IDBConnection.php b/lib/public/IDBConnection.php index 5618e3ec40b7a..8761a7e3baacc 100644 --- a/lib/public/IDBConnection.php +++ b/lib/public/IDBConnection.php @@ -69,8 +69,8 @@ public function getQueryBuilder(); /** * Used to abstract the ownCloud database access away * @param string $sql the sql query with ? placeholder for params - * @param int $limit the maximum number of rows - * @param int $offset from which row we want to start + * @param int|null $limit the maximum number of rows + * @param int|null $offset from which row we want to start * @return IPreparedStatement The prepared statement. * @since 6.0.0 * @throws Exception since 21.0.0