Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
DALSchemaParser.inc
1 <?php
13 require_once 'DAL/Parsers/DALQueryParser.inc';
14 require_once 'DAL/DALBaker.inc';
15 
24 {
25 
33  private static $_requiresSizeAttr = array(
34  'VARCHAR',
35  'CHAR',
36  'NUMERIC',
37  'DECIMAL',
38  'FLOAT',
39  );
40 
47  private static $_columnDataTypes = array(
48  'CHAR',
49  'VARCHAR',
50  'CLOB',
51  'BLOB',
52  'NUMERIC',
53  'DECIMAL',
54  'INTEGER',
55  'SMALLINT',
56  'REAL',
57  'DOUBLE PRECISION',
58  'FLOAT',
59  'BOOLEAN',
60  'DATE',
61  'TIME WITH TIME ZONE',
62  'TIME WITHOUT TIME ZONE',
63  'TIMESTAMP WITH TIME ZONE',
64  'TIMESTAMP WITHOUT TIME ZONE',
65  'INTERVAL',
66  );
67 
74  private static $_udts = array();
75 
76 
84  private function __construct()
85  {
86 
87  }//end __construct()
88 
89 
98  public static function parse(DomElement $schema)
99  {
100  self::validate($schema);
101 
102  // Schema is valid, start parsing.
103  $query['CREATE'] = array();
104  $tables = $schema->getElementsByTagName('table');
105  self::$_udts = self::getSchemaUdts($schema);
106 
107  foreach ($tables as $table) {
108  $current = array();
109  $current['table'] = $table->getAttribute('name');
110  $current['COLUMNS'] = self::getTableColumns($table);
111  $current['INDEXES'] = self::getTableIndexes($table);
112  $current['CONSTRAINTS'] = self::getTableConstraints($table);
113  $current['SEQUENCES'] = self::getTableSequences($table);
114 
115  $query['CREATE'][] = $current;
116  }
117 
118  return $query;
119 
120  }//end parse()
121 
122 
131  public static function getSchemaUdts(DomElement $schema)
132  {
133  $schemaUdts = array(
134  'LOCAL' => array(),
135  'IMPORTED' => array()
136  );
137 
138  $udtsTag = $schema->getElementsByTagName('udts')->item(0);
139  if ($udtsTag !== NULL) {
140  // Get the local udts.
141  $ludts = $udtsTag->getElementsByTagName('udt');
142  foreach ($ludts as $udt) {
143  $current = array();
144  $current['type'] = $udt->getAttribute('type');
145  $current['size'] = $udt->getAttribute('size');
146  $current['scale'] = $udt->getAttribute('scale');
147 
148  $schemaUdts['LOCAL'][$udt->nodeValue] = $current;
149  }
150 
151  // Get the imported udts.
152  $ludts = $udtsTag->getElementsByTagName('udt-import');
153  foreach ($ludts as $udt) {
154  $current = array();
155  $current['system'] = $udt->getAttribute('system');
156 
157  $schemaUdts['IMPORTED'][$udt->nodeValue] = $current;
158  }
159  }//end if
160 
161  return $schemaUdts;
162 
163  }//end getSchemaUdts()
164 
165 
174  public static function getTableSequences(DomElement $table)
175  {
176  $squencesTag = $table->getElementsByTagName('sequences')->item(0);
177  $sequences = array();
178 
179  if ($squencesTag !== NULL) {
180  $seqs = $squencesTag->getElementsByTagName('sequence');
181  foreach ($seqs as $seq) {
182  $sequences[] = $seq->getAttribute('name');
183  }
184  }
185 
186  return $sequences;
187 
188  }//end getTableSequences()
189 
190 
199  public static function getConstraintsFromParent(DomElement $parent)
200  {
201  $keys = self::_getPrimaryKeyConstraints($parent);
202  if (empty($keys) === FALSE) {
203  $constraints['PRIMARY-KEYS'] = $keys;
204  }
205 
206  $keys = self::_getForeignKeyConstraints($parent);
207  if (empty($keys) === FALSE) {
208  $constraints['FOREIGN-KEYS'] = $keys;
209  }
210 
211  $keys = self::_getUniqueConstraints($parent);
212  if (empty($keys) === FALSE) {
213  $constraints['UNIQUES'] = $keys;
214  }
215 
216  return $constraints;
217 
218  }//end getConstraintsFromParent()
219 
220 
229  public static function getTableConstraints(DomElement $table)
230  {
231  $constraints = array();
232  $constraintsTag = $table->getElementsByTagName('constraints')->item(0);
233 
234  if ($constraintsTag === NULL) {
235  return $constraints;
236  }
237 
238  $constraints = self::getConstraintsFromParent($constraintsTag);
239 
240  return $constraints;
241 
242  }//end getTableConstraints()
243 
244 
253  private static function _getPrimaryKeyConstraints(DomElement $parent)
254  {
255  // Primary key constraints.
256  $pks = $parent->getElementsByTagName('primary-key');
257 
258  $primaryKeys = array();
259  foreach ($pks as $pk) {
260  $current = array();
261  $current['name'] = $pk->getAttribute('name');
262  $current['COLUMNS'] = array();
263 
264  $columns = $pk->getElementsByTagName('column');
265  foreach ($columns as $column) {
266  $current['COLUMNS'][] = $column->nodeValue;
267  }
268 
269  $primaryKeys[] = $current;
270  }
271 
272  return $primaryKeys;
273 
274  }//end _getPrimaryKeyConstraints()
275 
276 
285  private static function _getForeignKeyConstraints(DomElement $parent)
286  {
287  // Foreign key constraints.
288  $fks = $parent->getElementsByTagName('foreign-key');
289 
290  $foreignKeys = array();
291  foreach ($fks as $fk) {
292  $current = array();
293  $current['name'] = $fk->getAttribute('name');
294  $current['table'] = $fk->getAttribute('foreign-table');
295  $onDelete = $fk->getAttribute('on-delete');
296  if ($onDelete === '') {
297  $onDelete = 'NO ACTION';
298  }
299 
300  $current['on-delete'] = $onDelete;
301  $current['COLUMNS'] = array();
302 
303  $columns = $fk->getElementsByTagName('column');
304  foreach ($columns as $column) {
305  $col['name'] = $column->nodeValue;
306  $col['references'] = $column->getAttribute('references');
307  $current['COLUMNS'][] = $col;
308  }
309 
310  $foreignKeys[] = $current;
311  }//end foreach
312 
313  return $foreignKeys;
314 
315  }//end _getForeignKeyConstraints()
316 
317 
326  private static function _getUniqueConstraints(DomElement $parent)
327  {
328  // Unique constraints.
329  $uns = $parent->getElementsByTagName('unique');
330 
331  $uniques = array();
332  foreach ($uns as $uq) {
333  $current = array();
334  $current['name'] = $uq->getAttribute('name');
335  $columns = $uq->getElementsByTagName('column');
336  foreach ($columns as $column) {
337  $current['COLUMNS'][] = $column->nodeValue;
338  }
339 
340  $uniques[] = $current;
341  }
342 
343  return $uniques;
344 
345  }//end _getUniqueConstraints()
346 
347 
356  public static function getTableIndexes(DomElement $table)
357  {
358  $indexesTag = $table->getElementsByTagName('indexes')->item(0);
359  $idx = array();
360 
361  if ($indexesTag !== NULL) {
362  $indexes = $indexesTag->getElementsByTagName('index');
363  foreach ($indexes as $index) {
364  $current = array();
365  $current['name'] = $index->getAttribute('name');
366  $current['COLUMNS'] = array();
367 
368  $columns = $index->getElementsByTagName('column');
369  foreach ($columns as $column) {
370  $current['COLUMNS'][] = $column->nodeValue;
371  }
372 
373  $idx[] = $current;
374  }
375  }
376 
377  return $idx;
378 
379  }//end getTableIndexes()
380 
381 
394  private static function _getColumnFromUdt(DomElement $column, array $udts)
395  {
396  $type = $column->getAttribute('type');
397  $newColumn['type'] = $udts[$type]['type'];
398  $newColumn['size'] = $udts[$type]['size'];
399  $newColumn['scale'] = $udts[$type]['scale'];
400 
401  return $newColumn;
402 
403  }//end _getColumnFromUdt()
404 
405 
415  public static function getTableColumns(DomElement $table)
416  {
417  // Get the columns tag.
418  $cols = array();
419  $columnsTag = $table->getElementsByTagName('columns')->item(0);
420  if ($columnsTag !== NULL) {
421  $columns = $columnsTag->getElementsByTagName('column');
422  foreach ($columns as $column) {
423 
424  // Check to see if we have any columns that are in our local
425  // or imported UDT list.
426  if ((isset(self::$_udts['LOCAL']) === TRUE) && (in_array($column->getAttribute('type'), array_keys(self::$_udts['LOCAL'])) === TRUE)) {
427  // Covert the column from its UDT type to its Generic DB type.
428  $current = self::_getColumnFromUdt($column, self::$_udts['LOCAL']);
429  } else if ((isset(self::$_udts['IMPORTED']) === TRUE) && (in_array($column->getAttribute('type'), array_keys(self::$_udts['IMPORTED'])) === TRUE)) {
430 
431  // We have a imported UDT so we have to get the local UDTs
432  // from the imported system so that we can convert it into
433  // its generic DB type.
434  $systemName = self::$_udts['IMPORTED'][$column->getAttribute('type')]['system'];
435  $schemaDoc = DALBaker::getSystemSchemaDocument($systemName);
436 
437  if ($schemaDoc === NULL) {
438  $msg = 'Imported UDT from the system "'.$schemaName.'" without a schema.xml';
439  throw new DALParserException($msg);
440  }
441 
442  $schemaNode = $schemaDoc->getElementsByTagName('schema')->item(0);
443  $udts = self::getSchemaUdts($schemaNode);
444  $current = self::_getColumnFromUdt($column, $udts['LOCAL']);
445  } else {
446  // It's just a normal type.
447  $current = array();
448  $current['type'] = $column->getAttribute('type');
449  $current['size'] = $column->getAttribute('size');
450  $current['scale'] = $column->getAttribute('scale');
451 
452  }//end if
453 
454  $current['name'] = $column->nodeValue;
455  $current['allow-null'] = $column->getAttribute('allow-null');
456  $current['default'] = $column->getAttribute('default');
457 
458  $cols[] = $current;
459  }//end foreach
460  }//end if
461 
462  return $cols;
463 
464  }//end getTableColumns()
465 
466 
467  /*
468  Schema Validation
469  */
470 
471 
485  public static function validate(DomElement $schema)
486  {
487  // Make sure this is a schema.
488  if ($schema->tagName !== 'schema') {
489  throw new DALParserException('Given DomElements is not a schema.');
490  }
491 
492  // All tables need to have name attribute and valid columns.
493  $tables = $schema->getElementsByTagName('table');
494 
495  // Validate UDTs.
496  self::validateSchemaUdts($schema);
497 
498  foreach ($tables as $table) {
499  self::validateTable($table);
500  }
501 
502  }//end validate()
503 
504 
518  public static function validateTable(DomElement $table)
519  {
520  if ($table->getAttribute('name') === '') {
521  $msg = 'One of the tables does not contain "name" attribute.';
522  throw new DALParserException($msg);
523  }
524 
525  // Validate this tables columns.
526  self::validateTableColumns($table);
527 
528  // Validate constraints.
529  self::validateTableConstraints($table);
530 
531  // Validate Indexes.
532  self::validateTableIndexes($table);
533 
534  // Validate Sequences.
535  self::validateTableSequences($table);
536 
537  }//end validateTable()
538 
539 
551  public static function validateTableColumns(DomElement $table)
552  {
553  // Get table's columns.
554  $columnsTag = $table->getElementsByTagName('columns')->item(0);
555  $tableName = $table->getAttribute('name');
556  if ($tableName === '') {
557  $tableName = $table->getAttribute('table');
558  }
559 
560  if ($columnsTag === NULL) {
561  $msg = $tableName.'\'s table has no columns.';
562  throw new DALParserException($msg);
563  }
564 
565  $cols = $columnsTag->getElementsByTagName('column');
566 
567  if ($cols->length === 0) {
568  $msg = $tableName.'\'s table has no columns.';
569  throw new DALParserException($msg);
570  }
571 
572  $msg = $tableName.'\'s table column at #';
573 
574  // Check column attributes.
575  $attr = 1;
576  foreach ($cols as $col) {
577  $type = $col->getAttribute('type');
578  if ($type === '') {
579  $msg .= $attr.' does not have "type" attribute.';
580  throw new DALParserException($msg);
581  } else {
582  self::validSchemaColumnType($table, $type);
583  }
584 
585  if (in_array($type, self::$_requiresSizeAttr) === TRUE) {
586  $size = $col->getAttribute('size');
587  if ($size === '') {
588  $msg .= $attr.' does not have "size" attribute.';
589  throw new DALParserException($msg);
590  }
591  }
592 
593  // If type is NUMERIC then we need scale attribute.
594  if ($type === 'NUMERIC') {
595  if ($col->getAttribute('scale') === '') {
596  $msg .= $attr.' is type NUMERIC and it does not have';
597  $msg .= ' "scale" attribute.';
598  throw new DALParserException($msg);
599  }
600  }
601 
602  if ($col->nodeValue === '') {
603  $msg .= $attr.' does not have a column name.';
604  throw new DALParserException($msg);
605  }
606 
607  $attr++;
608  }//end foreach
609 
610  }//end validateTableColumns()
611 
612 
624  public static function validSchemaColumnType(DomElement $table, $type)
625  {
626  // If type is not uppercase then its not valid.
627  if (strtoupper($type) !== $type) {
628  return FALSE;
629  }
630 
631  // Check if this is in available column types.
632  if (in_array($type, self::$_columnDataTypes) === TRUE) {
633  return TRUE;
634  }
635 
636  // Get the owner document.
637  $doc = $table->ownerDocument;
638 
639  // Check udts.
640  $xpath = new DomXpath($doc);
641  $query = '//schema/udts[udt="'.$type.'" or udt-import="'.$type.'"]';
642  $result = $xpath->query($query);
643 
644  if ($result->length > 0) {
645  return TRUE;
646  }
647 
648  return FALSE;
649 
650  }//end validSchemaColumnType()
651 
652 
665  public static function validateTableConstraints(DomElement $table)
666  {
667  $constTag = $table->getElementsByTagName('constraints')->item(0);
668  $tableName = $table->getAttribute('name');
669  $msg = $tableName.'\'s table';
670 
671  if ($constTag === NULL) {
672  $msg .= ' does not have "constraints".';
673  throw new DALParserException($msg);
674  }
675 
676  // Check general constraint rules.
677  self::validateConstraints($constTag, $msg);
678 
679  // Additional Primary Key checks.
680  $pks = $constTag->getElementsByTagName('primary-key');
681  if ($pks->length !== 1) {
682  $msg .= ' must have a primary-key.';
683  throw new DALParserException($msg);
684  } else {
685  foreach ($pks as $pk) {
686  $cols = $pk->getElementsByTagName('column');
687  // Each of the columns here must be defined in table columns.
688  foreach ($cols as $col) {
689  if (self::tableHasColumn($table, $col->nodeValue) === FALSE) {
690  $msg .= ' does not have column "'.$col->nodeValue;
691  $msg .= '", but it was used in its primary-key.';
692  throw new DALParserException($msg);
693  }
694  }
695  }
696  }//end else
697 
698  // Additional Foreign Key checks.
699  // Check if table has already defined this column name.
700  $fks = $constTag->getElementsByTagName('foreign-key');
701  $keyPosition = 1;
702  foreach ($fks as $fk) {
703  $cols = $fk->getElementsByTagName('column');
704  if ($cols !== NULL) {
705  $colLoc = 1;
706  foreach ($cols as $col) {
707  $colVal = $col->nodeValue;
708  if (self::tableHasColumn($table, $colVal) === FALSE) {
709  $msg .= ' foreign-key #'.$keyPosition;
710  $msg .= ' has column (#'.$colLoc.')';
711  $msg .= ' with column name that was NOT defined in';
712  $msg .= ' table columns. Name: '.$colVal;
713  throw new DALParserException($msg);
714  }
715 
716  $colLoc++;
717  }
718  }
719 
720  $keyPosition++;
721  }
722 
723  // Additional unique Key checks.
724  $uniques = $constTag->getElementsByTagName('unique');
725  foreach ($uniques as $unique) {
726  $cols = $unique->getElementsByTagName('column');
727  if ($cols !== NULL) {
728  foreach ($cols as $col) {
729  $colVal = $col->nodeValue;
730  if (self::tableHasColumn($table, $colVal) === FALSE) {
731  $msg .= ' does not have column "'.$colVal;
732  $msg .= '", but it was used in its unique constraint.';
733  throw new DALParserException($msg);
734  }
735  }
736  }
737  }
738 
739  }//end validateTableConstraints()
740 
741 
751  public static function validateConstraints(DomElement $parent, $prefix='')
752  {
753  // Primary Keys.
754  $pks = $parent->getElementsByTagName('primary-key');
755  foreach ($pks as $pk) {
756  self::_validatePrimaryKeyConstraint($pk, $prefix);
757  }
758 
759  // Foreign Keys.
760  $fks = $parent->getElementsByTagName('foreign-key');
761  $keyPosition = 1;
762  foreach ($fks as $fk) {
763  self::_validateForeignKeyConstraint($fk, $keyPosition, $prefix);
764  $keyPosition++;
765  }
766 
767  // Unique constraints.
768  $uniques = $parent->getElementsByTagName('unique');
769  $keyPosition = 1;
770  foreach ($uniques as $unique) {
771  self::_validateUniqueConstraint($unique, $keyPosition, $prefix);
772  $keyPosition++;
773  }
774 
775  }//end validateConstraints()
776 
777 
789  private static function _validatePrimaryKeyConstraint(DomElement $pk, $prefix='')
790  {
791  $msg = $prefix;
792  // Check that it has name attribute.
793  if ($pk->getAttribute('name') === '') {
794  $msg .= ' primary-key does not have "name" attribute.';
795  throw new DALParserException($msg);
796  }
797 
798  // Check that it has columns.
799  $cols = $pk->getElementsByTagName('column');
800  if ($cols->length === 0) {
801  $msg .= ' has no columns defined for its primary-key.';
802  throw new DALParserException($msg);
803  }
804 
805  }//end _validatePrimaryKeyConstraint()
806 
807 
819  private static function _validateForeignKeyConstraint(DomElement $fk, $keyPosition, $prefix='')
820  {
821  $msg = $prefix;
822 
823  if ($fk->getAttribute('name') === '') {
824  $msg .= ' foreign-key #'.$keyPosition;
825  $msg .= ' does not have "name" attribute.';
826  throw new DALParserException($msg);
827  }
828 
829  if ($fk->getAttribute('foreign-table') === '') {
830  $msg .= ' foreign-key #'.$keyPosition;
831  $msg .= ' does not have "foreign-table" attribute.';
832  throw new DALParserException($msg);
833  } else {
834  // Check that foreign-table exists?
835  }
836 
837  // Check on-delete attribute value.
838  $onDelete = $fk->getAttribute('on-delete');
839  if ($onDelete !== '') {
840  if (($onDelete !== 'CASCADE') && ($onDelete !== 'NO ACTION')) {
841  $msg .= ' foreign-key #'.$keyPosition;
842  $msg .= ' has invalid on-delete attribute value.';
843  throw new DALParserException($msg);
844  }
845  }
846 
847  // Check each column for this fk.
848  $cols = $fk->getElementsByTagName('column');
849  if ($cols->length === 0) {
850  $msg .= ' foreign-key #'.$keyPosition.' does not have columns.';
851  throw new DALParserException($msg);
852  } else {
853  $colLoc = 1;
854  foreach ($cols as $col) {
855  if ($col->getAttribute('references') === '') {
856  $msg .= ' foreign-key #'.$keyPosition;
857  $msg .= ' has column (#'.$colLoc.')';
858  $msg .= ' with missing references attribute.';
859  throw new DALParserException($msg);
860  } else {
861  // Check if foreign table has this column?
862  }
863 
864  $colVal = $col->nodeValue;
865  if ($colVal === '') {
866  $msg .= ' foreign-key #'.$keyPosition;
867  $msg .= ' has column (#'.$colLoc.')';
868  $msg .= ' with missing content.';
869  throw new DALParserException($msg);
870  }
871 
872  $colLoc++;
873  }//end foreach foreign-key columns
874  }//end if
875 
876  }//end _validateForeignKeyConstraint()
877 
878 
891  private static function _validateUniqueConstraint(DomElement $unique, $keyPosition, $prefix='')
892  {
893  $msg = $prefix;
894 
895  if ($unique->getAttribute('name') === '') {
896  $msg .= ' unique constraint #'.$keyPosition;
897  $msg .= ' does not have "name" attribute.';
898  throw new DALParserException($msg);
899  }
900 
901  $cols = $unique->getElementsByTagName('column');
902  if ($cols->length === 0) {
903  $msg .= 'unique constraint #'.$keyPosition.' does now have columns.';
904  throw new DALParserException($msg);
905  }
906 
907  }//end _validateUniqueConstraint()
908 
909 
923  public static function validateTableIndexes(DomElement $table)
924  {
925  $tableName = $table->getAttribute('name');
926  $msg = $tableName.'\'s table';
927 
928  // Get the indexes.
929  $indexes = $table->getElementsByTagName('indexes');
930  if ($indexes->length !== 0) {
931  $indexes = $indexes->item(0)->getElementsByTagName('index');
932  foreach ($indexes as $index) {
933  if ($index->getAttribute('name') === '') {
934  $msg .= ' has index with missing "name" attribute.';
935  throw new DALParserException($msg);
936  }
937 
938  $cols = $index->getElementsByTagName('column');
939  if ($cols->length === 0) {
940  $msg .= ' has index with no columns.';
941  throw new DALParserException($msg);
942  } else {
943  foreach ($cols as $col) {
944  $colVal = $col->nodeValue;
945  if (self::tableHasColumn($table, $colVal) === FALSE) {
946  $msg .= ' does not have column "'.$colVal;
947  $msg .= '" but it was used in its index.';
948  throw new DALParserException($msg);
949  }
950  }
951  }
952  }//end foreach indexes
953  }//end if indexes !== NULL
954 
955  }//end validateTableIndexes()
956 
957 
970  public static function validateTableSequences(DomElement $table)
971  {
972  $tableName = $table->getAttribute('name');
973  $msg = $tableName.'\'s table';
974 
975  // Get the indexes.
976  $seqsTag = $table->getElementsByTagName('sequences');
977  if ($seqsTag->length !== 0) {
978  $seqs = $seqsTag->item(0)->getElementsByTagName('sequence');
979  if ($seqs->length === 0) {
980  $msg .= ' has sequences tag with no sequence tags.';
981  throw new DALParserException($msg);
982  }
983 
984  foreach ($seqs as $seq) {
985  if ($seq->getAttribute('name') === '') {
986  $msg .= ' has sequence with missing "name" attribute.';
987  throw new DALParserException($msg);
988  }
989  }//end foreach
990  }//end if
991 
992  }//end validateTableSequences()
993 
994 
1006  public static function validateSchemaUdts(DomElement $schema)
1007  {
1008  $msg = 'Schema "'.$schema->getAttribute('system').'" ';
1009 
1010  // Get schema User Defined Types (UDTs).
1011  $udtsTag = $schema->getElementsByTagName('udts');
1012 
1013  if ($udtsTag->length !== 0) {
1014  // Get local UDTs.
1015  $ludts = $udtsTag->item(0)->getElementsByTagName('udt');
1016 
1017  if ($ludts->length !== 0) {
1018  foreach ($ludts as $ludt) {
1019  // UDTs must be in uppercase.
1020  $var = $ludt->nodeValue;
1021  if ($var !== strtoupper($var)) {
1022  $msg .= ' has UDT with an invalid name "'.$var.'".';
1023  $msg .= ' Expected "'.strtoupper($var).'".';
1024  throw new DALParserException($msg);
1025  }
1026 
1027  $type = $ludt->getAttribute('type');
1028  if ($type === '') {
1029  $msg .= ' has UDT with no type attribute.';
1030  throw new DALParserException($msg);
1031  }
1032 
1033  if (in_array($type, self::$_requiresSizeAttr) === TRUE) {
1034  if ($ludt->getAttribute('size') === '') {
1035  $msg .= ' has '.$type.' UDT with no size attr.';
1036  throw new DALParserException($msg);
1037  }
1038  }
1039 
1040  if ($type === 'NUMERIC') {
1041  if ($ludt->getAttribute('scale') === '') {
1042  $msg .= ' has NUMERIC UDT with no scale attr.';
1043  throw new DALParserException($msg);
1044  }
1045  }
1046  }//end foreach ludts
1047  }//end if
1048 
1049  // Get foreign UDTs.
1050  $fudts = $udtsTag->item(0)->getElementsByTagName('udt-import');
1051  if ($fudts->length !== 0) {
1052  foreach ($fudts as $fudt) {
1053  if ($fudt->getAttribute('system') === '') {
1054  $msg .= ' has foreign UDT with no "system" attribute';
1055  throw new DALParserException($msg);
1056  }
1057 
1058  $var = $fudt->nodeValue;
1059  if ($var !== strtoupper($var)) {
1060  $msg .= ' has foreign UDT with an invalid var name.';
1061  throw new DALParserException($msg);
1062  }
1063  }
1064  }
1065 
1066  }//end if
1067 
1068  }//end validateSchemaUdts()
1069 
1070 
1082  public static function tableHasColumn(DomElement $table, $columnName)
1083  {
1084  // Is this a table node?
1085  if ($table->tagName !== 'table') {
1086  $msg = 'tableHasColumn\'s first argument must be a table node.';
1087  throw new DALParserException($msg);
1088  }
1089 
1090  /*
1091  Check UDTs ? If yes, then change the fn name to schemaHasColumn().
1092  */
1093 
1094  // Check Table Columns.
1095  $cols = $table->getElementsByTagName('columns')->item(0);
1096  if ($cols !== NULL) {
1097  $cols = $cols->getElementsByTagName('column');
1098  foreach ($cols as $col) {
1099  if ($col->nodeValue === $columnName) {
1100  return TRUE;
1101  }
1102  }
1103  }
1104 
1105  return FALSE;
1106 
1107  }//end tableHasColumn()
1108 
1109 
1110 }//end class
1111 
1112 ?>