summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-08-01 00:55:57 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-08-01 00:55:57 +0300
commit576b70df3dc93b7b723a9a16fafee5265ab95803 (patch)
tree0119e18117169984e85b36012339d1e65e37333a /src
parent67067a5f7dddc15aa818bfa2c1ede29fb4ced4a1 (diff)
downloadsql-parser-576b70df3dc93b7b723a9a16fafee5265ab95803.zip
sql-parser-576b70df3dc93b7b723a9a16fafee5265ab95803.tar.gz
sql-parser-576b70df3dc93b7b723a9a16fafee5265ab95803.tar.bz2
Fixed coding style.
Fixed a bug which caused an infinite loop when a invalid DELIMITER statement was provided.
Diffstat (limited to 'src')
-rw-r--r--src/Component.php4
-rw-r--r--src/Components/UnionKeyword.php4
-rw-r--r--src/Context.php5
-rw-r--r--src/Lexer.php17
-rw-r--r--src/Parser.php10
-rw-r--r--src/Statement.php4
-rw-r--r--src/Statements/SetStatement.php4
-rw-r--r--src/Statements/TransactionStatement.php7
-rw-r--r--src/UtfString.php2
9 files changed, 39 insertions, 18 deletions
diff --git a/src/Component.php b/src/Component.php
index 7291ca5..1678706 100644
--- a/src/Component.php
+++ b/src/Component.php
@@ -51,6 +51,8 @@ namespace SqlParser {
* @param TokensList $list The list of tokens that are being parsed.
* @param array $options Parameters for parsing.
*
+ * @throws \Exception Not implemented yet.
+ *
* @return mixed
*/
public static function parse(
@@ -69,6 +71,8 @@ namespace SqlParser {
*
* @param mixed $component The component to be built.
*
+ * @throws \Exception Not implemented yet.
+ *
* @return string
*/
public static function build($component)
diff --git a/src/Components/UnionKeyword.php b/src/Components/UnionKeyword.php
index 5a247bc..cbdb529 100644
--- a/src/Components/UnionKeyword.php
+++ b/src/Components/UnionKeyword.php
@@ -9,9 +9,7 @@
namespace SqlParser\Components;
use SqlParser\Component;
-use SqlParser\Parser;
-use SqlParser\Token;
-use SqlParser\TokensList;
+use SqlParser\Statements\SelectStatement;
/**
* `UNION` keyword builder.
diff --git a/src/Context.php b/src/Context.php
index dd912fb..eb7f299 100644
--- a/src/Context.php
+++ b/src/Context.php
@@ -416,6 +416,10 @@ abstract class Context
*/
public static function load($context = '')
{
+ /**
+ * @var Context $context
+ */
+
if (empty($context)) {
$context = self::$defaultContext;
}
@@ -467,6 +471,7 @@ abstract class Context
);
continue;
}
+
// Last generated context was valid (did not throw any exceptions).
// So we return it, to let the user know what context was loaded.
return $context;
diff --git a/src/Lexer.php b/src/Lexer.php
index bfaff93..697218c 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -255,8 +255,8 @@ namespace SqlParser {
&& ($token->type === Token::TYPE_SYMBOL)
&& ($token->flags & Token::FLAG_SYMBOL_VARIABLE)
&& (($lastToken->type === Token::TYPE_STRING)
- || (($lastToken->type === Token::TYPE_SYMBOL)
- && ($lastToken->flags & Token::FLAG_SYMBOL_BACKTICK)))
+ || (($lastToken->type === Token::TYPE_SYMBOL)
+ && ($lastToken->flags & Token::FLAG_SYMBOL_BACKTICK)))
) {
// Handles ```... FROM 'user'@'%' ...```.
$lastToken->token .= $token->token;
@@ -266,7 +266,6 @@ namespace SqlParser {
continue;
} elseif (($lastToken !== null)
&& ($token->type === Token::TYPE_KEYWORD)
- && ($token->flags & Token::FLAG_KEYWORD_RESERVED)
&& ($lastToken->type === Token::TYPE_OPERATOR)
&& ($lastToken->value === '.')
) {
@@ -316,6 +315,16 @@ namespace SqlParser {
while ((++$this->last < $this->len) && (!Context::isWhitespace($this->str[$this->last]))) {
$this->delimiter .= $this->str[$this->last];
}
+
+ if (empty($this->delimiter)) {
+ $this->error(
+ __('Expected delimiter.'),
+ '',
+ $this->last
+ );
+ $this->delimiter = ';';
+ }
+
--$this->last;
// Saving the delimiter and its token.
@@ -608,7 +617,7 @@ namespace SqlParser {
} elseif (($this->last + 1 < $this->len)
&& ($this->str[$this->last] === '0')
&& (($this->str[$this->last + 1] === 'x')
- || ($this->str[$this->last + 1] === 'X'))
+ || ($this->str[$this->last + 1] === 'X'))
) {
$token .= $this->str[$this->last++];
$state = 2;
diff --git a/src/Parser.php b/src/Parser.php
index d8ba75b..b44ecc6 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -332,7 +332,7 @@ namespace SqlParser {
/**
* Last transaction.
- * @var TransactionStatement
+ * @var TransactionStatement $lastTransaction
*/
$lastTransaction = null;
@@ -435,6 +435,10 @@ namespace SqlParser {
&& ($lastStatement instanceof SelectStatement)
&& ($statement instanceof SelectStatement)
) {
+ /**
+ * This SELECT statement.
+ * @var SelectStatement $statement
+ */
/**
* Last SELECT statement.
@@ -459,6 +463,10 @@ namespace SqlParser {
// Handles transactions.
if ($statement instanceof TransactionStatement) {
+
+ /**
+ * @var TransactionStatement $statement
+ */
if ($statement->type === TransactionStatement::TYPE_BEGIN) {
$lastTransaction = $statement;
$this->statements[] = $statement;
diff --git a/src/Statement.php b/src/Statement.php
index eb560b6..fabb82d 100644
--- a/src/Statement.php
+++ b/src/Statement.php
@@ -124,7 +124,7 @@ abstract class Statement
/**
* The builder (parser) of this clause.
- * @var string $class
+ * @var Component $class
*/
$class = Parser::$KEYWORD_PARSERS[$name]['class'];
@@ -213,7 +213,7 @@ abstract class Statement
/**
* The name of the class that is used for parsing.
- * @var string $class
+ * @var Component $class
*/
$class = null;
diff --git a/src/Statements/SetStatement.php b/src/Statements/SetStatement.php
index ed94901..d412853 100644
--- a/src/Statements/SetStatement.php
+++ b/src/Statements/SetStatement.php
@@ -9,11 +9,7 @@
namespace SqlParser\Statements;
use SqlParser\Statement;
-use SqlParser\Components\Expression;
-use SqlParser\Components\Limit;
-use SqlParser\Components\OrderKeyword;
use SqlParser\Components\SetOperation;
-use SqlParser\Components\Condition;
/**
* `SET` statement.
diff --git a/src/Statements/TransactionStatement.php b/src/Statements/TransactionStatement.php
index d7c9dbf..0ae83fe 100644
--- a/src/Statements/TransactionStatement.php
+++ b/src/Statements/TransactionStatement.php
@@ -10,9 +10,7 @@ namespace SqlParser\Statements;
use SqlParser\Parser;
use SqlParser\Statement;
-use SqlParser\Token;
use SqlParser\TokensList;
-use SqlParser\Components\Expression;
use SqlParser\Components\OptionsArray;
/**
@@ -51,7 +49,7 @@ class TransactionStatement extends Statement
/**
* The list of statements in this transaction.
*
- * @var Statements[]
+ * @var Statement[]
*/
public $statements;
@@ -110,6 +108,9 @@ class TransactionStatement extends Statement
$ret = OptionsArray::build($this->options);
if ($this->type === TransactionStatement::TYPE_BEGIN) {
foreach ($this->statements as $statement) {
+ /**
+ * @var SelectStatement $statement
+ */
$ret .= ';' . $statement->build();
}
$ret .= ';' . $this->end->build();
diff --git a/src/UtfString.php b/src/UtfString.php
index cac93ab..5f4ba12 100644
--- a/src/UtfString.php
+++ b/src/UtfString.php
@@ -209,7 +209,7 @@ class UtfString implements \ArrayAccess
/**
* Returns the contained string.
*
- * @return strin
+ * @return string
*/
public function __toString()
{