Framework  3.9
IteratedQuery Class Reference

IteratedQuery provides a memory-efficient way to query and return large data sets. More...

+ Inheritance diagram for IteratedQuery:
+ Collaboration diagram for IteratedQuery:

Public Member Functions

 __construct ($class, $constraints="")
 
 _runQuery ()
 
 execute ()
 
- Public Member Functions inherited from AbstractQuery
 constraints ($constraints)
 Sets the constraint clause for the Query. More...
 
 filter ($filter)
 Sets a filter to constrain the fields retrieved when the query is executed. More...
 
 params ($params)
 Sets the bound parameters array. More...
 
 bind ()
 Binds placeholders to parameter values. More...
 

Static Public Member Functions

static create ($class, $constraints="")
 

Additional Inherited Members

- Public Attributes inherited from AbstractQuery
 $class
 
 $constraints
 
 $filter
 
 $params
 

Detailed Description

IteratedQuery provides a memory-efficient way to query and return large data sets.

Whereas the default Query class and the IndexedQuery and GroupedQuery classes all pull the full result set into memory when the query is executed, IteratedQuery leaves the connection to the database open and retrieves the results one row at a time. The results are returned wrapped in a DataItemIterator, allowing them to be used in foreach(...) statements, etc.

In general it is recommended that IteratedQuery only be used in situations where the result would take up too much memory to be processed using a standard Query object.

Author
andy

Definition at line 163 of file iterated_query.inc.

Constructor & Destructor Documentation

◆ __construct()

IteratedQuery::__construct (   $class,
  $constraints = "" 
)

Reimplemented from AbstractQuery.

Definition at line 165 of file iterated_query.inc.

166  {
167  parent::__construct($class, $constraints);
168  }

Member Function Documentation

◆ _runQuery()

IteratedQuery::_runQuery ( )

Definition at line 170 of file iterated_query.inc.

171  {
172  $prototype = new $this->class;
173  $prototype->filter = $this->filter;
174 
175  $order_by_idx = strpos(strtoupper($this->constraints), "ORDER BY");
176  $orderBy = "";
177 
178  if ($order_by_idx !== false)
179  {
180  $orderBy = substr($this->constraints, $order_by_idx);
181 
182  $this->constraints = substr($this->constraints, 0, $order_by_idx);
183  }
184 
185  if ($this->constraints == "") $this->constraints = "WHERE 1=1"; //TODO - tidy this up some day
186  $this->constraints .= " ".$prototype->getIdentityConstraint();
187 
188  $query = "SELECT ".$prototype->getFieldList()." FROM {$prototype->table} {$this->tableAlias} {$this->constraints} $orderBy";
189 
190  trace("$query", 3);
191 
192  try
193  {
195 
196  $result = $db->prepare($query);
197  $result->execute($this->params);
198  $this->rowCount = $result->rowCount();
199  return $result;
200  }
201  catch(PDOException $e)
202  {
203  throw new FakoliException($e->getMessage());
204  }
205  }
constraints($constraints)
Sets the constraint clause for the Query.
Definition: query.inc:68
params($params)
Sets the bound parameters array.
Definition: query.inc:91
static getConnection()
Retrieves a reference to the global database connection.
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

◆ create()

static IteratedQuery::create (   $class,
  $constraints = "" 
)
static

Definition at line 212 of file iterated_query.inc.

213  {
214  return new IteratedQuery($class, $constraints);
215  }
IteratedQuery provides a memory-efficient way to query and return large data sets.

◆ execute()

IteratedQuery::execute ( )

Reimplemented from AbstractQuery.

Definition at line 207 of file iterated_query.inc.

208  {
209  return new DataItemIterator($this);
210  }
DataItemIterator is a memory-efficient iterator class that can be used when rendering large data sets...

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