13 require_once
'DAL/Parsers/DALQueryParser.inc';
14 require_once
'DAL/Parsers/DALOrderByParser.inc';
15 require_once
'DAL/Parsers/DALGroupByParser.inc';
16 require_once
'DAL/Parsers/DALWhereParser.inc';
17 require_once
'DAL/Parsers/DALFromParser.inc';
38 private function __construct()
52 public static function parse(DomElement $xmlQuery)
54 if (strtolower($xmlQuery->tagName) !==
'select') {
55 $selectTag = $xmlQuery->getElementsByTagName(
'select')->item(0);
57 $selectTag = $xmlQuery;
60 $query = self::_getSelectClause($selectTag);
82 if (empty($selectHooks) === FALSE) {
83 $query[
'HOOKS'] = $selectHooks;
107 private static function _getSelectClause(DomElement $select, $level=0)
109 $query[
'SELECT'] = array();
111 if (strtolower($select->getAttribute(
'distinct')) ===
'true') {
112 $query[
'SELECT'][
'distinct'] = TRUE;
116 $fieldsTag = $select->getElementsByTagName(
'fields')->item(0);
119 $query[
'SELECT'][
'FIELDS'] = self::parseChildFields($fieldsTag);
139 $selectTag = $query->getElementsByTagName(
'select');
142 $numSelects = $selectTag->length;
143 if ($numSelects === 0) {
146 $selectTag = $selectTag->item(0);
149 $fieldsTag = $selectTag->getElementsByTagName(
'fields');
150 if ($numSelects !== $fieldsTag->length) {
151 $msg =
'Each select query must have a fields tag.';
155 $fieldsTag = $fieldsTag->item(0);
156 if ($fieldsTag === NULL) {
160 $fields = $fieldsTag->getElementsByTagName(
'field');
162 foreach ($fields as $field) {
163 self::validateField($field, TRUE);
172 $fromTag = $selectTag->getElementsByTagName(
'from');
173 if ($fromTag !== NULL) {
174 $fromTag = $fromTag->item(0);
175 if ($fromTag !== NULL) {
177 $unionTag = self::getUnionTag($fromTag);
178 if ($unionTag === NULL) {
179 $tables = $fromTag->getElementsByTagName(
'table');
180 if ($tables->length === 0) {
181 $msg =
'No "table" tags found in "from" tag.';
184 foreach ($tables as $table) {
185 if ($table->nodeValue ===
'') {
186 $msg =
'table tag with empty value.';
193 $foundSelect = FALSE;
194 foreach ($unionTag->childNodes as $node) {
195 if ($node->nodeType !== XML_ELEMENT_NODE) {
199 if ($node->tagName ===
'select' || $node->tagName ===
'hook') {
205 if ($foundSelect === FALSE) {
206 $msg = strtoupper($unionTag->tagName);
207 $msg .=
' must have 1 or more SELECT queries or HOOKs.';
215 $whereTag = $selectTag->getElementsByTagName(
'where')->item(0);
216 if ($whereTag !== NULL) {