dumpSql() public static method

Returns syntax highlighted SQL command.
public static dumpSql ( $sql, array $params = NULL, Connection $connection = NULL ) : string
$params array
$connection Connection
return string
    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">' . Helpers::dumpSql(self::$maxLength ? Nette\Utils\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 .= Nette\Diagnostics\Helpers::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 }
			#nette-debug nette-DbConnectionPanel 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 nette-DbConnectionPanel">
			<table>
				<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . '
			</table>
			</div>';
    }
Beispiel #2
0
 /**
  * @param array
  * @return string
  */
 protected function processQuery(array $query)
 {
     $s = '';
     list($sql, $params, $time) = $query;
     $s .= '<tr><td>' . sprintf('%0.3f', $time * 1000);
     $s .= '</td><td class="nette-Doctrine2Panel-sql">' . Helpers::dumpSql($sql);
     $s .= '</td><td>' . Dumper::toHtml($params) . '</tr>';
     return $s;
 }
Beispiel #3
0
 public static function renderException($e)
 {
     if (!$e instanceof \PDOException) {
         return;
     }
     if (isset($e->queryString)) {
         $sql = $e->queryString;
     } elseif ($item = Tracy\Helpers::findTrace($e->getTrace(), 'PDO::prepare')) {
         $sql = $item['args'][0];
     }
     return isset($sql) ? ['tab' => 'SQL', 'panel' => Helpers::dumpSql($sql)] : NULL;
 }
    /**
     * @return string
     */
    public function getPanel()
    {
        $output = '';
        foreach ($this->queries as $record) {
            $time = $record['time'];
            $query = $record['query'];
            $output .= '<tr><td>';
            $output .= $time ? $time . '&nbsp;ms' : 'null';
            $output .= '</td><td>' . Helpers::dumpSql($query);
            $output .= '</td></tr>';
        }
        return empty($this->queries) ? '' : '<style> #tracy-debug .tracy-PropelPanel tr table { margin: 8px 0; max-height: 150px; overflow:auto }</style>
			<h1>Channel: ' . htmlSpecialChars($this->channelName, ENT_QUOTES, 'UTF-8') . ' | Queries: ' . htmlSpecialChars($this->profiledQueriesCounter, ENT_QUOTES, 'UTF-8') . ' / ' . htmlSpecialChars($this->unprofiledQueriesCounter, ENT_QUOTES, 'UTF-8') . ' | Time: ' . htmlSpecialChars($this->totalTime, ENT_QUOTES, 'UTF-8') . 'ms</h1>
			<div class="tracy-inner tracy-PropelPanel" style="max-width: 800px;">
			<table>
				<tr><th>Time</th><th>SQL Statement</th></tr>' . $output . '
			</table>
			</div>';
    }
 public function getPanel()
 {
     global $wpdb;
     $inner = '';
     foreach ($wpdb->queries as $q) {
         $query = \Nette\Database\Helpers::dumpSql($q[0]);
         $time = round($q[1] * 100000) / 1000;
         $files = $q[2];
         $callstack = explode(', ', $q[2]);
         array_shift($callstack);
         array_shift($callstack);
         array_shift($callstack);
         foreach ($callstack as &$row) {
             $row = htmlspecialchars($row);
         }
         unset($row);
         $callstack = implode('<br>', $callstack);
         $inner .= "<tr><td rowspan='2'>{$time}</td><td><code>{$query}</code></td></tr><tr><td><code style='font-size:.8em'>{$callstack}</code></td></tr>";
     }
     $panelHtml = "\n\t\t<h1>WordPress SQL</h1>\n\t\t<div class='tracy-inner nette-DbConnectionPanel'>\n\t\t\t<table>\n\t\t\t\t<tr><th>Time&nbsp;ms</th><th>SQL Query</th></tr>\n\t\t\t\t\t{$inner}\n\t\t\t</table>\n\t\t</div>\n\t\t";
     return $panelHtml;
 }
 public function logQuery(Connection $connection, $result)
 {
     if (!$result instanceof ResultSet) {
         return;
     }
     $queryString = $result->getQueryString();
     if (Strings::startsWith($queryString, 'EXPLAIN')) {
         return;
     }
     $source = NULL;
     $trace = $result instanceof \PDOException ? $result->getTrace() : debug_backtrace(PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : FALSE);
     foreach ($trace as $row) {
         if (isset($row['file']) && is_file($row['file']) && !Debugger::getBluescreen()->isCollapsed($row['file'])) {
             if (isset($row['function']) && strpos($row['function'], 'call_user_func') === 0 || isset($row['class']) && is_subclass_of($row['class'], '\\Nette\\Database\\Connection')) {
                 continue;
             }
             $source = array($row['file'], (int) $row['line']);
             break;
         }
     }
     $sqlQuery = Helpers::dumpSql($queryString, $result->getParameters(), $connection);
     $this->queries[$sqlQuery][] = array($sqlQuery, $source);
 }
