/** * @param int $timeLimit * @param string $connectionName * @return bool|int|number */ public function getMaxTime($timeLimit = 0, $connectionName = 'default') { $this->validateConnection($connectionName); $this->dynamicRepo->setUp($connectionName); $time = $this->dynamicRepo->isMaxExecutionSet(); $configLimits = $this->limits->getLimits(); if (is_numeric($time) && $time !== 0) { if ($timeLimit > 0 && $time > $timeLimit) { return $timeLimit; } return $time; } $limit = $timeLimit > 0 && $timeLimit <= $configLimits["time"] ? $timeLimit : $configLimits["time"]; if (is_string($time)) { // limit is in seconds! $this->dynamicRepo->setMaxExecutionTime($configLimits["time"], $time); } return $limit; }
/** * 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); } }