Ejemplo n.º 1
0
 /**
  * Executes a query on the database system.
  * @param \System\Db\Query The query to be executed
  * @return \System\Db\DatabaseResult A collection of result from the database.
  */
 public function query(\System\Db\Query $query)
 {
     if ($query->getUseSecondaryPipe() && $this->secondaryPipe instanceof \System\Db\Database) {
         $query->setUseSecondaryPipe(false);
         return $this->secondaryPipe->query($query);
     } else {
         $result = null;
         //we increase the amount of db queries
         $this->dbQueryCount++;
         $result = new DatabaseResult($this->httpTunnel, $this->createPostString(self::MODE_QUERY), $query, $this);
         $event = new \System\Event\Event\OnMySQLQueryEvent();
         $event->setQuery($query);
         $event->setResult($result);
         $event->raise($this);
         return $result;
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates a new database resultset. This function is automatically called by the database and should not
  * be called directly.
  * @param \MySQLi The link to the database system
  * @param \System\Db\Query The query
  * @param \System\Db\Database The database issueing the request
  */
 public function __construct(\MySQLi $databaseLink, \System\Db\Query $query, \System\Db\Database $database)
 {
     $this->databaseLink = $databaseLink;
     $this->requestIssuer = $database;
     $this->query = $query;
     //increase its own querycounter
     self::$queryCount++;
     $timer = new \System\Calendar\Timer();
     $timer->start();
     $actualQuery = $query->getQuery();
     if (!($this->results = $databaseLink->query($actualQuery))) {
         throw new \System\Error\Exception\DatabaseQueryException('Query: ' . $actualQuery . ' - ' . $databaseLink->error);
     }
     /**
      * If there is a query that wants to execute the amount of found rows, we store this amount in the own vector.
      * Do note that this query gets logged before the actual query, because of the stackframe buildup. The actual execution order is correct
      */
     if (strpos($actualQuery, 'SQL_CALC_FOUND_ROWS') !== false) {
         $query = new \System\Db\Query($database, 'SELECT FOUND_ROWS() AS amount');
         $this->totalAmount = $database->queryScalar($query)->first();
     } else {
         $this->totalAmount = $this->count();
     }
     $timer->stop();
     $this->duration = $timer->getDuration();
     self::$totalQueryTime += $this->duration;
     if (round($timer->getDuration()) >= self::SLOW_QUERY_TIME) {
         $event = new \System\Event\Event\OnSlowMySQLQueryEvent();
         $event->setQuery($query);
         $event->setDuration($this->duration);
         $event->raise($this);
     }
     $this->rewind();
 }