Skip to content

Commit

Permalink
Merge pull request #1372 from juanitomint/develop
Browse files Browse the repository at this point in the history
Added unbuffered_row() function (issue #1351)
  • Loading branch information
narfbg committed May 21, 2012
2 parents 67a08ed + 441dfc3 commit 1d79efe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions system/database/DB_result.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,19 @@ public function previous_row($type = 'object')

// --------------------------------------------------------------------

/**
* Returns an unbuffered row and move pointer to next row
*
* @return mixed either a result object or array
*/
public function unbuffered_row($type = 'object')
{
return ($type !== 'array') ? $this->_fetch_object() : $this->_fetch_assoc();

}

// --------------------------------------------------------------------

/**
* The following functions are normally overloaded by the identically named
* methods in the platform-specific driver -- except when query caching
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Release Date: Not Released
- Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge <database/forge>`.
- Added MSSQL, SQLSRV support for optimize_table() in :doc:`Database Utility <database/utilities>`.
- Improved CUBRID support for list_databases() in :doc:`Database Utility <database/utilities>` (until now only the currently used database was returned).
- Added unbuffered_row() function for getting a row without prefetching whole result (consume less memory)

- Libraries

Expand Down
20 changes: 20 additions & 0 deletions user_guide_src/source/database/results.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ parameter:
| **$row = $query->next_row('array')**
| **$row = $query->previous_row('array')**
.. note:: all the functions above will load the whole result into memory (prefetching) use unbuffered_row() for processing large result sets.

unbuffered_row($type)
=====

This function returns a single result row without prefetching the whole result in memory as row() does.
If your query has more than one row, it returns the current row and moves the internal data pointer ahead.
The result is returned as $type could be 'object' (default) or 'array' that will return an associative array.



$query = $this->db->query("YOUR QUERY");

while ($row = $query->unbuffered_row())
{
echo $row->title;
echo $row->name;
echo $row->body;
}

***********************
Result Helper Functions
***********************
Expand Down

1 comment on commit 1d79efe

@purdy
Copy link

@purdy purdy commented on 1d79efe Jan 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to be merged into master sometime?

Please sign in to comment.