/** * 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); } }
/** * @return float|string * @throws \QCharts\CoreBundle\Exception\DatabaseException */ public function getExecutionDuration() { $duration = $this->dynamicRepo->getExecutionDuration(); $duration = number_format($duration, 7, '.', ','); return $duration; }