function Quant::execute_query in Quant 7
Execute the quant query
Return value
A database resource result
1 call to Quant::execute_query()
- Quant::execute in plugins/
Quant.inc - Execute the quant for a given period
File
- plugins/
Quant.inc, line 96
Class
- Quant
- Quant class
Code
function execute_query() {
// Use a pre-defined query, if there is one
if (isset($this->query)) {
if (is_array($this->period)) {
return db_query($this->queryCustom, array(
':period0' => $this->period[0],
':period1' => $this->period[1],
));
}
else {
return db_query($this->query, array(
':period' => $this->period,
));
}
}
// Generate the query for this quant
$query = db_select($this->table, $this->table);
if ($this->dataType == 'count') {
$query
->fields($this->table, array(
$this->count,
));
$query
->addExpression("COUNT({$this->table}.{$this->count})", 'count');
$query
->groupBy("{$this->table}.{$this->count}");
}
else {
$query
->fields($this->table, array(
$this->field,
));
if ($this->dataType == 'multiple') {
$query
->fields($this->table, array(
$this->group,
));
}
$query
->orderBy("{$this->table}.{$this->field}", 'DESC');
}
if (is_array($this->period)) {
$query
->condition("{$this->table}.{$this->field}", $this->period[0], '>=');
$query
->condition("{$this->table}.{$this->field}", $this->period[1], '<=');
}
else {
$query
->condition("{$this->table}.{$this->field}", $this->period, '>=');
}
// Add the generated query to the object
$this->query = $query;
return $this->query
->execute();
}