TableDataSet Class Reference

Inheritance diagram for TableDataSet:

DataSet

List of all members.

Public Member Functions

 __construct (Connection $conn, $tableName, $p3=null, $p4=null)
 Construct new TableDataSet instance.
 tableName ()
 Gets the tableName defined in the schema.
 tableInfo ()
 Load the TableInfo (metadata) object for this table.
 fetchRecords ($p1=0, $p2=null)
 Fetch start to max records.
 addRecord ()
 Creates a new Record within this DataSet.
 save ()
 Saves all the records in the DataSet.
 removeDeletedRecords ()
 Removes any records that are marked as a zombie.
 setOptimisticLockingColumn ($olc)
 Sets the table column used for optomistic locking.
 optimisticLockingCol ()
 Gets the table column used for optomistic locking.
 where ($where)
 Sets the value for the SQL portion of the WHERE statement.
 getWhere ()
 Gets the value of the SQL portion of WHERE.
 order ($order)
 Sets the value for the SQL portion of the ORDER statement.
 getOrder ()
 Gets the value of the SQL portion of ORDER.
 other ($other)
 Sets the value for the SQL portion of the OTHER statement.
 getOther ()
 Gets the value of the SQL portion of OTHER.
 refresh ()
 This method refreshes all of the Records stored in this TableDataSet.
 setRefreshOnSave ($v)
 Setting this causes each Record to refresh itself when a save() is performed on it.
 refreshOnSave ()
 Setting this causes each Record to refresh itself when a save() is performed on it.
 getSelectSql ()
 Builds the select string that was used to populate this TableDataSet.

Private Member Functions

 buildSelectString ()
 Used by getSelectSql() to build the select string that was used to populate this TableDataSet.

Private Attributes

 $tableName
 Name of current table.
 $tableInfo
 TableInfo (metadata) object.
 $optimisticLockingCol
 the optimistic locking column value
 $where
 the value for the sql where clause
 $order
 the value for the sql order by clause
 $other
 the value for the sql other clause
 $refreshOnSave = false
 Whether to reload record values when save() is performed.


Detailed Description

Definition at line 39 of file TableDataSet.php.


Constructor & Destructor Documentation

TableDataSet::__construct ( Connection conn,
tableName,
p3 = null,
p4 = null 
)

Construct new TableDataSet instance.

Supports a few signatures:

Parameters:
Connection $conn
string $tableName
mixed $p3 KeyDef or column list (string)
mixed $p4 KeyDef or column list (string)

Definition at line 75 of file TableDataSet.php.

References $tableName, and tableName().

00076     {
00077         $this->conn = $conn;
00078         $this->columns = "*";
00079         $this->tableName = $tableName;
00080         
00081         if ($p4 !== null) {
00082             $this->columns = $p3;
00083             $this->keyDef = $p4;
00084         } elseif ($p3 !== null) {
00085             if ($p3 instanceof KeyDef) {
00086                 $this->keyDef = $p3;
00087             } else { // it's a string (column list)
00088                 $this->columns = $p3;
00089             }
00090         }
00091     }


Member Function Documentation

TableDataSet::addRecord (  ) 

Creates a new Record within this DataSet.

Returns:
Record The added record
Exceptions:
DataSetException 
SQLException 

Definition at line 138 of file TableDataSet.php.

00139     {
00140         $rec = new Record($this, true);
00141         $rec->markForInsert();
00142         $this->records[] = $rec;
00143         return $rec;
00144     }

TableDataSet::buildSelectString (  )  [private]

Used by getSelectSql() to build the select string that was used to populate this TableDataSet.

See also:
getSelectSql()
Returns:
void
Exceptions:
DataSetException 

Definition at line 324 of file TableDataSet.php.

References order(), other(), tableName(), and where().

Referenced by fetchRecords().

