rdbms: clean up and refactor ResultWrapper classes
[lhc/web/wiklou.git] / includes / libs / rdbms / database / resultwrapper / ResultWrapper.php
index a9befc2..b7938ad 100644 (file)
@@ -30,8 +30,8 @@ class ResultWrapper implements IResultWrapper {
 
        /** @var int */
        protected $pos = 0;
-       /** @var stdClass|null */
-       protected $currentRow = null;
+       /** @var stdClass|bool|null */
+       protected $currentRow;
 
        /**
         * Create a row iterator from a result resource and an optional Database object
@@ -63,29 +63,16 @@ class ResultWrapper implements IResultWrapper {
                return $this->getDB()->fetchRow( $this );
        }
 
-       public function seek( $row ) {
-               $this->getDB()->dataSeek( $this, $row );
+       public function seek( $pos ) {
+               $this->getDB()->dataSeek( $this, $pos );
+               $this->pos = $pos;
        }
 
        public function free() {
-               if ( $this->db ) {
-                       $this->db = null;
-               }
+               $this->db = null;
                $this->result = null;
        }
 
-       /**
-        * @return IDatabase
-        * @throws RuntimeException
-        */
-       private function getDB() {
-               if ( !$this->db ) {
-                       throw new RuntimeException( static::class . ' needs a DB handle for iteration.' );
-               }
-
-               return $this->db;
-       }
-
        function rewind() {
                if ( $this->numRows() ) {
                        $this->getDB()->dataSeek( $this, 0 );
@@ -95,8 +82,8 @@ class ResultWrapper implements IResultWrapper {
        }
 
        function current() {
-               if ( is_null( $this->currentRow ) ) {
-                       $this->next();
+               if ( $this->currentRow === null ) {
+                       $this->currentRow = $this->fetchObject();
                }
 
                return $this->currentRow;
@@ -116,6 +103,18 @@ class ResultWrapper implements IResultWrapper {
        function valid() {
                return $this->current() !== false;
        }
+
+       /**
+        * @return IDatabase
+        * @throws RuntimeException
+        */
+       private function getDB() {
+               if ( !$this->db ) {
+                       throw new RuntimeException( static::class . ' needs a DB handle for iteration.' );
+               }
+
+               return $this->db;
+       }
 }
 
 /**