/**
  * @param $query
  * @param array $configurations
  * @return array
  * @throws \QCharts\CoreBundle\Exception\DatabaseException
  */
 public function validateQueryExecution($query, array $configurations)
 {
     $offset = $configurations["offset"];
     $query = $this->querySyntax->getLimitedQuery($query, $this->getMaxRows($configurations["rows"]), $offset);
     $this->validateConnection($configurations["connection"]);
     $this->dynamicRepo->setUp($configurations["connection"]);
     $results = $this->dynamicRepo->execute($query);
     $duration = $this->dynamicRepo->getExecutionDuration();
     $configurations["validation"] = ["duration" => $duration, "results" => $results];
     $validators = $this->getValidators($configurations);
     foreach ($validators as $name => $validator) {
         /** @var ValidatorInterface $validator */
         $validator->validate();
     }
     return $results;
 }
Example #2
0
 /**
  * Calls the dynamic repository and calls the results from the query
  *
  * @param $query
  * @param int $limit
  * @param string $connection
  * @return array
  * @throws DatabaseException
  * @throws ParameterNotPassedException
  * @throws ValidationFailedException
  * @throws \Exception
  */
 public function getResultsFromQuery($query, $limit = 0, $connection = 'default')
 {
     try {
         $this->queryValidator->isValidQuery($query, $connection);
         $query = $this->queryValidator->getLimitedQuery($query, $limit);
         $this->dynamicRepo->setUp($connection);
         $res = $this->dynamicRepo->execute($query);
         $duration = $this->dynamicRepo->getExecutionDuration();
         $duration = number_format($duration, 7, '.', ',');
         return ["results" => $res, "duration" => $duration];
     } catch (ParameterNotPassedException $e) {
         throw $e;
     } catch (ValidationFailedException $e) {
         throw $e;
     } catch (TypeNotValidException $e) {
         throw $e;
     } catch (DBALException $e) {
         $exceptionText = "There was an error when executing the query, your database's message:\n\n{$e->getPrevious()->getMessage()}";
         throw new DatabaseException($exceptionText, 500, $e);
     }
 }