13 require_once
'DAL/Parsers/DALQueryParser.inc';
14 require_once
'DAL/Parsers/DALSelectParser.inc';
15 require_once
'XML/XML.inc';
36 private function __construct()
60 public static function parse(DomElement $xmlQuery)
63 $insertTag = $xmlQuery->getElementsByTagName(
'insert')->item(0);
64 if ($insertTag !== NULL) {
65 $query[
'INSERT'] = array();
68 $fieldsTag = $insertTag->getElementsByTagName(
'fields')->item(0);
69 if ($fieldsTag !== NULL) {
70 $query[
'INSERT'][
'into'] = $fieldsTag->getAttribute(
'table');
71 $query[
'INSERT'][
'FIELDS'] = array();
73 $fields = $fieldsTag->getElementsByTagName(
'field');
74 foreach ($fields as $field) {
75 $query[
'INSERT'][
'FIELDS'][] = $field->nodeValue;
80 $select = $insertTag->getElementsByTagName(
'select')->item(0);
81 if ($select === NULL || ($select->parentNode->tagName !==
'insert' && $select->parentNode->tagName !==
'values')) {
82 $query[
'INSERT'][
'VALUES'] = array();
84 $valuesTag = $insertTag->getElementsByTagName(
'values')->item(0);
85 foreach ($valuesTag->childNodes as $value) {
86 if ($value->nodeType === XML_ELEMENT_NODE) {
87 if ($value->tagName ===
'value') {
88 $vCol = $value->getAttribute(
'column');
92 $colVal = $value->nodeValue;
95 $query[
'INSERT'][
'VALUES'][$vCol] = $colVal;
125 $insertTag = $query->getElementsByTagName(
'insert')->item(0);
127 if ($insertTag === NULL) {
130 $fields = $insertTag->getElementsByTagName(
'fields')->item(0);
132 if ($fields === NULL) {
133 $msg =
'Insert query must have fields tag.';
135 }
else if ($fields->parentNode->tagName ===
'insert') {
137 if ($fields->getAttribute(
'table') ===
'') {
138 $msg =
'Fields tag must have table attribute.';
144 $valsTag = $insertTag->getElementsByTagName(
'values')->item(0);
145 if ($valsTag !== NULL) {
146 self::validateFieldsTag($fields);
147 if ($valsTag->parentNode->tagName ===
'insert') {
150 self::validateValuesTag($valsTag);
154 $selTag = $insertTag->getElementsByTagName(
'select')->item(0);
155 if ($selTag !== NULL) {
156 if ($selTag->parentNode->tagName ===
'insert') {
164 $msg =
'Insert query must have values or select tag.';
170 $msg =
'Inser query must have fields tag.';