New method PreparedStatement::fetchSingleObject()
authorMarcel Werk <burntime@woltlab.com>
Tue, 23 Jun 2020 09:21:59 +0000 (11:21 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 23 Jun 2020 09:21:59 +0000 (11:21 +0200)
Closes #3373

wcfsetup/install/files/lib/system/database/statement/DebugPreparedStatement.class.php
wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php

index 43073a8566fdc3dc9c0e2ca93714db59acf8234a..89e5a43d8b92c5199e1eca0c49696310eb1dd07e 100644 (file)
@@ -69,6 +69,15 @@ class DebugPreparedStatement extends PreparedStatement {
                return parent::fetchObject($className);
        }
        
+       /**
+        * @inheritDoc
+        */
+       public function fetchSingleObject($className) {
+               $this->debugThrowIfNotExecutedBefore();
+               
+               return parent::fetchSingleObject($className);
+       }
+       
        /**
         * @inheritDoc
         */
index a4b0675b12a56c5a53b9651c50787979f8835ea4..37e43df7ae1c2825c39f01e7306080d8d428ee98 100644 (file)
@@ -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.
         *