aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/db/dbal.php
diff options
context:
space:
mode:
authorDavid M <davidmj@users.sourceforge.net>2006-05-05 22:06:17 +0000
committerDavid M <davidmj@users.sourceforge.net>2006-05-05 22:06:17 +0000
commit3d2a45ab049606701172c11552aa0c1006d2fbf1 (patch)
treeea65a291ac3901d723f33446c54e449e3218ea13 /phpBB/includes/db/dbal.php
parentb6ffae82b938eb3c40395234f14d79b53ba003c4 (diff)
downloadforums-3d2a45ab049606701172c11552aa0c1006d2fbf1.tar
forums-3d2a45ab049606701172c11552aa0c1006d2fbf1.tar.gz
forums-3d2a45ab049606701172c11552aa0c1006d2fbf1.tar.bz2
forums-3d2a45ab049606701172c11552aa0c1006d2fbf1.tar.xz
forums-3d2a45ab049606701172c11552aa0c1006d2fbf1.zip
I hope nothing broke!
- Added a query builder, it is currently only used for complex queries that involve a FROM clause with two tables and a left join - Changed some function calls in the DBAL - Made the viewtopic queries nicer git-svn-id: file:///svn/phpbb/trunk@5885 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/db/dbal.php')
-rw-r--r--phpBB/includes/db/dbal.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index acc64da799..1a8b8a4ddf 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -192,6 +192,67 @@ class dbal
}
/**
+ * Build sql statement from array for select and select distinct statements
+ *
+ * Possible query values: SELECT, SELECT_DISTINCT
+ */
+ function sql_build_query($query, $array)
+ {
+ $sql = '';
+ switch ($query)
+ {
+ case 'SELECT':
+ case 'SELECT_DISTINCT';
+
+ if ($query == 'SELECT_DISTINCT')
+ {
+ $sql .= 'SELECT DISTINCT';
+ }
+ else
+ {
+ $sql .= 'SELECT';
+ }
+
+ $sql .= ' ' . $array['SELECT'];
+ $sql .= ' FROM ';
+
+ $table_array = array();
+ foreach ($array['FROM'] as $table_name => $alias)
+ {
+ $table_array[] = $table_name . ' ' . $alias;
+ }
+
+ $sql .= $this->_sql_custom_build('FROM', implode(', ', $table_array));
+
+ if (!empty($array['LEFT_JOIN']))
+ {
+ foreach ($array['LEFT_JOIN'] as $join)
+ {
+ $sql .= ' LEFT JOIN ' . key($join['FROM']) . ' ' . current($join['FROM']) . ' ON (' . $join['ON'] . ')';
+ }
+ }
+
+ if (!empty($array['WHERE']))
+ {
+ $sql .= ' WHERE ' . $this->_sql_custom_build('WHERE', $array['WHERE']);
+ }
+
+ if (!empty($array['GROUP_BY']))
+ {
+ $sql .= ' GROUP BY ' . $array['GROUP_BY'];
+ }
+
+ if (!empty($array['ORDER_BY']))
+ {
+ $sql .= ' ORDER BY ' . $array['ORDER_BY'];
+ }
+
+ break;
+ }
+ return $sql;
+ }
+
+ /**
* display sql error page
*/
function sql_error($sql = '')