+
+ // populate fields
+ foreach ($primaryXML->fieldName as $v) {
+ $fieldName = (string) ($v);
+ $length = (string) ($v['length']);
+ if (strlen($length) > 0) {
+ $fieldName = "$fieldName($length)";
+ }
+ $primaryKey['field'][] = $fieldName;
+ }
+
+ // when field array is empty set it to the name of the primary key.
+ if (empty($primaryKey['field'])) {
+ $primaryKey['field'][] = $name;
+ }
+
+ // all fieldnames have to be defined and should exist in schema.
+ foreach ($primaryKey['field'] as $fieldName) {
+ if (!$fieldName) {
+ echo "Invalid field defination for index $name\n";
+ return;
+ }
+ $parenOffset = strpos($fieldName, '(');
+ if ($parenOffset > 0) {
+ $fieldName = substr($fieldName, 0, $parenOffset);
+ }
+ if (!array_key_exists($fieldName, $fields)) {
+ echo "Table does not contain $fieldName\n";
+ print_r($fields);
+ exit();
+ }
+ }
+