From b80d77bcd5ae98f7c615825988292164238b98ea Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 23 Jun 2020 11:21:59 +0200 Subject: [PATCH] New method PreparedStatement::fetchSingleObject() Closes #3373 --- .../DebugPreparedStatement.class.php | 9 +++++++++ .../statement/PreparedStatement.class.php | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/wcfsetup/install/files/lib/system/database/statement/DebugPreparedStatement.class.php b/wcfsetup/install/files/lib/system/database/statement/DebugPreparedStatement.class.php index 43073a8566..89e5a43d8b 100644 --- a/wcfsetup/install/files/lib/system/database/statement/DebugPreparedStatement.class.php +++ b/wcfsetup/install/files/lib/system/database/statement/DebugPreparedStatement.class.php @@ -69,6 +69,15 @@ class DebugPreparedStatement extends PreparedStatement { return parent::fetchObject($className); } + /** + * @inheritDoc + */ + public function fetchSingleObject($className) { + $this->debugThrowIfNotExecutedBefore(); + + return parent::fetchSingleObject($className); + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php index a4b0675b12..37e43df7ae 100644 --- a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php +++ b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php @@ -170,6 +170,26 @@ class PreparedStatement { return null; } + /** + * Fetches the next row from a result set in a database object. + * Closes the 'cursor' afterwards to free up the connection + * for new queries. + * Note: It is not possible to fetch further rows after calling + * this method! + * + * @param string $className + * @return DatabaseObject|null + * @since 5.3 + */ + public function fetchSingleObject($className) { + $row = $this->fetchSingleRow(); + if ($row !== false) { + return new $className(null, $row); + } + + return null; + } + /** * Fetches the all rows from a result set into database objects. * -- 2.20.1