示例#1
0
    public function getPanel()
    {
        $this->disabled = TRUE;
        $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*\\(?\\s*SELECT\\s#iA', $sql)) {
                try {
                    $cmd = is_string($this->explain) ? $this->explain : 'EXPLAIN';
                    $explain = $connection->queryArgs("{$cmd} {$sql}", $params)->fetchAll();
                } catch (PDOException $e) {
                }
            }
            $s .= '<tr><td>' . sprintf('%0.3f', $time * 1000);
            if ($explain) {
                static $counter;
                $counter++;
                $s .= "<br /><a href='#' class='nette-toggler' rel='#nette-DbConnectionPanel-row-{$counter}'>explain&nbsp;&#x25ba;</a>";
            }
            $s .= '</td><td class="nette-DbConnectionPanel-sql">' . DatabaseHelpers::dumpSql(self::$maxLength ? Strings::truncate($sql, self::$maxLength) : $sql);
            if ($explain) {
                $s .= "<table id='nette-DbConnectionPanel-row-{$counter}' 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) {
                $s .= DebugHelpers::editorLink($source[0], $source[1])->class('nette-DbConnectionPanel-source');
            }
            $s .= '</td><td>';
            foreach ($params as $param) {
                $s .= Debugger::dump($param, TRUE);
            }
            $s .= '</td><td>' . $rows . '</td></tr>';
        }
        return empty($this->queries) ? '' : '<style> #nette-debug td.nette-DbConnectionPanel-sql { background: white !important }
			#nette-debug .nette-DbConnectionPanel-source { color: #BBB !important } </style>
			<h1>Queries: ' . count($this->queries) . ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . '</h1>
			<div class="nette-inner nette-DbConnectionPanel">
			<table>
				<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . '
			</table>
			</div>';
    }
示例#2
0
文件: Neon.php 项目: riskatlas/micka
 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>', Strings::truncate(self::$tokenizer->tokens[$this->n], 40)) : 'end';
     throw new NeonException(str_replace('%s', $token, $message) . " on line {$line}, column {$col}.");
 }