MediaWiki master
Wikimedia\Rdbms\ResultWrapper Class Reference

Result wrapper for grabbing data queried from an IDatabase object. More...

Inherits Wikimedia\Rdbms\IResultWrapper.

Inherited by Wikimedia\Rdbms\FakeResultWrapper, Wikimedia\Rdbms\MysqliResultWrapper, Wikimedia\Rdbms\PostgresResultWrapper, and Wikimedia\Rdbms\SqliteResultWrapper.

Collaboration diagram for Wikimedia\Rdbms\ResultWrapper:

Public Member Functions

 count ()
 Get the number of rows in a result object.
 
 current ()
 
 fetchObject ()
 Fetch the next row from the given result object, in object form.
 
 fetchRow ()
 Fetch the next row from the given result object, in associative array form.
 
 free ()
 Free a result object.
 
 getFieldNames ()
 Get the names of the fields in the result.
 
 key ()
 
 next ()
 
 numRows ()
 Get the number of rows in a result object.
 
 rewind ()
 
 seek ( $pos)
 Change the position of the cursor in a result object.
 
 valid ()
 

Protected Member Functions

 doFetchObject ()
 Get the next row as a stdClass object, or false if iteration has proceeded past the end.
 
 doFetchRow ()
 Get the next row as an array containing the data duplicated, once with string keys and once with numeric keys, per the PDO::FETCH_BOTH convention.
 
 doFree ()
 Free underlying data.
 
 doGetFieldNames ()
 Get the field names in the result set.
 
 doNumRows ()
 Get the number of rows in the result set.
 
 doSeek ( $pos)
 Modify the current cursor position to the row with the specified offset.
 

Protected Attributes

int $currentPos = 0
 The offset of the current row that would be returned by current() and may have been previously returned by fetchObject().
 
stdClass array bool null $currentRow
 The row at $this->currentPos, or null if it has not yet been retrieved, or false if the current row was past the end.
 
int $nextPos = 0
 The offset of the row that would be returned by the next call to fetchObject().
 

Detailed Description

Result wrapper for grabbing data queried from an IDatabase object.

Only IDatabase-related classes should construct these. Other code may use the FakeResultWrapper class for convenience or compatibility shims.

Note that using the Iterator methods in combination with the non-Iterator IDatabase result iteration functions may cause rows to be skipped or repeated.

By default, this will use the iteration methods of the IDatabase handle if provided. Subclasses can override methods to make it solely work on the result resource instead.

Definition at line 22 of file ResultWrapper.php.

Member Function Documentation

◆ count()

Wikimedia\Rdbms\ResultWrapper::count ( )

Get the number of rows in a result object.

Returns
int

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 97 of file ResultWrapper.php.

Referenced by Wikimedia\Rdbms\FakeResultWrapper\doNumRows(), and Wikimedia\Rdbms\SqliteResultWrapper\doNumRows().

◆ current()

Wikimedia\Rdbms\ResultWrapper::current ( )
Returns
stdClass|array|false

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 138 of file ResultWrapper.php.

◆ doFetchObject()

Wikimedia\Rdbms\ResultWrapper::doFetchObject ( )
abstractprotected

Get the next row as a stdClass object, or false if iteration has proceeded past the end.

The offset within the result set is in $this->currentPos.

Since
1.37
Returns
stdClass|bool

Reimplemented in Wikimedia\Rdbms\FakeResultWrapper, Wikimedia\Rdbms\MysqliResultWrapper, Wikimedia\Rdbms\PostgresResultWrapper, and Wikimedia\Rdbms\SqliteResultWrapper.

◆ doFetchRow()

Wikimedia\Rdbms\ResultWrapper::doFetchRow ( )
abstractprotected

Get the next row as an array containing the data duplicated, once with string keys and once with numeric keys, per the PDO::FETCH_BOTH convention.

Or false if iteration has proceeded past the end.

Returns
array|bool

Reimplemented in Wikimedia\Rdbms\FakeResultWrapper, Wikimedia\Rdbms\MysqliResultWrapper, Wikimedia\Rdbms\PostgresResultWrapper, and Wikimedia\Rdbms\SqliteResultWrapper.

