Source for file recordset.php
Documentation is available at recordset.php
* dbscript for PHP 4 & 5 - restful crud framework
* @version 0.1.2 -- 19-Feb-2007
* @author Brian Hendrickson <brian@dbscript.net>
* @link http://dbscript.net/
* @copyright Copyright 2007 Brian Hendrickson
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* RecordSets are objects comprised of a join query result resource
* and a lazy-loading iterator for each table in the result.
* $rs = $db->get_recordset( $people->get_query );
* while ( $Person = $rs->MoveNext() )
* {@link http://dbscript.net/recordset}
* @author Brian Hendrickson <brian@dbscript.net>
$this->result = $db->get_result($sql, true);
// get table and field names from result column headers
for ( $i = 0; $i < $db->num_fields( $this->result ); $i++ ) {
$col = split( "\.", $db->field_name( $this->result, $i ) );
if ( count( $col ) == 2 && $col[0] && $col[1] ) {
if ($col[1] == $db->models[$col[0]]->primary_key) {
if ($i == 0) $this->table = $col[0];
trigger_error( 'Malformed SQORP query "'. $db->field_name( $this->result, $i ). '". Example: select people.id as "people.id".', E_USER_ERROR );
// read the primary key value(s) in each row and map them to the result row number
for ( $i = 0; $i < $db->num_rows( $this->result ); $i++ ) {
foreach ( $this->tablelist as $table => $pkoffset ) {
$pkvalue = $db->result_value( $this->result, $i, $pkoffset );
$this->rowmap[$table][$pkvalue] = $i;
if ( !( $table == $this->table ) ) {
if ( !( isset ( $this->iterator[$table] ))) {
return $this->iterator[$table]->MoveFirst();
if ( !( isset ( $this->iterator[$table] ))) {
return $this->iterator[$table]->MoveNext();
if ( !( isset ( $this->iterator[$table] ))) {
return $this->iterator[$table]->FirstChild( $parent_pkval );
function NextChild( $parent_pkval, $table ) {
if ( !( isset ( $this->iterator[$table] ))) {
return $this->iterator[$table]->NextChild( $parent_pkval );
function Load( $table, $row ) {
if ( !( $row < $this->rowcount )) return false;
foreach ( $this->fieldlist[$table] as $field => $idx ) {
return $db->iterator_load_record( $table, $this->fieldlist[$table], $this );
if ( !( isset ( $this->iterator[$table] ))) {
return $this->iterator[$table]->seek( $row );
if (isset ($this->rowmap[$table]))
|