37 require_once realpath(dirname(__FILE__).
"/query.inc");
66 $order_by_idx = strpos(strtoupper($this->
constraints),
"ORDER BY");
67 if ($order_by_idx !==
false)
69 $orderBy = substr($this->
constraints, $order_by_idx);
74 $fields = $prototype->getFieldList();
78 $query =
"SELECT $fields FROM {$prototype->table} {$this->constraints} ".$prototype->getIdentityConstraint().
" $orderBy";;
85 $useFormat = preg_match(
"/^[A-Za-z0-9_]*$/", $field) ? false :
true;
91 $result = $db->prepare($query);
92 $result->execute($this->
params);
94 while($line = $result->fetch())
97 $item->populate($line);
98 $val = ($useFormat) ? $item->format($field) : $item->get($field);
100 $items[$val][] = $item;
105 catch(PDOException $e)
107 $err =
"groupedQuery() failed - " . $e->getMessage();
127 $this->
constraints .=
" ".$prototype->getIdentityConstraint();
129 $query =
"SELECT {$this->groupBy}, $func as result FROM {$prototype->table} {$this->tableAlias} {$this->constraints} GROUP BY {$this->groupBy}";
139 $result = $db->prepare($query);
140 $result->execute($this->
params);
142 while ($row = $result->fetch())
149 catch(PDOException $e)
151 $err =
"Query::executeValue() failed - " . $e->getMessage();
177 $field = $prototype->primary_key;
183 if (func_num_args() > 1)
185 $query->constraints(func_get_arg(1));
187 if (func_num_args() > 2)
189 $query->groupBy(func_get_arg(2));
191 if (func_num_args() > 3)
193 $query->filter(func_get_arg(3));
198 return $query->execute();
constraints($constraints)
Sets the constraint clause for the Query.
filter($filter)
Sets a filter to constrain the fields retrieved when the query is executed.
params($params)
Sets the bound parameters array.
static getConnection()
Retrieves a reference to the global database connection.
static create($class, $constraints="", $groupBy="")
__construct($class, $constraints="", $groupBy="")
executeValue($func)
Query the database to calculate aggregate values by grouping.
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
groupedQuery($class)
Performs a query against the database, returning an array of arrays of DataItem objects of the specif...