1
0
mirror of synced 2025-01-29 19:41:45 +03:00

Implemented support for internal exception showing DQL that contains syntax or semantical error.

This commit is contained in:
Guilherme Blanco 2012-05-21 16:34:27 -04:00
parent 93fcb74f9a
commit d05ad996c4
4 changed files with 16 additions and 10 deletions

View File

@ -25,7 +25,7 @@ use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\QueryException;
/**
* "DATE_ADD(date1, interval, unit)"
* "DATE_ADD" "(" ArithmeticPrimary "," ArithmeticPrimary "," StringPrimary ")"
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org

View File

@ -24,7 +24,7 @@ use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\Parser;
/**
* "DATE_DIFF(date1, date2)"
* "DATE_DIFF" "(" ArithmeticPrimary "," ArithmeticPrimary ")"
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org

View File

@ -377,7 +377,7 @@ class Parser
$message .= ($expected !== '') ? "Expected {$expected}, got " : 'Unexpected ';
$message .= ($this->_lexer->lookahead === null) ? 'end of string.' : "'{$token['value']}'";
throw QueryException::syntaxError($message);
throw QueryException::syntaxError($message, QueryException::dqlError($this->_query->getDQL()));
}
/**
@ -410,7 +410,7 @@ class Parser
// Building informative message
$message = 'line 0, col ' . $tokenPos . " near '" . $tokenStr . "': Error: " . $message;
throw QueryException::semanticalError($message);
throw QueryException::semanticalError($message, QueryException::dqlError($this->_query->getDQL()));
}
/**
@ -1381,7 +1381,7 @@ class Parser
*
* NewValue ::= SimpleArithmeticExpression | "NULL"
*
* SimpleArithmeticExpression covers all *Primary grammar rules and also SimplEntityExpression
* SimpleArithmeticExpression covers all *Primary grammar rules and also SimpleEntityExpression
*/
public function NewValue()
{
@ -2483,7 +2483,8 @@ class Parser
/**
* ArithmeticPrimary ::= SingleValuedPathExpression | Literal | "(" SimpleArithmeticExpression ")"
* | FunctionsReturningNumerics | AggregateExpression | FunctionsReturningStrings
* | FunctionsReturningDatetime | IdentificationVariable | ResultVariable | CaseExpression
* | FunctionsReturningDatetime | IdentificationVariable | ResultVariable
* | InputParameter | CaseExpression
*/
public function ArithmeticPrimary()
{

View File

@ -37,14 +37,19 @@ use Doctrine\ORM\Query\AST\PathExpression;
*/
class QueryException extends \Doctrine\ORM\ORMException
{
public static function syntaxError($message)
public static function dqlError($dql)
{
return new self('[Syntax Error] ' . $message);
return new self($dql);
}
public static function semanticalError($message)
public static function syntaxError($message, $previous = null)
{
return new self('[Semantical Error] ' . $message);
return new self('[Syntax Error] ' . $message, 0, $previous);
}
public static function semanticalError($message, $previous = null)
{
return new self('[Semantical Error] ' . $message, 0, $previous);
}
public static function invalidLockMode()