MediaWiki  1.28.3
ResultWrapper Class Reference

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

Inheritance diagram for ResultWrapper:
Collaboration diagram for ResultWrapper:

Public Member Functions

 __construct (IDatabase $db=null, $result)
 Create a row iterator from a result resource and an optional Database 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...
 
 key ()
 
 next ()
 
 numRows ()
 Get the number of rows in a result object. More...
 
 rewind ()
 
 seek ($row)
 Change the position of the cursor in a result object. More...
 
 valid ()
 

Public Attributes

resource array null $result
 Optional underlying result handle for subclass usage. More...
 

Protected Attributes

stdClass null $currentRow = null
 
IDatabase null $db
 
int $pos = 0
 

Private Member Functions

 getDB ()
 

Detailed Description

Result wrapper for grabbing data queried from an IDatabase object.

Note that using the Iterator methods in combination with the non-Iterator DB 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. If no database is provided, and the subclass does not override the DB iteration methods, then a RuntimeException will be thrown when iteration is attempted.

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.

Definition at line 18 of file ResultWrapper.php.

Constructor & Destructor Documentation

ResultWrapper::__construct ( IDatabase  $db = null,
  $result 
)

Create a row iterator from a result resource and an optional Database object.

Only Database-related classes should construct ResultWrapper. Other code may use the FakeResultWrapper subclass for convenience or compatibility shims, however.

Parameters
IDatabase | null$dbOptional database handle
ResultWrapper | array | resource$resultOptional underlying result handle

Definition at line 39 of file ResultWrapper.php.

References $db, and $result.

Member Function Documentation

ResultWrapper::current ( )
Returns
stdClass|array|bool

Definition at line 127 of file ResultWrapper.php.

References $currentRow, and next().

Referenced by valid().

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

Definition at line 65 of file ResultWrapper.php.

References getDB().

Referenced by IndexPager\extractResultInfo(), and next().

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

Definition at line 76 of file ResultWrapper.php.

References getDB().

Referenced by IndexPager\extractResultInfo().

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.

Definition at line 96 of file ResultWrapper.php.

ResultWrapper::getDB ( )
private
Returns
IDatabase
Exceptions
RuntimeException

Definition at line 108 of file ResultWrapper.php.

References $db.

Referenced by fetchObject(), fetchRow(), numRows(), rewind(), and seek().

ResultWrapper::key ( )
Returns
int

Definition at line 138 of file ResultWrapper.php.

References $pos.

ResultWrapper::next ( )
Returns
stdClass

Definition at line 145 of file ResultWrapper.php.

References $currentRow, and fetchObject().

Referenced by current().

ResultWrapper::numRows ( )

Get the number of rows in a result object.

Returns
int

Definition at line 53 of file ResultWrapper.php.

References getDB().

Referenced by IndexPager\extractResultInfo(), and rewind().

ResultWrapper::rewind ( )

Definition at line 116 of file ResultWrapper.php.

References getDB(), and numRows().

ResultWrapper::seek (   $row)

Change the position of the cursor in a result object.

See mysql_data_seek()

Parameters
int$row

Definition at line 86 of file ResultWrapper.php.

References getDB().

Referenced by IndexPager\extractResultInfo().

ResultWrapper::valid ( )

Definition at line 152 of file ResultWrapper.php.

References current().

Member Data Documentation

stdClass null ResultWrapper::$currentRow = null
protected
IDatabase null ResultWrapper::$db
protected

Definition at line 23 of file ResultWrapper.php.

Referenced by __construct(), and getDB().

int ResultWrapper::$pos = 0
protected

Definition at line 26 of file ResultWrapper.php.

Referenced by FakeResultWrapper\fetchRow(), and key().

resource array null ResultWrapper::$result

Optional underlying result handle for subclass usage.

Definition at line 20 of file ResultWrapper.php.

Referenced by __construct(), MssqlResultWrapper\fetchObject(), MssqlResultWrapper\fetchRow(), and MssqlResultWrapper\seek().


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