Example #1
0
 /**
  * Gets the amount of total log entries
  * @param \System\Db\Database The database to query
  * @return int The amount of items in the log
  */
 public static final function getAmount(\System\Db\Database $db)
 {
     $query = new \System\Db\Query($db, SQL_SYSERROR_TOTALCOUNT);
     $results = $db->queryScalar($query);
     assert($results->hasItems());
     return $results->first();
 }
Example #2
0
 /**
  * Returns a Vector with all the database names from the current connection.
  * The database given will be used to retrieve all the databases the current connected user has access to.
  * @param \System\Db\Database The connection used to poll the user's accessable databases
  * @param string A prefix for the databases. No prefix returns all
  * @return \System\Collection\Vector A Vector containing all databases
  */
 public static final function getDatabaseNames(\System\Db\Database $db, $prefix = '')
 {
     $query = new \System\Db\Query($db, 'SHOW DATABASES');
     $results = $db->queryScalar($query);
     if (!empty($prefix)) {
         $vec = new \System\Collection\Vector();
         foreach ($results as $result) {
             if (stripos($result, $prefix) === 0) {
                 $vec[] = $result;
             }
         }
         return $vec;
     }
     return $results;
 }
Example #3
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();
 }