00325     {
00326         $this->selectSql = "SELECT ";
00327         $this->selectSql .= $this->columns;
00328         $this->selectSql .= " FROM " . $this->tableName;
00329         if ($this->where !== null && $this->where !== "") {
00330             $this->selectSql .= " WHERE " . $this->where;
00331         }
00332         if ($this->order !== null && $this->order !== "") {
00333             $this->selectSql .= " ORDER BY " . $this->order;
00334         }
00335         if ($this->other !== null && $this->other !== "") {
00336             $this->selectSql .= $this->other;
00337         }
00338     }

TableDataSet::fetchRecords ( p1 = 0,
p2 = null 
)

Fetch start to max records.

start is at Record 0

Parameters:
int $start
int $max
Returns:
TableDataSet This object.
Exceptions:
SQLException 
DataSetException 

Reimplemented from DataSet.

Definition at line 125 of file TableDataSet.php.

References buildSelectString().

00126     {
00127         $this->buildSelectString();
00128         return parent::fetchRecords($p1, $p2);
00129     }

TableDataSet::getOrder (  ) 

Gets the value of the SQL portion of ORDER.

Returns:
string

Definition at line 243 of file TableDataSet.php.

References order().

00244     {
00245         return $this->order;
00246     }

TableDataSet::getOther (  ) 

Gets the value of the SQL portion of OTHER.

Returns:
string

Definition at line 267 of file TableDataSet.php.

References other().

00268     {
00269         return $this->other;
00270     }

TableDataSet::getSelectSql (  ) 

Builds the select string that was used to populate this TableDataSet.

Returns:
SQL select string

Reimplemented from DataSet.

Definition at line 312 of file TableDataSet.php.

00313     {
00314         return $this->selectSql;     
00315     }

TableDataSet::getWhere (  ) 

Gets the value of the SQL portion of WHERE.

Returns:
string

Definition at line 219 of file TableDataSet.php.

References where().

00220     {
00221         return $this->where;
00222     }

TableDataSet::optimisticLockingCol (  ) 

Gets the table column used for optomistic locking.

Returns:
string

Definition at line 196 of file TableDataSet.php.

Referenced by setOptimisticLockingColumn().

00197     {
00198         return $this->optimisticLockingCol;
00199     }

TableDataSet::order ( order  ) 

Sets the value for the SQL portion of the ORDER statement.

Returns:
TableDataSet instance of self
Exceptions:
DataSetException 

Definition at line 230 of file TableDataSet.php.

References $order.

Referenced by buildSelectString(), and getOrder().

00231     {
00232         if ($order === null) {
00233             throw new DataSetException("null not allowed for order clause");
00234         }
00235         $this->order = $order;
00236         return $this;
00237     }

TableDataSet::other ( other  ) 

Sets the value for the SQL portion of the OTHER statement.

Parameters:
string $other
Returns:
TableDataSet instance of self
Exceptions:
DataSetException 

Definition at line 254 of file TableDataSet.php.

References $other.

Referenced by buildSelectString(), and getOther().

00255     {
00256         if ($other === null) {
00257             throw new DataSetException("null not allowed for other clause");
00258         }            
00259         $this->other = $other;
00260         return $this;
00261     }

TableDataSet::refresh (  ) 

This method refreshes all of the Records stored in this TableDataSet.

Exceptions:
SQLException,DataSetException 
Returns:
void

Definition at line 277 of file TableDataSet.php.

00278     {
00279         foreach($this->records as $rec) {
00280             $rec->refresh($this->conn);
00281         }
00282     }

TableDataSet::refreshOnSave (  ) 

Setting this causes each Record to refresh itself when a save() is performed on it.

Default value is false.

Returns:
boolean True if it is on; false otherwise

Definition at line 303 of file TableDataSet.php.

Referenced by setRefreshOnSave().

00304     {
00305         return $this->refreshOnSave;
00306     }  

TableDataSet::removeDeletedRecords (  ) 

Removes any records that are marked as a zombie.

Returns:
void
Exceptions:
DataSetException 

