Skip to content

Latest commit

 

History

History
126 lines (96 loc) · 4.54 KB

fUnbufferedResult.wiki

File metadata and controls

126 lines (96 loc) · 4.54 KB

Table of Contents

fUnbufferedResult

<<css mode="next" class="sidebar"></css>> (((

Class Resources <<toc></toc>>

 - '''<a href="/docs/fResult">Class Documentation</a>'''
 - <a href="/api/fResult">API Reference</a>
 - <a href="https://github.com/flourishlib/flourish-classes/blob/master/fResult.php" target="_blank">Source Code</a>

<<toc></toc>>

Database Classes <<toc></toc>>

 - fDatabase
 - fNoRowsException
 - fResult
 - fSQLException
 - fSQLTranslation
 - fSQLSchemaTranslation
 - fSchema
 - fStatement
 - '''fUnbufferedResult'''

)))

The fUnbufferedResult class is an iterable result object that is returned when an SQL query is executed. It contains similar information to fResult, however some features are missing due to the nature of the results not being buffered. The quality of being unbuffered causes this object to use less memory than an fResult object.

Creation

The fUnbufferedResult class can be created by executing the methods fDatabase::unbufferedQuery() or fDatabase::unbufferedTranslatedQuery().

Row Format

By default when retrieving rows from an unbuffered result object, they are returned as associative arrays. In the case of Oracle databases, where columns are case-insensitive, the array keys are lowercase.

It is possible to retrieve `stdClass` objects back for each row instead of associative arrays. This is done by calling the method ::asObjects(). The method returns the fUnbufferedResult object, allowing for method chaining:

If you are looking for objects with more functionality, please see fActiveRecord.

Unescaping Data

While it is certainly possible to manually unescape data from a result set, one row and column at a time, unescaping the whole result is often much easier. The method ::unescape() accepts an associative array of the column name as the key and the data type as the value. This method should be called before any rows are fetched.

Iteration

The fUnbufferedResult class implements the Iterator interface, which means that you can use the `foreach` construct to loop through all resulting rows. Below is an example of iterating over a result:

If the result did not return any rows, the `foreach` construct will not be looped at all and the execution of the code will continue. If you wish to execute different code if no rows are returned, see the next section about [#Exceptions].

If you wish to to manual iteration you can use the ::fetchRow() and ::valid() methods as shown below:

Exceptions

As mentioned in the last section, if you iterate through the result and no rows are returned, nothing will happen. If you do need to execute different code when no rows are returned, you will want to call the ::tossIfNoRows() to cause an fNoRowsException to be thrown:

In addition to calling `tossIfNoRows()`, an fNoRowsException will be thrown if any Iterator interface methods (such as `current()`, `next()`, etc) or `fetchRow()` is called on a result object which returned no rows.

Query Info

Since fUnbufferedResult does not use buffering, only a fraction of the information about a query is available compared to the fResult class.

|| Method || Description || || ::getSQL() || Returns the SQL statement executed for this result || || ::getUntranslatedSQL() || Returns the SQL from before translation happened - only applicable for results from ::unbufferedTranslatedQuery() ||