MediaWiki  master
Wikimedia\Rdbms\ResultWrapper Class Reference

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

Inheritance diagram for Wikimedia\Rdbms\ResultWrapper:
Collaboration diagram for Wikimedia\Rdbms\ResultWrapper:

Public Member Functions

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

Static Public Member Functions

static unwrap ( $res)
 Get the underlying RDBMS driver-specific result resource. More...
 

Protected Member Functions

 doFetchObject ()
 Get the next row as a stdClass object, or false if iteration has proceeded past the end. More...
 
 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. More...
 
 doFree ()
 Free underlying data. More...
 
 doGetFieldNames ()
 Get the field names in the result set. More...
 
 doNumRows ()
 Get the number of rows in the result set. More...
 
 doSeek ( $pos)
 Modify the current cursor position to the row with the specified offset. More...
 

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(). More...
 
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. More...
 
int $nextPos = 0
 The offset of the row that would be returned by the next call to fetchObject(). More...
 

Private Attributes

string[] null $fieldNames
 Cache of field names. More...
 

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.

Stability: stable
to override

Definition at line 23 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 125 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\doNumRows().

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

◆ current()

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

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 165 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\$currentRow, and Wikimedia\Rdbms\ResultWrapper\fetchObject().

◆ 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\SqliteResultWrapper, Wikimedia\Rdbms\PostgresResultWrapper, Wikimedia\Rdbms\MysqliResultWrapper, and Wikimedia\Rdbms\FakeResultWrapper.

Referenced by Wikimedia\Rdbms\ResultWrapper\fetchObject().

◆ 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\SqliteResultWrapper, Wikimedia\Rdbms\PostgresResultWrapper, Wikimedia\Rdbms\MysqliResultWrapper, and Wikimedia\Rdbms\FakeResultWrapper.

Referenced by Wikimedia\Rdbms\ResultWrapper\fetchRow().

◆ 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\SqliteResultWrapper, Wikimedia\Rdbms\PostgresResultWrapper, Wikimedia\Rdbms\MysqliResultWrapper, and Wikimedia\Rdbms\FakeResultWrapper.

Referenced by Wikimedia\Rdbms\ResultWrapper\seek().

◆ 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|bool
Exceptions
DBUnexpectedErrorThrown if the database returns an error

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 129 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\$currentRow, and Wikimedia\Rdbms\ResultWrapper\doFetchObject().

Referenced by Wikimedia\Rdbms\ResultWrapper\current(), and Wikimedia\Rdbms\ResultWrapper\next().

◆ 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|bool
Exceptions
DBUnexpectedErrorThrown if the database returns an error

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 135 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\$currentRow, and Wikimedia\Rdbms\ResultWrapper\doFetchRow().

◆ 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 156 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\doFree().

◆ 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 186 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\$fieldNames, and Wikimedia\Rdbms\ResultWrapper\doGetFieldNames().

◆ key()

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

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 173 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\$currentPos.

◆ next()

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

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 177 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\fetchObject().

◆ numRows()

Wikimedia\Rdbms\ResultWrapper::numRows ( )

Get the number of rows in a result object.

Returns
int

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 121 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\doNumRows().

Referenced by Wikimedia\Rdbms\ResultWrapper\seek(), and Wikimedia\Rdbms\ResultWrapper\valid().

◆ rewind()

Wikimedia\Rdbms\ResultWrapper::rewind ( )

Definition at line 161 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\seek().

◆ 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 141 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\doSeek(), and Wikimedia\Rdbms\ResultWrapper\numRows().

Referenced by Wikimedia\Rdbms\ResultWrapper\rewind().

◆ unwrap()

static Wikimedia\Rdbms\ResultWrapper::unwrap (   $res)
static

Get the underlying RDBMS driver-specific result resource.

The result resource field should not be accessed from non-Database related classes. It is database class specific and is stored here to associate iterators with queries.

Since
1.34
Deprecated:
since 1.37
Parameters
self | mixed$res
Returns
mixed

Definition at line 59 of file ResultWrapper.php.

References $res, and wfDeprecated().

◆ valid()

Wikimedia\Rdbms\ResultWrapper::valid ( )

Definition at line 181 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\numRows().

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 34 of file ResultWrapper.php.

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

◆ $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 40 of file ResultWrapper.php.

Referenced by Wikimedia\Rdbms\ResultWrapper\current(), Wikimedia\Rdbms\ResultWrapper\fetchObject(), and Wikimedia\Rdbms\ResultWrapper\fetchRow().

◆ $fieldNames

string [] null Wikimedia\Rdbms\ResultWrapper::$fieldNames
private

Cache of field names.

Definition at line 45 of file ResultWrapper.php.

Referenced by Wikimedia\Rdbms\ResultWrapper\getFieldNames().

◆ $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 28 of file ResultWrapper.php.


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