Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
DALTruncateParser.inc
1 <?php
13 require_once 'DAL/Parsers/DALQueryParser.inc';
14 require_once 'DAL/DALBaker.inc';
15 require_once 'DAL/Parsers/DALWhereParser.inc';
16 
27 {
28 
29 
38  private function __construct()
39  {
40 
41  }//end __construct()
42 
43 
58  public static function parse(DomElement $xmlQuery)
59  {
60  $query = array();
61  $deleteTag = $xmlQuery->getElementsByTagName('truncate')->item(0);
62 
63  if ($deleteTag !== NULL) {
64  $query['TRUNCATE'] = array();
65 
66  // There must be a where tag and should have been checked before.
67  $tableTag = $deleteTag->getElementsByTagName('table')->item(0);
68  $query['TRUNCATE']['from'] = $tableTag->nodeValue;
69  }//end if
70 
71  return $query;
72 
73  }//end parse()
74 
75 
89  public static function validate(DomElement $query)
90  {
91  $deleteTag = $query->getElementsByTagName('truncate')->item(0);
92  if ($deleteTag === NULL) {
93  throw new DALParserException('Truncate tag not found.');
94  }
95 
96  // Must have where tag.
97  $tableTag = $deleteTag->getElementsByTagName('table')->item(0);
98  if ($tableTag === NULL) {
99  $msg = 'Truncate queries must have a table tag, specifying the table to be cleared.';
100  throw new DALParserException($msg);
101  } else if (trim($tableTag->nodeValue) === '') {
102  $msg = 'Truncate queries must have a table tag, specifying the table to be cleared.';
103  throw new DALParserException($msg);
104  }
105 
106  }//end validate()
107 
108 
109 }//end class
110 
111 ?>