dump() public static method

Prints out a syntax highlighted version of the SQL command or Result.
public static dump ( $sql = NULL, $return = FALSE ) : string
return string
Ejemplo n.º 1
0
 /**
  * Returns custom panels.
  * @return array
  */
 public function getPanels()
 {
     $panels = array();
     if ($this->sql !== NULL) {
         $panels['SQL'] = array('expanded' => TRUE, 'content' => dibi::dump($this->sql, TRUE));
     }
     return $panels;
 }
Ejemplo n.º 2
0
 /**
  * Generates and prints SQL query.
  * @param  array|mixed  one or more arguments
  * @return bool
  */
 public final function test($args)
 {
     $args = func_get_args();
     $this->connect();
     try {
         $translator = new DibiTranslator($this->driver);
         dibi::dump($translator->translate($args));
         return TRUE;
     } catch (DibiException $e) {
         dibi::dump($e->getSql());
         return FALSE;
     }
 }
Ejemplo n.º 3
0
 /**
  * Returns HTML code for custom panel.
  * @return mixed
  */
 public function getPanel()
 {
     if (!dibi::$numOfQueries) {
         return;
     }
     $content = "\n<h1>Queries: " . dibi::$numOfQueries . (dibi::$totalTime === NULL ? '' : ', time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms') . "</h1>\n\n<style>\n\t#nette-debug-DibiProfiler td.dibi-sql { background: white }\n\t#nette-debug-DibiProfiler .nette-alt td.dibi-sql { background: #F5F5F5 }\n\t#nette-debug-DibiProfiler .dibi-sql div { display: none; margin-top: 10px; max-height: 150px; overflow:auto }\n</style>\n\n<div class='nette-inner'>\n<table>\n<tr>\n\t<th>Time</th><th>SQL Statement</th><th>Rows</th><th>Connection</th>\n</tr>\n";
     $i = 0;
     $classes = array('class="nette-alt"', '');
     foreach (self::$tickets as $ticket) {
         list($connection, $event, $sql, $time, $count, $explain) = $ticket;
         if (!($event & self::QUERY)) {
             continue;
         }
         $content .= "\n<tr {$classes[++$i % 2]}>\n\t<td>" . sprintf('%0.3f', $time * 1000) . ($explain ? "\n\t<br><a href='#' class='nette-toggler' rel='#nette-debug-DibiProfiler-row-{$i}'>explain&nbsp;&#x25ba;</a>" : '') . "</td>\n\t<td class='dibi-sql'>" . dibi::dump(strlen($sql) > self::$maxLength ? substr($sql, 0, self::$maxLength) . '...' : $sql, TRUE) . ($explain ? "\n\t<div id='nette-debug-DibiProfiler-row-{$i}'>{$explain}</div>" : '') . "</td>\n\t<td>{$count}</td>\n\t<td>" . htmlSpecialChars($connection->getConfig('driver') . '/' . $connection->getConfig('name')) . "</td>\n</tr>\n";
     }
     $content .= '</table></div>';
     return $content;
 }
Ejemplo n.º 4
0
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">

<h1>Dumping SQL and Result Set | dibi</h1>