Definition at line 170 of file TableDataSet.php.

Referenced by save().

00171     {
00172         // this algorythm should be a fair bit
00173         // faster than calling DataSet::removeRecord()
00174         $new_recs = array();
00175         foreach($this->records as $rec) {
00176             if (!$rec->isAZombie()) {
00177                 $new_recs[] = $rec;
00178             }
00179         }
00180         $this->records = $new_recs;
00181     }

TableDataSet::save (  ) 

Saves all the records in the DataSet.

Returns:
int Total number of records updated/inserted/deleted.
Exceptions:
SQLException,DataSetException 

Definition at line 151 of file TableDataSet.php.

References removeDeletedRecords().

00152     {
00153         $j = 0;
00154         foreach($this->records as $rec) {
00155             $rec->save();
00156             $j++;
00157         }        
00158         // now go through and remove any records
00159         // that were previously marked as a zombie by the 
00160         // delete process
00161         $this->removeDeletedRecords();
00162         return $j;
00163     }

TableDataSet::setOptimisticLockingColumn ( olc  ) 

Sets the table column used for optomistic locking.

Parameters:
string $olc

Definition at line 187 of file TableDataSet.php.

References optimisticLockingCol().

00188     {
00189         $this->optimisticLockingCol = $olc;
00190     }

TableDataSet::setRefreshOnSave ( v  ) 

Setting this causes each Record to refresh itself when a save() is performed on it.

Default value is false.

Parameters:
boolean $v
Returns:
true if it is on; false otherwise

Definition at line 291 of file TableDataSet.php.

References refreshOnSave().

00292     {
00293         $this->refreshOnSave = $v;
00294     }

TableDataSet::tableInfo (  ) 

Load the TableInfo (metadata) object for this table.

Returns:
TableInfo
Exceptions:
SQLException if current conn doesn't know about $this->tableName

Definition at line 108 of file TableDataSet.php.

References tableName().

00109     {
00110         if ($this->tableInfo === null) {
00111             $this->tableInfo = $this->conn->getDatabaseInfo()->getTable($this->tableName);
00112         }
00113         return $this->tableInfo;
00114     }

TableDataSet::tableName (  ) 

Gets the tableName defined in the schema.

Returns:
string
Exceptions:
DataSetException 

Definition at line 98 of file TableDataSet.php.

Referenced by __construct(), buildSelectString(), and tableInfo().

00099     {
00100         return $this->tableName;
00101     }

TableDataSet::where ( where  ) 

Sets the value for the SQL portion of the WHERE statement.

Returns:
instance of self
Exceptions:
DataSetException 

Definition at line 206 of file TableDataSet.php.

References $where.

Referenced by buildSelectString(), and getWhere().

00207     {
00208         if ($where == null) {
00209             throw new DataSetException("null not allowed for where clause");
00210         }            
00211         $this->where = $where;
00212         return $this;
00213     }


Member Data Documentation

TableDataSet::$optimisticLockingCol [private]

the optimistic locking column value

Definition at line 48 of file TableDataSet.php.

TableDataSet::$order [private]

the value for the sql order by clause

Definition at line 54 of file TableDataSet.php.

Referenced by order().

TableDataSet::$other [private]

the value for the sql other clause

Definition at line 57 of file TableDataSet.php.

Referenced by other().

TableDataSet::$refreshOnSave = false [private]

Whether to reload record values when save() is performed.

Definition at line 60 of file TableDataSet.php.

TableDataSet::$tableInfo [private]

TableInfo (metadata) object.

Definition at line 45 of file TableDataSet.php.

TableDataSet::$tableName [private]

Name of current table.

Definition at line 42 of file TableDataSet.php.

Referenced by __construct().

TableDataSet::$where [private]

the value for the sql where clause

Definition at line 51 of file TableDataSet.php.

Referenced by where().


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

Generated on Wed May 6 23:10:50 2009 for fareofficelib by  doxygen 1.5.8