/**
  * @expectedException Psc\Doctrine\QueryException
  */
 public function testwithException_throwsPscDoctrineQueryException()
 {
     $query = $this->doublesManager->createQueryMock(array('getResult', 'getScalarResult', 'getDQL'), $this->emm);
     $query->expects($this->once())->method('getDQL')->will($this->returnValue('SELECT * FROM DAM\\AGE'));
     $query->expects($this->once())->method('getResult')->will($this->throwException(\Doctrine\ORM\Query\QueryException::semanticalError('DAM\\AGE ist keine Tabelle natürlich')));
     $this->runDeliverQuery(NULL, 'result', $query);
 }
Beispiel #2
0
 /**
  * @param \Doctrine\ORM\Query\SqlWalker $sqlWalker
  * @return string
  * @throws QueryException
  */
 public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
 {
     $unit = strtoupper(is_string($this->unit) ? $this->unit : $this->unit->value);
     if (!in_array($unit, self::$allowedUnits)) {
         throw QueryException::semanticalError('DATE_SUB() does not support unit "' . $unit . '".');
     }
     return 'DATE_SUB(' . $this->firstDateExpression->dispatch($sqlWalker) . ', INTERVAL ' . $this->intervalExpression->dispatch($sqlWalker) . ' ' . $unit . ')';
 }
Beispiel #3
0
 /**
  * @override
  */
 public function getSql(SqlWalker $sqlWalker)
 {
     switch (strtolower($this->unit->value)) {
         case 'day':
             return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddDaysExpression($this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker));
         case 'month':
             return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddMonthExpression($this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker));
         default:
             throw QueryException::semanticalError('DATE_ADD() only supports units of type day and month.');
     }
 }
 public function getSql(SqlWalker $sqlWalker)
 {
     $unit = strtolower($this->unit);
     if ($unit == "day") {
         return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddDaysExpression($this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker));
     } else {
         if ($unit == "month") {
             return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddMonthExpression($this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker));
         } else {
             throw QueryException::semanticalError('DATE_ADD() only supports units of type day and month.');
         }
     }
 }
 /**
  * Generates a new semantical error.
  *
  * @param string     $message Optional message.
  * @param array|null $token   Optional token.
  *
  * @return void
  *
  * @throws \Doctrine\ORM\Query\QueryException
  */
 public function semanticalError($message = '', $token = null)
 {
     if ($token === null) {
         $token = $this->lexer->lookahead;
     }
     // Minimum exposed chars ahead of token
     $distance = 12;
     // Find a position of a final word to display in error string
     $dql = $this->query->getDql();
     $length = strlen($dql);
     $pos = $token['position'] + $distance;
     $pos = strpos($dql, ' ', $length > $pos ? $pos : $length);
     $length = $pos !== false ? $pos - $token['position'] : $distance;
     $tokenPos = isset($token['position']) && $token['position'] > 0 ? $token['position'] : '-1';
     $tokenStr = substr($dql, $token['position'], $length);
     // Building informative message
     $message = 'line 0, col ' . $tokenPos . " near '" . $tokenStr . "': Error: " . $message;
     throw QueryException::semanticalError($message, QueryException::dqlError($this->query->getDQL()));
 }
Beispiel #6
0
    /**
     * Generates a new semantical error.
     *
     * @param string $message Optional message.
     * @param array $token Optional token.
     *
     * @throws \Doctrine\ORM\Query\QueryException
     */
    public function semanticalError($message = '', $token = null)
    {
        if ($token === null) {
            $token = $this->_lexer->lookahead;
        }

        // Minimum exposed chars ahead of token
        $distance = 12;

        // Find a position of a final word to display in error string
        $dql = $this->_query->getDql();
        $length = strlen($dql);
        $pos = $token['position'] + $distance;
        $pos = strpos($dql, ' ', ($length > $pos) ? $pos : $length);
        $length = ($pos !== false) ? $pos - $token['position'] : $distance;

        // Building informative message
        $message = 'line 0, col ' . (
            (isset($token['position']) && $token['position'] > 0) ? $token['position'] : '-1'
        ) . " near '" . substr($dql, $token['position'], $length) . "': Error: " . $message;

        throw \Doctrine\ORM\Query\QueryException::semanticalError($message);
    }