aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/database.php117
1 files changed, 65 insertions, 52 deletions
diff --git a/engine/lib/database.php b/engine/lib/database.php
index 6b8db1956..1cc348574 100644
--- a/engine/lib/database.php
+++ b/engine/lib/database.php
@@ -444,67 +444,80 @@
$sql = "";
- // Query prefix & fields
- if (!empty($this->query_type))
- {
- $sql .= "{$this->query_type} ";
-
- if (!empty($this->fields))
+ try
+ {
+ // Query prefix & fields
+ if (!empty($this->query_type))
{
- $fields = "";
+ $sql .= "{$this->query_type} ";
- foreach ($this->fields as $field)
- $fields .= "$field";
+ if (!empty($this->fields))
+ {
+ $fields = "";
+
+ foreach ($this->fields as $field)
+ $fields .= "$field";
+
+ $sql .= " $fields from ";
+ }
+ }
+ else
+ throw new DatabaseException("Unrecognised or unspecified query type.");
+
+ // Tables
+ if (!empty($this->tables))
+ {
+ foreach($this->tables as $table)
+ $sql .= "$table, ";
+
+ $sql = trim($sql, ", ");
+ }
+
+ // Joins on select queries
+ if ($this->query_type->query_type == 'select')
+ {
+ if (!empty($this->joins))
+ {
+ foreach($this->joins as $join)
+ $sql .= "$join ";
+ }
+ }
+
+ // Where
+ if (!empty($this->where))
+ {
+ $sql .= "where 1 ";
- $sql .= " $fields from ";
+ foreach ($this->where as $where)
+ $sql .= "$where ";
}
- }
- else
- throw new DatabaseException("Unrecognised or unspecified query type.");
+
+ // Access control
+ if (!empty($this->access_control))
+ {
+
+ // Catch missing Where
+ if (empty($this->where))
+ $sql .= "where 1 ";
- // Tables
- if (!empty($this->tables))
- {
- foreach($this->tables as $table)
- $sql .= "$table, ";
+ $sql .= "{$this->access_control} ";
+ }
+ else
+ throw new DatabaseException("No access control was provided on query");
- $sql = trim($sql, ", ");
- }
-
- // Joins on select queries
- if ($this->query_type->query_type == 'select')
- {
- if (!empty($this->joins))
- {
- foreach($this->joins as $join)
- $sql .= "$join ";
- }
- }
-
- // Where
- if (!empty($this->where))
- {
- $sql .= "where 1 ";
+ // Limits
+ if (!empty($this->limit_and_offset))
+ $sql .= "{$this->limit_and_offset} ";
- foreach ($this->where as $where)
- $sql .= "$where ";
- }
-
- // Access control
- if (!empty($this->access_control))
- $sql .= "{$this->access_control} ";
- else
- throw DatabaseException("No access control was provided on query");
+ // Order by
+ if (!empty($this->order))
+ $sql .= $this->order;
- // Limits
- if (!empty($this->limit_and_offset))
- $sql .= "{$this->limit_and_offset} ";
-
- // Order by
- if (!empty($this->order))
- $sql .= $this->order;
-
+ } catch (Exception $e) {
+ trigger_error($e, E_USER_WARNING);
+ }
+
return $sql;
}