Beispiel #7
0
    public function getPanel()
    {
        $this->disabled = TRUE;
        $s = '';
        foreach ($this->queries as $query) {
            list($connection, $sql, $params, $source, $time, $rows, $error) = $query;
            $explain = NULL;
            // EXPLAIN is called here to work SELECT FOUND_ROWS()
            if (!$error && $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>';
            if ($error) {
                $s .= '<span title="' . htmlSpecialChars($error, ENT_IGNORE | ENT_QUOTES) . '">ERROR</span>';
            } elseif ($time !== NULL) {
                $s .= sprintf('%0.3f', $time * 1000);
            }
            if ($explain) {
                static $counter;
                $counter++;
                $s .= "<br /><a class='tracy-toggle tracy-collapsed' href='#nette-DbConnectionPanel-row-{$counter}'>explain</a>";
            }
            $s .= '</td><td class="nette-DbConnectionPanel-sql">' . Helpers::dumpSql($sql, $params, $connection);
            if ($explain) {
                $s .= "<table id='nette-DbConnectionPanel-row-{$counter}' class='tracy-collapsed'><tr>";
                foreach ($explain[0] as $col => $foo) {
                    $s .= '<th>' . htmlSpecialChars($col) . '</th>';
                }
                $s .= '</tr>';
                foreach ($explain as $row) {
                    $s .= '<tr>';
                    foreach ($row as $col) {
                        $s .= '<td>' . htmlSpecialChars($col) . '</td>';
                    }
                    $s .= '</tr>';
                }
                $s .= '</table>';
            }
            if ($source) {
                $s .= substr_replace(Tracy\Helpers::editorLink($source[0], $source[1]), ' class="nette-DbConnectionPanel-source"', 2, 0);
            }
            $s .= '</td><td>' . $rows . '</td></tr>';
        }
        return $this->count ? '<style class="tracy-debug"> #tracy-debug td.nette-DbConnectionPanel-sql { background: white !important }
			#tracy-debug .nette-DbConnectionPanel-source { color: #BBB !important } </style>
			<h1 title="' . htmlSpecialChars($connection->getDsn()) . '">Queries: ' . $this->count . ($this->totalTime ? sprintf(', time: %0.3f ms', $this->totalTime * 1000) : '') . ', ' . htmlSpecialChars($this->name) . '</h1>
			<div class="tracy-inner nette-DbConnectionPanel">
			<table>
				<tr><th>Time&nbsp;ms</th><th>SQL Query</th><th>Rows</th></tr>' . $s . '
			</table>' . (count($this->queries) < $this->count ? '<p>...and more</p>' : '') . '</div>' : '';
    }
Beispiel #8
0
 /**
  * @param array
  * @return string
  */
 protected function processQuery(array $query)
 {
     $s = '<tr>';
     $s .= '<td>' . sprintf('%0.3f', $query[self::TIME] * 1000);
     if ($this->doExplains && isset($query[self::EXPLAIN])) {
         static $counter;
         $counter++;
         $s .= "<br /><a href='#' class='nette-toggler' rel='#nette-Doctrine2Panel-row-{$counter}'>explain&nbsp;&#x25ba;</a>";
     }
     $s .= '</td>';
     $s .= '<td class="nette-Doctrine2Panel-sql" style="min-width: 400px">' . Helpers::dumpSql($query[self::SQL]);
     if ($this->doExplains && isset($query[self::EXPLAIN])) {
         $s .= "<table id='nette-Doctrine2Panel-row-{$counter}' class='nette-collapsed'><tr>";
         foreach ($query[self::EXPLAIN][0] as $col => $foo) {
             $s .= '<th>' . htmlSpecialChars($col) . '</th>';
         }
         $s .= '</tr>';
         foreach ($query[self::EXPLAIN] as $row) {
             $s .= '<tr>';
             foreach ($row as $col) {
                 $s .= '<td>' . htmlSpecialChars($col) . '</td>';
             }
             $s .= '</tr>';
         }
         $s .= '</table>';
     }
     $s .= '</td>';
     $s .= '<td>' . \Nette\Diagnostics\Helpers::clickableDump($query[self::PARAMS], TRUE) . '</td>';
     $s .= '</tr>';
     return $s;
 }
 /**
  * Actual formatted query, e.g. 'SELECT * FROM ...'
  *
  * @return Html|string
  */
 public function getQuery()
 {
     return trim(NDB\Helpers::dumpSql($this->result->getQueryString(), $this->result->getParameters(), $this->result->connection));
 }
Beispiel #10
0
getTab(){return'<span title="Nette\\Database '.htmlSpecialChars($this->name).'">'.'<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEYSURBVBgZBcHPio5hGAfg6/2+R980k6wmJgsJ5U/ZOAqbSc2GnXOwUg7BESgLUeIQ1GSjLFnMwsKGGg1qxJRmPM97/1zXFAAAAEADdlfZzr26miup2svnelq7d2aYgt3rebl585wN6+K3I1/9fJe7O/uIePP2SypJkiRJ0vMhr55FLCA3zgIAOK9uQ4MS361ZOSX+OrTvkgINSjS/HIvhjxNNFGgQsbSmabohKDNoUGLohsls6BaiQIMSs2FYmnXdUsygQYmumy3Nhi6igwalDEOJEjPKP7CA2aFNK8Bkyy3fdNCg7r9/fW3jgpVJbDmy5+PB2IYp4MXFelQ7izPrhkPHB+P5/PjhD5gCgCenx+VR/dODEwD+A3T7nqbxwf1HAAAAAElFTkSuQmCC" />'.count($this->queries).' queries'.($this->totalTime?' / '.sprintf('%0.1f',$this->totalTime*1000).'ms':'').'</span>';}function
getPanel(){$this->disabled=TRUE;$s='';$h='htmlSpecialChars';foreach($this->queries
as$i=>$query){list($sql,$params,$time,$rows,$connection,$source)=$query;$explain=NULL;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">'.Helpers::dumpSql(self::$maxLength?Nette\Utils\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.=Nette\Diagnostics\Helpers::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>';}}}namespace Nette\Database\Drivers{use
 /**
  * Actual formatted query, e.g. 'SELECT * FROM ...'
  *
  * @return Html|string
  */
 public function getQuery()
 {
     $html = trim(Nette\Database\Helpers::dumpSql($this->query, $this->bindings));
     return Html::el()->setHtml($html);
 }
Beispiel #12
0
        function getPanel()
        {
            $this->disabled = TRUE;
            $s = '';
            foreach ($this->queries as $query) {
                list($sql, $params, $time, $rows, $connection, $source) = $query;
                $explain = NULL;
                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">' . Helpers::dumpSql(self::$maxLength ? Nette\Utils\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>' . htmlSpecialChars($col) . '</th>';
                    }
                    $s .= "</tr>";
                    foreach ($explain as $row) {
                        $s .= "<tr>";
                        foreach ($row as $col) {
                            $s .= '<td>' . htmlSpecialChars($col) . '</td>';
                        }
                        $s .= "</tr>";
                    }
                    $s .= "</table>";
                }
                if ($source) {
                    $s .= Nette\Diagnostics\Helpers::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 $this->count ? '<style class="nette-debug"> #nette-debug td.nette-DbConnectionPanel-sql { background: white !important }
			#nette-debug .nette-DbConnectionPanel-source { color: #BBB !important } </style>
			<h1 title="' . htmlSpecialChars($connection->getDsn()) . '">Queries: ' . $this->count . ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . ', ' . htmlSpecialChars($this->name) . '</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>' . (count($this->queries) < $this->count ? '<p>...and more</p>' : '') . '</div>' : '';
        }
Beispiel #13
0
 /**
  * @return string
  * @internal
  */
 public function getRows()
 {
     $self = $this;
     return implode('', array_map(function ($message) use($self) {
         return '<tr>' . '<td class="time">' . 1000 * $self->extractTime($message) . '</td>' . '<td class="sql">' . Database\Helpers::dumpSql($self->extractSql($message)) . $self->extractLink($message) . '</td>' . '<td class="mem">' . $self->extractMem($message) . '</td>' . '<td class="method">' . $self->extractMethod($message) . '</td>' . '</tr>';
     }, $this->messages));
 }