Accessing database views throws an error occasionally
Notice: This thread is very old.
- majorko
- Member | 2
When accessing a row in a database view, Nette occasionally throws this exception:
Nette\InvalidStateException – Row does not contain primary column data.
Error shows unpredictably – seems like cache problem.
The problem seems to lie in this part of code (Nette/Database/Table/ActiveRow:335):
<?php
//if ($this->table->getDataRefreshed() && !$this->dataRefreshed) {
$this->data = $this->table[$this->getSignature()]->data;
$this->dataRefreshed = TRUE;
//}
?>
When this if-branch is always executed, then accessing a row passes when it's table row, but always crashes when accessing a row of a database view.
Using Nette 2.0.10 with PHP 5.4.15.
<?php
//accessing table data
$table = $db->table('some_table');
foreach ($table as $row) {
//passess
echo $row->id;
}
//accessing view data
$table = $db->table('some_view');
foreach ($table as $row) {
//throws an error
echo $row->id;
}
?>
SQL:
-- Adminer 3.6.4 MySQL dump
SET NAMES utf8;
SET foreign_key_checks = 0;
SET time_zone = '+02:00';
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS `some_table`;
CREATE TABLE `some_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `some_table` (`id`) VALUES
(1),
(2),
(3),
(4),
(5),
(6),
(7),
(8),
(9);
DROP VIEW IF EXISTS `some_view`;
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `some_view` AS select `some_table`.`id` AS `id` from `some_table`;