13 require_once
'DAL/Parsers/DALQueryParser.inc';
14 require_once
'DAL/Parsers/DALSchemaParser.inc';
35 private function __construct()
49 public static function parse(DomElement $xmlQuery)
52 $alterTag = $xmlQuery->getElementsByTagName(
'alter')->item(0);
53 if ($alterTag !== NULL) {
54 $query[
'ALTER'] = array();
56 $query[
'ALTER'][
'table'] = $alterTag->getAttribute(
'table');
59 foreach ($alterTag->childNodes as $alter) {
60 if ($alter->nodeType === XML_ELEMENT_NODE) {
62 switch ($alter->tagName) {
64 case 'modify-column' :
69 $info = $alter->nodeValue;
71 case 'rename-column' :
73 $info[
'OLD'] = $alter->getAttribute(
'old');
74 $info[
'NEW'] = $alter->nodeValue;
78 $info[
'OLD'] = $alter->getAttribute(
'old');
79 $info[
'NEW'] = $alter->nodeValue;
81 case 'add-constraint' :
84 case 'drop-constraint' :
85 $info = $alter->nodeValue;
89 $query[
'ALTER'][strtoupper($alter->tagName)] = $info;
118 $alterTag = $query->getElementsByTagName(
'alter')->item(0);
119 if ($alterTag === NULL) {
123 if ($alterTag->getAttribute(
'table') ===
'') {
124 $msg =
'Alter tag must have table attribute.';
129 foreach ($alterTag->childNodes as $alter) {
130 if ($alter->nodeType === XML_ELEMENT_NODE) {
133 switch ($alter->tagName) {
135 case 'modify-column' :
139 if ($alter->nodeValue ===
'') {
140 $msg =
'drop-column tag must have a value.';
145 case 'rename-column' :
146 if ($alter->nodeValue ===
'') {
147 $msg =
'rename-column tag must have a value.';
151 if ($alter->getAttribute(
'old') ===
'') {
152 $msg =
'rename-column tag must have a old attr.';
157 case 'rename-table' :
158 if ($alter->nodeValue ===
'') {
159 $msg =
'rename-table tag must have a value.';
163 if ($alter->getAttribute(
'old') ===
'') {
164 $msg =
'rename-table tag must have a old attr.';
169 case 'add-constraint' :
172 case 'drop-constraint' :
173 if ($alter->nodeValue ===
'') {
174 $msg =
'drop-constraint tag must have a value.';
180 $msg =
'Invalid ALTER TABLE tag: '.$alter->tagName;
187 if ($emptyTag === TRUE) {
188 $msg =
'Empty alter tag found.';