summaryrefslogtreecommitdiffstats
path: root/src/Fragments
diff options
context:
space:
mode:
Diffstat (limited to 'src/Fragments')
-rw-r--r--src/Fragments/DataTypeFragment.php4
-rw-r--r--src/Fragments/FieldDefFragment.php35
-rw-r--r--src/Fragments/OptionsFragment.php42
3 files changed, 40 insertions, 41 deletions
diff --git a/src/Fragments/DataTypeFragment.php b/src/Fragments/DataTypeFragment.php
index 7baefdd..740fbfd 100644
--- a/src/Fragments/DataTypeFragment.php
+++ b/src/Fragments/DataTypeFragment.php
@@ -88,8 +88,8 @@ class DataTypeFragment extends Fragment
}
if ($state === 0) {
- $ret->name = $token->value;
- if (!isset(Context::$DATA_TYPES[$token->value])) {
+ $ret->name = strtoupper($token->value);
+ if (($token->type !== Token::TYPE_KEYWORD) || (!($token->flags & Token::FLAG_KEYWORD_DATA_TYPE))) {
$parser->error('Unrecognized data type.', $token);
}
$state = 1;
diff --git a/src/Fragments/FieldDefFragment.php b/src/Fragments/FieldDefFragment.php
index ba4b6dc..f4a08bd 100644
--- a/src/Fragments/FieldDefFragment.php
+++ b/src/Fragments/FieldDefFragment.php
@@ -38,6 +38,7 @@ class FieldDefFragment extends Fragment
'UNIQUE KEY' => 4,
'COMMENT' => array(5, 'var'),
'COLUMN_FORMAT' => array(6, 'var'),
+ 'ON UPDATE' => array(7, 'var'),
);
/**
@@ -133,16 +134,14 @@ class FieldDefFragment extends Fragment
}
continue;
} elseif ($state === 1) {
- if (($token->type === Token::TYPE_KEYWORD) && ($token->flags & Token::FLAG_KEYWORD_RESERVED)) {
- if ($token->value === 'CONSTRAINT') {
- $state = 4;
- } elseif (isset(Context::$KEY_TYPES[$token->value])) {
- $expr->type = $token->value;
- $state = 5;
- } else {
- $parser->error('Unexpected keyword.', $token);
- break; // TODO: Skip to the end of the query.
- }
+ if (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'CONSTRAINT')) {
+ $state = 4;
+ } elseif (($token->type === Token::TYPE_KEYWORD) && ($token->flags & Token::FLAG_KEYWORD_KEY)) {
+ $expr->type = $token->value;
+ $state = 5;
+ } elseif (($token->type === Token::TYPE_KEYWORD) && ($token->flags & Token::FLAG_KEYWORD_RESERVED)) {
+ $parser->error('Unexpected keyword.', $token);
+ break; // TODO: Skip to the end of the query.
} else {
$expr->name = $token->value;
$state = 2;
@@ -154,17 +153,23 @@ class FieldDefFragment extends Fragment
$expr->options = OptionsFragment::parse($parser, $list, static::$FIELD_OPTIONS);
$state = 6;
} elseif ($state === 4) {
- if (!isset(Context::$KEY_TYPES[$token->value])) {
+ if (($token->type !== Token::TYPE_KEYWORD) || (!($token->flags & Token::FLAG_KEYWORD_KEY))) {
$expr->name = $token->value;
} else {
$expr->type = $token->value;
$state = 5;
}
} elseif ($state === 5) {
- $expr->indexes = ArrayFragment::parse($parser, $list);
- $state = 6;
+ if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) {
+ $expr->indexes = ArrayFragment::parse($parser, $list);
+ $state = 6;
+ } else {
+ $expr->name = $token->value;
+ }
} elseif ($state === 6) {
- $ret[] = $expr;
+ if (!empty($expr->type)) {
+ $ret[] = $expr;
+ }
$expr = new FieldDefFragment();
if ($token->value === ',') {
$state = 1;
@@ -178,7 +183,7 @@ class FieldDefFragment extends Fragment
}
// Last iteration was not saved.
- if (!empty($expr->name)) {
+ if (!empty($expr->type)) {
$ret[] = $expr;
}
diff --git a/src/Fragments/OptionsFragment.php b/src/Fragments/OptionsFragment.php
index f002f5b..dfb4fc9 100644
--- a/src/Fragments/OptionsFragment.php
+++ b/src/Fragments/OptionsFragment.php
@@ -70,30 +70,24 @@ class OptionsFragment extends Fragment
continue;
}
- if (isset($options[strtoupper($token->value)])) {
- $lastOption = $options[strtoupper($token->value)];
- $lastOptionId = is_array($lastOption) ? $lastOption[0] : $lastOption;
-
- // Checking for option conflicts.
- // For example, in `SELECT` statements the keywords `ALL` and `DISTINCT`
- // conflict and if used together, they produce an invalid query.
- // Usually, tokens can be identified in the array by the option ID,
- // but if conflicts occur, a psuedo option ID is used.
- // The first pseudo duplicate ID is the maximum value of the real
- // options (e.g. if there are 5 options, the first fake ID is 6).
- if (isset($ret->options[$lastOptionId])) {
- $parser->error('This option conflicts with \'' . $ret->options[$lastOptionId] . '\'.', $token);
- $lastOptionId = $lastAssignedId++;
- }
- } else {
- // There is no option to be processed.
- if ($lastOption === null) {
- break;
- }
-
- // The only keywords that are expected are those which are
- // options.
- if (($token->type === Token::TYPE_KEYWORD) && ($token->flags & Token::FLAG_KEYWORD_RESERVED)) {
+ if ($lastOption === null) {
+ if (isset($options[strtoupper($token->value)])) {
+ $lastOption = $options[strtoupper($token->value)];
+ $lastOptionId = is_array($lastOption) ? $lastOption[0] : $lastOption;
+
+ // Checking for option conflicts.
+ // For example, in `SELECT` statements the keywords `ALL` and `DISTINCT`
+ // conflict and if used together, they produce an invalid query.
+ // Usually, tokens can be identified in the array by the option ID,
+ // but if conflicts occur, a psuedo option ID is used.
+ // The first pseudo duplicate ID is the maximum value of the real
+ // options (e.g. if there are 5 options, the first fake ID is 6).
+ if (isset($ret->options[$lastOptionId])) {
+ $parser->error('This option conflicts with \'' . $ret->options[$lastOptionId] . '\'.', $token);
+ $lastOptionId = $lastAssignedId++;
+ }
+ } else {
+ // There is no option to be processed.
break;
}
}