DataSet Class Reference

Inherited by QueryDataSet, and TableDataSet.

List of all members.

Public Member Functions

Public Attributes


Detailed Description

The DataSet represents the results of a query.

It contains a collection of records and implements the IteratorAggregate interface so that you can use the dataset in a foreach() {} loop.

$ds = new TableDataSet($conn, "mytable"); $ds->fetchRecords(); foreach($ds as $record) { $record->setValue("col1", "new value"); $record->save(); }

This class is extended by QueryDataSet and TableDataSet and should not be used directly.

NOTE: Iterating over a dataset in the php4 version has to be done in a for-loop:

$ds = new TableDataSet($conn, "mytable"); $ds->fetchRecords();

for ($it =& $ds->getIterator(); $it->valid(); $it->next()) { $record =& $it->current(); $record->setValue("col1", "new value"); $record->save(); }

Author Jon S. Stevens <jon@latchkey.com> (Village)

Michael Aichler <aichler@mediacluster.de> (Jargon)

Hans Lellelid <hans@xmpl.org> (Jargon)

Version 

Revision

1.2
jargon


Member Function Documentation

DataSet::ALL_RECORDS ()

 

indicates that all records should be retrieved during a fetch

& DataSet::getIterator ()

 

Return iterator (for IteratorAggregate interface). This allows this class to be used in a foreach() loop. foreach($dataset as $record) { print "col1 = " . $record->getValue("col1") . "\n"; }

Returns DataSetIterator

& DataSet::resultSet ()

 

Gets the ResultSet for this DataSet

Returns mixed ResultSet The result set for this DataSet on success, DataSetException - if resultset is null

DataSet::allRecordsRetrieved ()

 

Check if all the records have been retrieve

Returns boolean True if all records have been retrieved

DataSet::setAllRecordsRetrieved ( $  set)

 

Set all records retrieved

Parameters:
boolean $set

Returns void

& DataSet::removeRecord ( &$  rec)

 

Remove a record from the DataSet's internal storage

Parameters:
Record $rec //

Returns mixed Record The record removed on success, DataSetException on failure.

mixed Record The record removed on success, FALSE if not found.

& DataSet::clearRecords ()

 

Remove all records from the DataSet and nulls those records out and close() the DataSet.

Returns an instance of myself

& DataSet::releaseRecords ()

 

Removes the records from the DataSet, but does not null the records out

Returns an instance of myself

DataSet::close ()

 

Releases the records, closes the ResultSet and the Statement, and nulls the Schema and Connection references.

Returns void

& DataSet::reset ()

 

Essentially the same as releaseRecords, but it won't work on a QueryDataSet that has been created with a ResultSet

Returns mixed DataSet This object on success, DataSetException on failure.

& DataSet::connection ()

 

Gets the current database connection

Returns Connection A database connection.

& DataSet::schema ()

 

Gets the Schema for this DataSet

Returns Schema The Schema for this DataSet

& DataSet::getRecord ( $  pos)

 

Get Record at 0 based index position

NOTE: Behaviour of this function is slightly different compared to the php5 version. Instead of throwing (returning) an exception, this function simply returnes FALSE, if the record at position $pos cannot be found.

Parameters:
int $pos

Returns mixed Record An instance of the found Record or FALSE if not found.

& DataSet::findRecord ( $  pos)

 

Find Record at 0 based index position. This is an internal alternative to getRecord which tries to be smart about the type of record it is.

NOTE: Behaviour of this function is slightly different compared to the php5 version. Instead of throwing (returning) an exception, this function simply returnes FALSE, if the record at position $pos cannot be found.

Parameters:
int $pos

Returns mixed Record an instance of the found Record on success, otherwise FALSE.

DataSet::containsRecord ( $  pos)

 

Check to see if the DataSet contains a Record at 0 based position

Parameters:
pos 

Returns TRUE if record exists otherwise FALSE.

DataSet::fetchRecords ( $  p1 = 0,  $  p2 = null )

 

Causes the DataSet to hit the database and fetch max records, starting at start. Record count begins at 0.

This method supports two signatures:

Parameters:
int $p1 max - or start if $p2 is set
int $p2 start

Returns DataSet This class on success.

SQL- or DataSetException on failure.

Reimplemented in TableDataSet.

DataSet::lastFetchSize ()

 

The number of records that were fetched with the last fetchRecords.

Returns int

& DataSet::keydef ()

 

gets the KeyDef object for this DataSet

Returns KeyDef The keydef for this DataSet, this value can be null

DataSet::__toString ()

 

This returns a represention of this DataSet

DataSet::getSelectSql ()

 

Classes extending this class must implement this method.

Returns string The SELECT SQL.

Exceptions:
DataSetException; 

Reimplemented in QueryDataSet, and TableDataSet.

& DataSet::getColumns ()

 

Returns the columns attribute for the DataSet

Returns the columns attribute for the DataSet

DataSet::size ()

 

Gets the number of Records in this DataSet. It is 0 based.

Returns int Number of Records in this DataSet


Member Data Documentation

DataSet::$records

 

this DataSet's collection of Record objects

DataSet::$conn

 

this DataSet's connection object

DataSet::$allRecordsRetrieved = false

 

have all records been retrieved with the fetchRecords?

DataSet::$recordRetrievedCount = 0

 

number of records retrieved

DataSet::$lastFetchSize = 0

 

number of records that were last fetched

DataSet::$totalFetchCount = 0

 

number of records total that have been fetched

DataSet::$columns

 

the columns in the SELECT statement for this DataSet

DataSet::$selectSql

 

the select string that was used to build this DataSet

DataSet::$keyDef

 

the KeyDef for this DataSet

DataSet::$resultSet

 

the result set for this DataSet

DataSet::$stmt

 

the Statement for this DataSet


This file is part of the Creole[php4] library.


Copyright © 2004 Hans Lellelid  
Creole[php4] CVS