public function getPanel() { $s = ''; foreach ($this->queries as $query) { list($sql, $params, $time, $rows) = $query; $s .= '<tr><td>' . sprintf('%0.3f', $time * 1000) . '</td><td class="database-sql">' . Connection::highlightSql(Nette\String::truncate($sql, self::$maxLength)) . '</td><td>' . htmlSpecialChars(implode(', ', $params)) . '</td><td>' . $rows . '</td></tr>'; } return empty($this->queries) ? '' : '<style> #nette-debug-database td.database-sql { background: white !important } </style> <h1>Queries: ' . count($this->queries) . ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . '</h1> <div class="nette-inner"> <table> <tr><th>Time ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . ' </table> </div>'; }
public function getPanel() { $s = ''; $h = 'htmlSpecialChars'; foreach ($this->queries as $i => $query) { list($sql, $params, $time, $rows, $connection, $source) = $query; $explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS() if ($this->explain && preg_match('#\\s*SELECT\\s#iA', $sql)) { try { $explain = $connection->queryArgs('EXPLAIN ' . $sql, $params)->fetchAll(); } catch (\PDOException $e) { } } $s .= '<tr><td>' . sprintf('%0.3f', $time * 1000); if ($explain) { $s .= "<br /><a href='#' class='nette-toggler' rel='#nette-debug-database-row-{$h($this->name)}-{$i}'>explain ►</a>"; } $s .= '</td><td class="database-sql">' . Connection::highlightSql(Nette\String::truncate($sql, self::$maxLength)); if ($explain) { $s .= "<table id='nette-debug-database-row-{$h($this->name)}-{$i}' class='nette-collapsed'><tr>"; foreach ($explain[0] as $col => $foo) { $s .= "<th>{$h($col)}</th>"; } $s .= "</tr>"; foreach ($explain as $row) { $s .= "<tr>"; foreach ($row as $col) { $s .= "<td>{$h($col)}</td>"; } $s .= "</tr>"; } $s .= "</table>"; } if ($source) { list($file, $line) = $source; $s .= (Nette\Debug::$editor ? "<a href='{$h(Nette\DebugHelpers::editorLink($file, $line))}'" : '<span') . " class='database-source' title='{$h($file)}:{$line}'>" . "{$h(basename(dirname($file)) . '/' . basename($file))}:{$line}" . (Nette\Debug::$editor ? '</a>' : '</span>'); } $s .= '</td><td>'; foreach ($params as $param) { $s .= "{$h(Nette\String::truncate($param, self::$maxLength))}<br>"; } $s .= '</td><td>' . $rows . '</td></tr>'; } return empty($this->queries) ? '' : '<style> #nette-debug-database td.database-sql { background: white !important } #nette-debug-database .database-source { color: #BBB !important } #nette-debug-database tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style> <h1>Queries: ' . count($this->queries) . ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . '</h1> <div class="nette-inner"> <table> <tr><th>Time ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . ' </table> </div>'; }
private function error($message = "Unexpected '%s'") { list(, $line, $col) = self::$tokenizer->getOffset($this->n); $token = str_replace("\n", '\\n', Nette\String::truncate(self::$tokenizer->tokens[$this->n], 40)); throw new NeonException(str_replace('%s', $token, $message) . "' on line " . ($line - 1) . ", column {$col}."); }
private function error($message = "Unexpected '%s'") { list(, $line, $col) = self::$tokenizer->getOffset($this->n); $token = isset(self::$tokenizer->tokens[$this->n]) ? str_replace("\n", '<new line>', Nette\String::truncate(self::$tokenizer->tokens[$this->n], 40)) : 'end'; throw new NeonException(str_replace('%s', $token, $message) . " on line $line, column $col."); }