summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDeven Bansod <devenbansod.bits@gmail.com>2016-09-24 23:04:01 +0530
committerDeven Bansod <devenbansod.bits@gmail.com>2016-09-27 01:15:06 +0530
commit98679cb7ed977d2b0d6cfa4b27c7964d41dc5c44 (patch)
treec40688475c133aee7380eae458bbbd75069129a2 /src
parent0fb198f38657741b928580c94055d199c754b0ce (diff)
downloadsql-parser-98679cb7ed977d2b0d6cfa4b27c7964d41dc5c44.zip
sql-parser-98679cb7ed977d2b0d6cfa4b27c7964d41dc5c44.tar.gz
sql-parser-98679cb7ed977d2b0d6cfa4b27c7964d41dc5c44.tar.bz2
Fixed some errors and add new tests
Signed-off-by: Deven Bansod <devenbansod.bits@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/Components/Limit.php6
-rw-r--r--src/Statements/DeleteStatement.php50
2 files changed, 21 insertions, 35 deletions
diff --git a/src/Components/Limit.php b/src/Components/Limit.php
index f69531f..743fa98 100644
--- a/src/Components/Limit.php
+++ b/src/Components/Limit.php
@@ -127,10 +127,6 @@ class Limit extends Component
*/
public static function build($component, array $options = array())
{
- if (count($component->offset) === 0) {
- return (string) $component->rowCount;
- } else {
- return $component->offset . ', ' . $component->rowCount;
- }
+ return $component->offset . ', ' . $component->rowCount;
}
}
diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php
index 119b5f5..fac7655 100644
--- a/src/Statements/DeleteStatement.php
+++ b/src/Statements/DeleteStatement.php
@@ -180,6 +180,13 @@ class DeleteStatement extends Statement
*/
$state = 0;
+ /**
+ * If the query is multi-table or not
+ *
+ * @var bool $multiTable
+ */
+ $multiTable = false;
+
for (; $list->idx < $list->count; ++$list->idx) {
/**
* Token parsed at this moment.
@@ -193,11 +200,6 @@ class DeleteStatement extends Statement
break;
}
- // Skipping whitespaces and comments.
- if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) {
- continue;
- }
-
if ($state === 0) {
if ($token->type === Token::TYPE_KEYWORD
&& $token->value !== 'FROM'
@@ -226,9 +228,6 @@ class DeleteStatement extends Statement
++$list->idx; // Skip 'FROM'
$this->from = ExpressionArray::parse($parser, $list);
$state = 2;
- } elseif ($token->type === Token::TYPE_KEYWORD) {
- $parser->error(__('Unexpected keyword.'), $token);
- break;
} else {
$parser->error(__('Unexpected token.'), $token);
break;
@@ -237,9 +236,11 @@ class DeleteStatement extends Statement
if ($token->type === Token::TYPE_KEYWORD
&& $token->value === 'USING'
) {
- ++$list->idx; // Skip 'FROM'
+ ++$list->idx; // Skip 'USING'
$this->using = ExpressionArray::parse($parser, $list);
$state = 3;
+
+ $multiTable = true;
} elseif ($token->type === Token::TYPE_KEYWORD
&& $token->value === 'WHERE'
) {
@@ -261,9 +262,6 @@ class DeleteStatement extends Statement
} elseif ($token->type === Token::TYPE_KEYWORD) {
$parser->error(__('Unexpected keyword.'), $token);
break;
- } else {
- $parser->error(__('Unexpected token.'), $token);
- break;
}
} elseif ($state === 3) {
if ($token->type === Token::TYPE_KEYWORD
@@ -272,18 +270,6 @@ class DeleteStatement extends Statement
++$list->idx; // Skip 'WHERE'
$this->where = Condition::parse($parser, $list);
$state = 4;
- } elseif ($token->type === Token::TYPE_KEYWORD
- && $token->value === 'ORDER BY'
- ) {
- ++$list->idx; // Skip 'ORDER BY'
- $this->order = OrderKeyword::parse($parser, $list);
- $state = 5;
- } elseif ($token->type === Token::TYPE_KEYWORD
- && $token->value === 'LIMIT'
- ) {
- ++$list->idx; // Skip 'LIMIT'
- $this->limit = Limit::parse($parser, $list);
- $state = 6;
} elseif ($token->type === Token::TYPE_KEYWORD) {
$parser->error(__('Unexpected keyword.'), $token);
break;
@@ -292,6 +278,16 @@ class DeleteStatement extends Statement
break;
}
} elseif ($state === 4) {
+ if ($multiTable === true
+ && $token->type === Token::TYPE_KEYWORD
+ ) {
+ $parser->error(
+ __('This type of clause is not valid in Multi-table queries.'),
+ $token
+ );
+ break;
+ }
+
if ($token->type === Token::TYPE_KEYWORD
&& $token->value === 'ORDER BY'
) {
@@ -307,9 +303,6 @@ class DeleteStatement extends Statement
} elseif ($token->type === Token::TYPE_KEYWORD) {
$parser->error(__('Unexpected keyword.'), $token);
break;
- } else {
- $parser->error(__('Unexpected token.'), $token);
- break;
}
} elseif ($state === 5) {
if ($token->type === Token::TYPE_KEYWORD
@@ -321,9 +314,6 @@ class DeleteStatement extends Statement
} elseif ($token->type === Token::TYPE_KEYWORD) {
$parser->error(__('Unexpected keyword.'), $token);
break;
- } else {
- $parser->error(__('Unexpected token.'), $token);
- break;
}
}
}