-
Notifications
You must be signed in to change notification settings - Fork 3
/
Oracle.php
67 lines (54 loc) · 1.94 KB
/
Oracle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace koolreport\querybuilder;
class Oracle extends SQL
{
protected function buildSelectQuery($options = [])
{
$sql = "SELECT ";
if ($this->query->distinct) {
$sql .= "DISTINCT ";
}
if (count($this->query->columns) > 0) {
$sql .= $this->getSelect($this->query->columns);
} else {
$sql .= "*";
}
if (count($this->query->tables) > 0) {
$sql .= " FROM " . $this->getFrom($this->query->tables);
} else {
throw new \Exception("No table available in SQL Query");
}
if (count($this->query->joins) > 0) {
$sql .= $this->getJoin($this->query->joins);
}
if (count($this->query->conditions) > 0) {
$where = trim($this->getWhere($this->query->conditions, $options));
if (!empty($where)) $sql .= " WHERE " . $where;
}
if (count($this->query->groups) > 0) {
$groupBy = trim($this->getGroupBy($this->query->groups));
if (!empty($groupBy)) $sql .= " GROUP BY " . $groupBy;
}
if ($this->query->having) {
$having = trim($this->getHaving($this->query->having, $options));
if (!empty($having)) $sql .= " HAVING " . $having;
}
if (count($this->query->orders) > 0) {
$orderBy = trim($this->getOrderBy($this->query->orders));
if (!empty($orderBy)) $sql .= " ORDER BY " . $orderBy;
}
if ($this->query->offset !== null) {
$sql .= " OFFSET ".$this->query->offset." ROWS ";
}
if ($this->query->limit !== null) {
$sql .= " FETCH NEXT ".$this->query->limit." ROWS ONLY ";
}
if (count($this->query->unions) > 0) {
$sql .= $this->getUnions($this->query->unions);
}
if ($this->query->lock) {
$sql .= " " . $this->query->lock;
}
return $sql;
}
}