From: Marcel Werk Date: Tue, 23 Jun 2020 09:21:59 +0000 (+0200) Subject: New method PreparedStatement::fetchSingleObject() X-Git-Tag: 5.3.0_Alpha_1~207 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b80d77bcd5ae98f7c615825988292164238b98ea;p=GitHub%2FWoltLab%2FWCF.git New method PreparedStatement::fetchSingleObject() Closes #3373 --- 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. *