Exemplo n.º 1
0
 /**
  * Loads cache of previous accessed columns and returns it
  *
  * @internal
  * @return array|false
  */
 public function getPreviousAccessed()
 {
     $cache = $this->connection->getCache();
     if ($this->rows === null && $cache && !is_string($this->prevAccessed)) {
         $this->accessed = $this->prevAccessed = $cache->load(array(__CLASS__, $this->name, $this->sqlBuilder->getConditions()));
     }
     return $this->prevAccessed;
 }
Exemplo n.º 2
0
 /**
  * Creates filtered table representation.
  * @param  string  database table name
  * @param  Nette\Database\Connection
  */
 public function __construct($table, Nette\Database\Connection $connection)
 {
     $this->name = $table;
     $this->connection = $connection;
     $reflection = $connection->getDatabaseReflection();
     $this->primary = $reflection->getPrimary($table);
     $this->sqlBuilder = new SqlBuilder($table, $connection, $reflection);
     $this->cache = $connection->getCache();
 }
Exemplo n.º 3
0
 /**
  * Returns SQL query.
  * @return string
  */
 public function getSql()
 {
     $join = $this->createJoins(implode(',', $this->conditions), TRUE) + $this->createJoins(implode(',', $this->select) . ",{$this->group},{$this->having}," . implode(',', $this->order));
     $cache = $this->connection->getCache();
     if ($this->rows === NULL && $cache && !is_string($this->prevAccessed)) {
         $this->accessed = $this->prevAccessed = $cache->load(array(__CLASS__, $this->name, $this->conditions));
     }
     $prefix = $join ? "{$this->delimitedName}." : '';
     if ($this->select) {
         $cols = $this->removeExtraTables($this->tryDelimite(implode(', ', $this->select)));
     } elseif ($this->prevAccessed) {
         $cols = $prefix . implode(', ' . $prefix, array_map(array($this->connection->getSupplementalDriver(), 'delimite'), array_keys($this->prevAccessed)));
     } else {
         $cols = $prefix . '*';
     }
     return "SELECT{$this->topString()} {$cols} FROM {$this->delimitedName}" . implode($join) . $this->whereString();
 }
Exemplo n.º 4
0
 protected function saveCacheState()
 {
     if ($this->observeCache && ($cache = $this->connection->getCache()) && !$this->sqlBuilder->getSelect() && $this->accessed != $this->prevAccessed) {
         $cache->save(array(__CLASS__, $this->name, $this->sqlBuilder->getConditions()), $this->accessed);
     }
 }