FrxSQLQueryBuilder.inc in Forena Reports 7.2
File
FrxSQLQueryBuilder.inc
View source
<?php
class FrxSQLQueryBuilder {
private $clauses = array();
private $descriptions = array();
private $where_clause = array();
private $comparison_operators = array(
'<' => 'is less than',
'>' => 'is greater than',
'=' => 'is equal to',
'<>' => 'is not equal to',
'= any' => 'is one of',
'LIKE' => 'is like',
);
private $data;
public function query($block, $values = array()) {
$this->applied_filters = array();
$this->block = $block;
$this->data = $values;
return $this;
}
public function execute() {
return FrxReportGenerator::instance()
->invoke_data_provider($this->block, $this->data, $this
->sql());
}
public function sql() {
$where = '';
$i = 0;
if (count($this->where_clause) > 0) {
foreach ($this->where_clause as $clause) {
$i++;
$where .= $i == 1 ? 'WHERE ' : ' AND ';
$where .= $clause;
}
}
return $where;
}
public function where($condition, $include = TRUE) {
if ($include) {
$this->where_clause[] = $condition;
}
return $this;
}
public function filter($field, $comparison, $include = TRUE) {
if ($include === null) {
$include = !empty($this->data[$field]);
}
if ($include && @$this->comparison_operators[$comparison]) {
$this->where_clause[] = $field . ' ' . $comparison . ' :' . $field;
}
return $this;
}
public function condition($field, $comparison, $value) {
$this->data[$field] = $value;
$this
->filter($field, $comparison);
}
public function filter_not_null($field, $comparison) {
if (!empty($this->data[$field])) {
$this
->filter($field, $comparison);
}
return $this;
}
}
Classes
Name |
Description |
FrxSQLQueryBuilder |
FrxSQLQuery SQL Builder
This class defines a common query builder that is used to
make SQL safe queries based on named column filteres.
@author metzlerd |