◆ doFree()

Wikimedia\Rdbms\ResultWrapper::doFree ( )
abstractprotected

◆ doGetFieldNames()

Wikimedia\Rdbms\ResultWrapper::doGetFieldNames ( )
abstractprotected

◆ doNumRows()

Wikimedia\Rdbms\ResultWrapper::doNumRows ( )
abstractprotected

◆ doSeek()

Wikimedia\Rdbms\ResultWrapper::doSeek (   $pos)
abstractprotected

Modify the current cursor position to the row with the specified offset.

If $pos is out of bounds, the behaviour is undefined.

Parameters
int$pos

Reimplemented in Wikimedia\Rdbms\FakeResultWrapper, Wikimedia\Rdbms\MysqliResultWrapper, Wikimedia\Rdbms\PostgresResultWrapper, and Wikimedia\Rdbms\SqliteResultWrapper.

◆ fetchObject()

Wikimedia\Rdbms\ResultWrapper::fetchObject ( )

Fetch the next row from the given result object, in object form.

Fields can be retrieved with $row->fieldname, with fields acting like member variables. If no more rows are available, false is returned.

Returns
stdClass|false
Exceptions
DBUnexpectedErrorThrown if the database returns an error

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 101 of file ResultWrapper.php.

◆ fetchRow()

Wikimedia\Rdbms\ResultWrapper::fetchRow ( )

Fetch the next row from the given result object, in associative array form.

Fields are retrieved with $row['fieldname']. If no more rows are available, false is returned.

Returns
array|false
Exceptions
DBUnexpectedErrorThrown if the database returns an error

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 107 of file ResultWrapper.php.

◆ free()

Wikimedia\Rdbms\ResultWrapper::free ( )

Free a result object.

This either saves memory in PHP (buffered queries) or on the server (unbuffered queries). In general, queries are not large enough in result sets for this to be worth calling.

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 128 of file ResultWrapper.php.

◆ getFieldNames()

Wikimedia\Rdbms\ResultWrapper::getFieldNames ( )

Get the names of the fields in the result.

Since
1.37
Returns
string[]

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 157 of file ResultWrapper.php.

◆ key()

Wikimedia\Rdbms\ResultWrapper::key ( )
Returns
int

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 144 of file ResultWrapper.php.

◆ next()

Wikimedia\Rdbms\ResultWrapper::next ( )
Returns
void

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 148 of file ResultWrapper.php.

◆ numRows()

Wikimedia\Rdbms\ResultWrapper::numRows ( )

Get the number of rows in a result object.

Returns
int

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 93 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\doNumRows().

Referenced by Wikimedia\Rdbms\QueryStatus\__construct().

◆ rewind()

Wikimedia\Rdbms\ResultWrapper::rewind ( )

Definition at line 133 of file ResultWrapper.php.

◆ seek()

Wikimedia\Rdbms\ResultWrapper::seek (   $pos)

Change the position of the cursor in a result object.

See mysql_data_seek()

Exceptions
OutOfBoundsException
Parameters
int$pos

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 113 of file ResultWrapper.php.

◆ valid()

Wikimedia\Rdbms\ResultWrapper::valid ( )

Definition at line 152 of file ResultWrapper.php.

Member Data Documentation

◆ $currentPos

int Wikimedia\Rdbms\ResultWrapper::$currentPos = 0
protected

The offset of the current row that would be returned by current() and may have been previously returned by fetchObject().

Definition at line 33 of file ResultWrapper.php.

Referenced by Wikimedia\Rdbms\FakeResultWrapper\doFetchObject(), and Wikimedia\Rdbms\SqliteResultWrapper\doFetchObject().

◆ $currentRow

stdClass array bool null Wikimedia\Rdbms\ResultWrapper::$currentRow
protected

The row at $this->currentPos, or null if it has not yet been retrieved, or false if the current row was past the end.

Definition at line 39 of file ResultWrapper.php.

◆ $nextPos

int Wikimedia\Rdbms\ResultWrapper::$nextPos = 0
protected

The offset of the row that would be returned by the next call to fetchObject().

Definition at line 27 of file ResultWrapper.php.


The documentation for this class was generated from the following file: