protected function execute()
{
if ($this->rows !== NULL) {
return;
}
$this->observeCache = $this;
if ($this->primary === NULL && $this->sqlBuilder->getSelect() === NULL) {
throw new Nette\InvalidStateException('Table with no primary key requires an explicit select clause.');
}
try {
$result = $this->query($this->getSql());
} catch (Nette\Database\DriverException $exception) {
if (!$this->sqlBuilder->getSelect() && $this->previousAccessedColumns) {
$this->previousAccessedColumns = FALSE;
$this->accessedColumns = [];
$result = $this->query($this->getSql());
} else {
throw $exception;
}
}
$this->rows = [];
$usedPrimary = TRUE;
foreach ($result->getPdoStatement() as $key => $row) {
$row = $this->createRow($result->normalizeRow($row));
$primary = $row->getSignature(FALSE);
$usedPrimary = $usedPrimary && (string) $primary !== '';
$this->rows[$usedPrimary ? $primary : $key] = $row;
}
$this->data = $this->rows;
if ($usedPrimary && $this->accessedColumns !== FALSE) {
foreach ((array) $this->primary as $primary) {
$this->accessedColumns[$primary] = TRUE;
}
}
}