/**
  * get command handler
  *
  * @param string $alias
  * @throws QueryException
  * @return callable
  */
 public function getQueryHandler($alias)
 {
     if (class_exists($alias)) {
         return new $alias();
     }
     throw QueryException::handlerError(sprintf('alias <%s> does not exist', $alias));
 }
Esempio n. 2
0
 /**
  * Set or override a query component for a given dql alias.
  *
  * @param string $dqlAlias The DQL alias.
  * @param array $queryComponent
  */
 public function setQueryComponent($dqlAlias, array $queryComponent)
 {
     $requiredKeys = array('metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token');
     if (array_diff($requiredKeys, array_keys($queryComponent))) {
         throw QueryException::invalidQueryComponent($dqlAlias);
     }
     $this->_queryComponents[$dqlAlias] = $queryComponent;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function execute(QueryInterface $query) : ResultInterface
 {
     $this->dispatcher->dispatch(Events::PRE_QUERY, new PreQueryEvent($query));
     $response = $this->http->send($this->translator->translate($query));
     if (!$this->isSuccessful($response)) {
         throw QueryException::failed($query, $response);
     }
     $response = json_decode((string) $response->getBody(), true);
     $result = Result::fromRaw($response['results'][0] ?? []);
     $this->dispatcher->dispatch(Events::POST_QUERY, new PostQueryEvent($query, $result));
     return $result;
 }
Esempio n. 4
0
 public function testGetParameters()
 {
     $this->assertEquals($this->parameters, $this->exception->getParameters());
 }
Esempio n. 5
0
 /**
  * @return string
  *
  * @throws \Doctrine\DBAL\Query\QueryException
  */
 protected function getSQLForSelect()
 {
     $query = 'SELECT ' . implode(', ', $this->sqlParts['select']) . ' FROM ';
     $fromClauses = array();
     $knownAliases = array();
     // Loop through all FROM clauses
     foreach ($this->sqlParts['from'] as $from) {
         $knownAliases[$from['alias']] = true;
         $fromClause = $from['table'] . ' ' . $from['alias'] . $this->getSQLForJoins($from['alias'], $knownAliases);
         $fromClauses[$from['alias']] = $fromClause;
     }
     foreach ($this->sqlParts['join'] as $fromAlias => $joins) {
         if (!isset($knownAliases[$fromAlias])) {
             throw QueryException::unknownAlias($fromAlias, array_keys($knownAliases));
         }
     }
     $query .= implode(', ', $fromClauses) . ($this->sqlParts['where'] !== null ? ' WHERE ' . (string) $this->sqlParts['where'] : '') . ($this->sqlParts['groupBy'] ? ' GROUP BY ' . implode(', ', $this->sqlParts['groupBy']) : '') . ($this->sqlParts['having'] !== null ? ' HAVING ' . (string) $this->sqlParts['having'] : '') . ($this->sqlParts['orderBy'] ? ' ORDER BY ' . implode(', ', $this->sqlParts['orderBy']) : '');
     return $this->maxResults === null && $this->firstResult == null ? $query : $this->connection->getDatabasePlatform()->modifyLimitQuery($query, $this->maxResults, $this->firstResult);
 }
Esempio n. 6
0
 /**
  * Gets the single result of the query.
  * Enforces the uniqueness of the result. If the result is not unique,
  * a QueryException is thrown.
  *
  * @param integer $hydrationMode
  * @return mixed
  * @throws QueryException If the query result is not unique.
  */
 public function getSingleResult($hydrationMode = null)
 {
     $result = $this->execute(array(), $hydrationMode);
     if (is_array($result)) {
         if (count($result) > 1) {
             throw QueryException::nonUniqueResult();
         }
         return array_shift($result);
     } else {
         if (is_object($result)) {
             if (count($result) > 1) {
                 throw QueryException::nonUniqueResult();
             }
             return $result->first();
         }
     }
     return $result;
 }
Esempio n. 7
0
 public function __construct($columns)
 {
     parent::__construct('This array contains different columns than the other arrays: "' . $columns . '"');
 }
	/**
	 * Handles an Query Error: A QueryExcpetion will be thrown.
	 *
	 * @see QueryException
	 * @throws QueryException
	 * @param string Last Query
	 **/
	protected function queryError($query) {
		$e = new QueryException($this->error(), $this->errno());
		$e->setQuery($query);
		$e->setLine(__LINE__);
		$e->setFile(__FILE__);

		// Try to get better results for line and file.
		if (function_exists('debug_backtrace') == true) {
			$backtraceInfo = debug_backtrace();
			// 0 is class.mysql.php, 1 is the calling code...
			if (isset($backtraceInfo[1]) == true) {
				$e->setLine($backtraceInfo[1]['line']);
				$e->setFile($backtraceInfo[1]['file']);
			}
		}

		$this->debug->addText($e);

		throw $e;
	}
 public function __construct()
 {
     parent::__construct('Expected result from query, didn\'t get one.');
 }