<?php 
require dirname(__FILE__) . '/Nette/Debugger.php';
require dirname(__FILE__) . '/../dibi/dibi.php';
dibi::connect(array('driver' => 'sqlite', 'database' => 'data/sample.sdb'));
$res = dibi::query('
	SELECT * FROM products
	INNER JOIN orders USING (product_id)
	INNER JOIN customers USING (customer_id)
');
echo '<h2>dibi::dump()</h2>';
// dump last query (dibi::$sql)
dibi::dump();
// dump result table
echo '<h2>DibiResult::dump()</h2>';
$res->dump();
Ejemplo n.º 5
0
 /**
  * Returns HTML code for custom panel.
  * @return mixed
  */
 public function getPanel()
 {
     return $this->sql ? dibi::dump($this->sql, TRUE) : NULL;
 }
    /**
     * Returns HTML code for custom panel. (Nette\Diagnostics\IBarPanel)
     * @return mixed
     */
    public function getPanel()
    {
        $totalTime = $s = NULL;
        $h = 'htmlSpecialChars';
        foreach ($this->events as $event) {
            $totalTime += $event->time;
            $explain = NULL;
            // EXPLAIN is called here to work SELECT FOUND_ROWS()
            if ($this->explain && $event->type === DibiEvent::SELECT) {
                try {
                    $backup = array($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime);
                    $event->connection->onEvent = NULL;
                    $cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN' : 'EXPLAIN');
                    $explain = dibi::dump($event->connection->nativeQuery("{$cmd} {$event->sql}"), TRUE);
                } catch (DibiException $e) {
                }
                list($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime) = $backup;
            }
            $s .= '<tr><td>' . sprintf('%0.3f', $event->time * 1000);
            if ($explain) {
                static $counter;
                $counter++;
                $s .= "<br /><a href='#' class='nette-toggler' rel='#nette-debug-DibiProfiler-row-{$counter}'>explain&nbsp;&#x25ba;</a>";
            }
            $s .= '</td><td class="nette-DibiProfiler-sql">' . dibi::dump(strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql, TRUE);
            if ($explain) {
                $s .= "<div id='nette-debug-DibiProfiler-row-{$counter}' class='nette-collapsed'>{$explain}</div>";
            }
            if ($event->source) {
                $helpers = 'Nette\\Diagnostics\\Helpers';
                if (!class_exists($helpers)) {
                    $helpers = class_exists('NDebugHelpers') ? 'NDebugHelpers' : 'DebugHelpers';
                }
                $s .= call_user_func(array($helpers, 'editorLink'), $event->source[0], $event->source[1])->class('nette-DibiProfiler-source');
            }
            $s .= "</td><td>{$event->count}</td><td>{$h($event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'))}</td></tr>";
        }
        return empty($this->events) ? '' : '<style> #nette-debug td.nette-DibiProfiler-sql { background: white !important }
			#nette-debug .nette-DibiProfiler-source { color: #999 !important }
			#nette-debug nette-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
			<h1>Queries: ' . count($this->events) . ($totalTime === NULL ? '' : ', time: ' . sprintf('%0.3f', $totalTime * 1000) . ' ms') . '</h1>
			<div class="nette-inner nette-DibiProfiler">
			<table>
				<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Rows</th><th>Connection</th></tr>' . $s . '
			</table>
			</div>';
    }
 /**
  * Generates and prints SQL query.
  * @param  array|mixed  one or more arguments
  * @return bool
  */
 public final function test($args)
 {
     $args = func_get_args();
     try {
         dibi::dump($this->translateArgs($args));
         return TRUE;
     } catch (DibiException $e) {
         if ($e->getSql()) {
             dibi::dump($e->getSql());
         } else {
             echo get_class($e) . ': ' . $e->getMessage() . (PHP_SAPI === 'cli' ? "\n" : '<br>');
         }
         return FALSE;
     }
 }
Ejemplo n.º 8
0
    /**
     * Returns HTML code for custom panel.
     * @return mixed
     */
    public function getPanel()
    {
        $s = NULL;
        $h = 'htmlSpecialChars';
        foreach (self::$tickets as $i => $ticket) {
            list($connection, $event, $sql, $time, $count, $source) = $ticket;
            if (!($event & self::QUERY)) {
                continue;
            }
            $explain = NULL;
            // EXPLAIN is called here to work SELECT FOUND_ROWS()
            if ($this->explainQuery && $event === self::SELECT) {
                try {
                    $explain = dibi::dump($connection->setProfiler(NULL)->nativeQuery('EXPLAIN ' . $sql), TRUE);
                } catch (DibiException $e) {
                }
                $connection->setProfiler($this);
            }
            $s .= '<tr><td>' . sprintf('%0.3f', $time * 1000);
            if ($explain) {
                $s .= "<br /><a href='#' class='nette-toggler' rel='#nette-debug-DibiProfiler-row-{$i}'>explain&nbsp;&#x25ba;</a>";
            }
            $s .= '</td><td class="dibi-sql">' . dibi::dump(strlen($sql) > self::$maxLength ? substr($sql, 0, self::$maxLength) . '...' : $sql, TRUE);
            if ($explain) {
                $s .= "<div id='nette-debug-DibiProfiler-row-{$i}' class='nette-collapsed'>{$explain}</div>";
            }
            if ($source) {
                list($file, $line) = $source;
                $s .= "<span class='dibi-source' title='{$h($file)}:{$line}'>{$h(basename(dirname($file)) . '/' . basename($file))}:{$line}</span>";
            }
            $s .= "</td><td>{$count}</td><td>{$h($connection->getConfig('driver') . '/' . $connection->getConfig('name'))}</td></tr>";
        }
        return $s === NULL ? '' : '<style> #nette-debug-DibiProfiler td.dibi-sql { background: white !important }
			#nette-debug-DibiProfiler .dibi-source { color: #BBB !important }
			#nette-debug-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>

			<h1>Queries: ' . dibi::$numOfQueries . (dibi::$totalTime === NULL ? '' : ', time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms') . '</h1>
			<div class="nette-inner">
			<table>
				<th>Time</th><th>SQL Statement</th><th>Rows</th><th>Connection</th>' . $s . '
			</table>
			</div>';
    }
Ejemplo n.º 9
0
 /**
  * Generates and prints SQL query.
  * @param  array|mixed  one or more arguments
  * @return bool
  */
 public final function test($args)
 {
     $args = func_get_args();
     try {
         dibi::dump($this->translateArgs($args));
         return TRUE;
     } catch (DibiException $e) {
         dibi::dump($e->getSql());
         return FALSE;
     }
 }
Ejemplo n.º 10
0
getTab(){return'<span title="dibi profiler"><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" />'.dibi::$numOfQueries.' queries</span>';}function
getPanel(){$s=NULL;$h='htmlSpecialChars';foreach(self::$tickets
as$i=>$ticket){list($connection,$event,$sql,$time,$count,$source)=$ticket;if(!($event&self::QUERY))continue;$explain=NULL;if($this->explainQuery&&$event===self::SELECT){try{$explain=dibi::dump($connection->setProfiler(NULL)->nativeQuery('EXPLAIN '.$sql),TRUE);}catch(DibiException$e){}$connection->setProfiler($this);}$s.='<tr><td>'.sprintf('%0.3f',$time*1000);if($explain){$s.="<br /><a href='#' class='nette-toggler' rel='#nette-debug-DibiProfiler-row-$i'>explain&nbsp;&#x25ba;</a>";}$s.='</td><td class="dibi-sql">'.dibi::dump(strlen($sql)>self::$maxLength?substr($sql,0,self::$maxLength).'...':$sql,TRUE);if($explain){$s.="<div id='nette-debug-DibiProfiler-row-$i' class='nette-collapsed'>{$explain}</div>";}if($source){list($file,$line)=$source;$s.="<span class='dibi-source' title='{$h($file)}:$line'>{$h(basename(dirname($file)).'/'.basename($file))}:$line</span>";}$s.="</td><td>{$count}</td><td>{$h($connection->getConfig('driver').'/'.$connection->getConfig('name'))}</td></tr>";}return$s===NULL?'':'<style> #nette-debug-DibiProfiler td.dibi-sql { background: white !important }
			#nette-debug-DibiProfiler .dibi-source { color: #BBB !important }
			#nette-debug-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>

			<h1>Queries: '.dibi::$numOfQueries.(dibi::$totalTime===NULL?'':', time: '.sprintf('%0.3f',dibi::$totalTime*1000).' ms').'</h1>
			<div class="nette-inner">
			<table>
				<th>Time</th><th>SQL Statement</th><th>Rows</th><th>Connection</th>'.$s.'
			</table>
			</div>';}function
Ejemplo n.º 11
0
 /**
  * Generates and prints SQL query.
  *
  * @param  array|mixed  one or more arguments
  * @return bool
  */
 public final function test($args)
 {
     $args = func_get_args();
     $this->connect();
     $trans = new DibiTranslator($this->driver);
     $ok = $trans->translate($args);
     dibi::dump($trans->sql);
     return $ok;
 }
Ejemplo n.º 12
0
 /**
  * Actual formatted query, e.g. 'SELECT * FROM ...'
  *
  * @return Html|string
  */
 public function getQuery()
 {
     $html = \dibi::dump($this->event->sql, TRUE);
     return Html::el()->setHtml($html);
 }