Example #1
1
 private static function runQueryWithView($query, $fields, $printArray)
 {
     $_SESSION['tableData'] = array();
     $exec_time_row = array();
     $records = '';
     try {
         // turn on query profiling
         Flight::get('db')->query('SET profiling = 1;');
         $stmt = Flight::get('db')->query($query);
         // find out time above query was ran for
         $exec_time_result = Flight::get('db')->query('SELECT query_id, SUM(duration) FROM information_schema.profiling GROUP BY query_id ORDER BY query_id DESC LIMIT 1;');
         $exec_time_row = $exec_time_result->fetchAll(PDO::FETCH_NUM);
         // run query and fetch array
         $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
         // store table fields/columns + data rows in session for exporting later
         $_SESSION['tableData'] = array_merge($fields, $data);
         $records = Presenter::listTableData($data);
     } catch (PDOException $e) {
         setFlashMessage('Error: ' . $e->getMessage());
     }
     Flight::render('table', array('title' => Flight::get('lastSegment'), 'icon' => self::$icon, 'table_data' => $records, 'fields' => getOptions($fields), 'query' => SqlFormatter::format($query), 'printArray' => $printArray, 'timetaken' => $exec_time_row[0][1]));
 }
Example #2
0
 /**
  * @test
  */
 public function leftJoinStartsOnNewLine()
 {
     $sql = "SELECT a\nFROM t LEFT JOIN b ON t.a  = b.c WHERE b = c";
     $expected = "SELECT a\nFROM t\nLEFT JOIN b ON t.a  = b.c\nWHERE b = c";
     $o = new SqlFormatter();
     $actual = $o->format($sql);
     $this->assertEquals($expected, $actual);
 }
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $this->data = array('queries' => $this->database->getQueries(), 'queryCount' => count($this->database->getQueries()));
     foreach ($this->data['queries'] as &$query) {
         $query['query_formatted'] = \SqlFormatter::format($query['query']);
     }
 }
Example #4
0
 /**
  * @param IQuery $query
  * @param bool $highlight
  * @return String
  * @throws Exception
  */
 public function format(IQuery $query, $highlight = false)
 {
     if (!class_exists('\\SqlFormatter')) {
         throw new Exception('Coult not find the SqlFormatter class by jdorn');
     }
     return \SqlFormatter::format($this->render($query), $highlight);
 }
 function setupTextArea($sql)
 {
     if ($sql == 'HIDE') {
         $this->sugar_smarty->assign("HIGHLIGHTED_SQL", "");
         $this->sugar_smarty->assign("SHOWTEXTAREA", 'none');
         $this->sugar_smarty->assign("HIDEEDITBUTTON", true);
         $parser = new PHPSQLParser($sql);
         $finalParser = $this->finalSQLParse($parser->parsed, "", 0);
     } elseif (!empty($sql)) {
         require_once 'custom/modules/Administration/SweetDBAdmin/sql-formatter/lib/SqlFormatter.php';
         $this->sugar_smarty->assign("HIGHLIGHTED_SQL", SqlFormatter::format($sql));
         $this->sugar_smarty->assign("SHOWTEXTAREA", 'none');
         $parser = new PHPSQLParser($sql);
         $finalParser = $this->finalSQLParse($parser->parsed, "", 0);
     } else {
         $this->sugar_smarty->assign("SHOWTEXTAREA", 'block');
     }
     if (isset($finalParser['TABLE']) || isset($finalParser['FROM'])) {
         if (isset($finalParser['TABLE'])) {
             $this->sugar_smarty->assign("TABLE", $finalParser['TABLE']);
         } else {
             if (count($finalParser['FROM']) == 1) {
                 $this->sugar_smarty->assign("TABLE", $finalParser['FROM'][0]['table']);
             }
         }
     }
 }
/**
 * @var \Zend\Db\Adapter\Driver\Pdo\Result $results
 * @var \Zend\Db\Adapter\Driver\StatementInterface $statement
 */
function renderResults(Result $results, StatementInterface $statement = null)
{
    $headers = [];
    $queryInformation = null;
    $outputData = null;
    $resultContents = null;
    if ($statement) {
        $queryInformation = SqlFormatter::format($statement->getSql());
        if ($statement->getParameterContainer()->count()) {
            $queryInformation .= createTable(array_keys($statement->getParameterContainer()->getNamedArray()), [array_values($statement->getParameterContainer()->getNamedArray())]);
        }
    }
    if ($results->count()) {
        foreach ($results as $result) {
            $headers = array_keys($result);
            $outputData[] = $result;
        }
    }
    // Results
    if ($outputData) {
        $resultContents = createTable([$headers], $outputData);
    }
    // Wrapper Table
    $table = new Table(new ConsoleOutput());
    $table->setHeaders([['Query Results', 'Generated SQL']])->setRows([[$resultContents, $queryInformation]])->render();
}
Example #7
0
 public function view()
 {
     /* @var $view \Doctrine\DBAL\Schema\View */
     $view = $this->__view;
     $this->view_name = $view->getName();
     $this->set('view_sql', \SqlFormatter::format($view->getSql()), false);
 }
Example #8
0
 public function disp_val()
 {
     if (Rend::$sql_pretty) {
         return \SqlFormatter::format($this->raw, false);
     } else {
         return parent::disp_val();
     }
 }
 /**
  * @return bool
  * @throws ValidationFailedException
  */
 public function validate()
 {
     $queryArray = \SqlFormatter::splitQuery($this->queryString);
     $pattern = '/\\*/';
     if ($this->stringHasRegexInstance($queryArray, $pattern)) {
         throw new ValidationFailedException("Query has to have all wished columns defined, no '*' is allowed", 500);
     }
     return true;
 }
Example #10
0
 /**
  * @param OutputInterface $output
  */
 protected function showCreates($output)
 {
     $creates = $this->app['schema.comparator']->getCreates();
     if ($creates) {
         $output->writeln('<info>Tables to be created:</info>');
         foreach ($creates as $tableName => $sql) {
             $output->writeln("\n");
             $output->writeln(\SqlFormatter::format($sql[0]));
             $output->writeln("\n");
         }
     }
 }
 /**
  * Internal helper function which returns all traced doctrine queries
  * which executed over the Shopware()->Models() manager.
  *
  * @return array
  */
 public function getDoctrineQueries()
 {
     $queries = array();
     /**@var $logger \Doctrine\DBAL\Logging\DebugStack */
     $logger = Shopware()->Models()->getConfiguration()->getSQLLogger();
     foreach ($logger->queries as $query) {
         $explain = $this->getSqlExplain($query['sql'], $query['params']);
         $sql = $this->getQuerySql($query['sql']);
         $this->sqlTime += $query['executionMS'];
         $queries[] = array('sql' => SqlFormatter::format($sql), 'short' => $this->getShortSql($sql), 'explain' => $explain, 'status' => $this->getQueryStatus($explain), 'params' => $query['params'], 'time' => number_format($query['executionMS'], 5));
     }
     return $queries;
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function startQuery($sql, array $params = null, array $types = null)
 {
     $this->start = microtime(true);
     $replacedSql = $sql;
     if ($params) {
         foreach ($params as $param => $value) {
             $value = is_string($value) ? "'" . $value . "'" : $value;
             $replacedSql = str_replace($param, $value, $replacedSql);
         }
     }
     echo SqlFormatter::format($replacedSql) . '</br></br>';
     parent::startQuery($sql, $params, $types);
 }
function print_sql($query)
{
    if ($GLOBALS['cli']) {
        print_vars($query);
    } else {
        if (class_exists('SqlFormatter')) {
            // Hide it under a "database icon" popup.
            #echo overlib_link('#', '<i class="oicon-databases"> </i>', SqlFormatter::highlight($query));
            echo '<p>', SqlFormatter::highlight($query), '</p>';
        } else {
            print_vars($query);
        }
    }
}
 /**
  * execute
  *
  * Action attached to the query listener.
  * It attaches each new query in a query stack.
  *
  * @access public
  * @param  name     event name
  * @param  array    $data
  * @param  Session  $session
  * @return null
  */
 public function execute($name, $data, Session $session)
 {
     if (!in_array($name, array('query:pre', 'query:post'))) {
         return;
     }
     if ('query:post' === $name) {
         end($this->queries);
         $key = key($this->queries);
         reset($this->queries);
         $this->queries[$key] += $data;
         return;
     }
     $this->queries[] = ['sql' => \SqlFormatter::format($data['sql'], true), 'parameters' => $data['parameters']];
 }
 /**
  * @return bool
  * @throws ValidationFailedException
  */
 public function validate()
 {
     $arrayOfQueries = \SqlFormatter::splitQuery($this->queryString);
     $queryString = array_map("strtolower", $arrayOfQueries);
     $tableNames = array_map("strtolower", $this->limits["table_names"]);
     $tableNamesString = $this->getTableNamesStringForRegex($tableNames);
     $regex = "/(from" . ValidTableNameValidator::ANY_SPACE_META_SEQUENCE_PATTERN . "({$tableNamesString}))/";
     $hasJoinCommand = "/join/";
     if ($this->stringHasRegexInstance($queryString, $hasJoinCommand)) {
         $regexJoinCommand = "/(join" . ValidTableNameValidator::ANY_SPACE_META_SEQUENCE_PATTERN . "({$tableNamesString}))/";
         $result = $this->stringHasRegexInstance($queryString, $regex) && $this->stringHasRegexInstance($queryString, $regexJoinCommand);
         if (!$result) {
             throw new ValidationFailedException("The given query does not contain a valid table in the Join statement.", 500);
         }
         return $result;
     }
     if (!$this->stringHasRegexInstance($queryString, $regex)) {
         $helper = "<em>Check that the tables specify the schema</em>";
         throw new ValidationFailedException("<p>The given query does not contain a valid table.</p>{$helper}", 500);
     }
     return true;
 }
Example #16
0
 /**
  * @param string $sql parameter query yang akan di-execute
  * @return mixed me-return array kosong jika parameter $sql == "", jika tidak maka akan me-return array data hasil execute SQL
  */
 public function query($params = [])
 {
     $paramDefs = $params;
     $params = array_merge($params, $this->queryParams);
     if (trim($this->sql) == "") {
         return [];
     }
     $db = Yii::app()->db;
     $template = DataSource::generateTemplate($this->sql, $params, $this, $paramDefs);
     ## execute SQL
     $this->command = $db->createCommand($template['sql']);
     $data = $this->command->queryAll(true, $template['params']);
     ## if should count, then count..
     if ($this->lastCount == 0) {
         if ($this->enablePaging == 'Yes') {
             $tc = DataSource::generateTemplate($this->pagingSQL, $params, $this);
             $count = $db->createCommand($tc['sql'])->queryAll(true, $tc['params']);
             if (count($count) > 0) {
                 $count = array_values($count[0]);
                 $count = $count[0];
             } else {
                 $count = 0;
             }
             $template['countSQL'] = $tc['sql'];
         } else {
             $count = count($data);
         }
     } else {
         $count = $this->lastCount;
         ## default shouldcount to true;
         $this->lastCount = 0;
     }
     $template['count'] = $count;
     $template['timestamp'] = date('Y-m-d H:i:s');
     $template['sql'] = SqlFormatter::format($template['sql']);
     ## return data
     return ['data' => $data, 'count' => $count, 'debug' => $template];
 }
Example #17
0
<?php

if (php_sapi_name() !== "cli") {
    echo "<p>Run this php script from the command line to see CLI syntax highlighting and formatting.  It support Unix pipes or command line argument style.</p>";
    echo "<pre><code>php examples/cli.php \"SELECT * FROM MyTable WHERE (id>5 AND \\`name\\` LIKE \\&quot;testing\\&quot;);\"</code></pre>";
    echo "<pre><code>echo \"SELECT * FROM MyTable WHERE (id>5 AND \\`name\\` LIKE \\&quot;testing\\&quot;);\" | php examples/cli.php</code></pre>";
}
if (isset($argv[1])) {
    $sql = $argv[1];
} else {
    $sql = stream_get_contents(fopen("php://stdin", "r"));
}
require_once __DIR__ . '/../lib/SqlFormatter.php';
echo SqlFormatter::format($sql);
 public function block_queries($context, array $blocks = array())
 {
     // line 56
     echo "    <h2>Queries</h2>\n\n    ";
     // line 58
     $context['_parent'] = (array) $context;
     $context['_seq'] = twig_ensure_traversable($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "queries"));
     $context['loop'] = array('parent' => $context['_parent'], 'index0' => 0, 'index' => 1, 'first' => true);
     if (is_array($context['_seq']) || is_object($context['_seq']) && $context['_seq'] instanceof Countable) {
         $length = count($context['_seq']);
         $context['loop']['revindex0'] = $length - 1;
         $context['loop']['revindex'] = $length;
         $context['loop']['length'] = $length;
         $context['loop']['last'] = 1 === $length;
     }
     foreach ($context['_seq'] as $context["connection"] => $context["queries"]) {
         // line 59
         echo "        <h3>Connection <em>";
         echo twig_escape_filter($this->env, isset($context["connection"]) ? $context["connection"] : $this->getContext($context, "connection"), "html", null, true);
         echo "</em></h3>\n        ";
         // line 60
         if (twig_test_empty(isset($context["queries"]) ? $context["queries"] : $this->getContext($context, "queries"))) {
             // line 61
             echo "            <p>\n                <em>No queries.</em>\n            </p>\n        ";
         } else {
             // line 65
             echo "            <ul class=\"alt\" id=\"queriesPlaceholder-";
             echo twig_escape_filter($this->env, $this->getAttribute(isset($context["loop"]) ? $context["loop"] : $this->getContext($context, "loop"), "index"), "html", null, true);
             echo "\">\n                ";
             // line 66
             $context['_parent'] = (array) $context;
             $context['_seq'] = twig_ensure_traversable(isset($context["queries"]) ? $context["queries"] : $this->getContext($context, "queries"));
             $context['loop'] = array('parent' => $context['_parent'], 'index0' => 0, 'index' => 1, 'first' => true);
             if (is_array($context['_seq']) || is_object($context['_seq']) && $context['_seq'] instanceof Countable) {
                 $length = count($context['_seq']);
                 $context['loop']['revindex0'] = $length - 1;
                 $context['loop']['revindex'] = $length;
                 $context['loop']['length'] = $length;
                 $context['loop']['last'] = 1 === $length;
             }
             foreach ($context['_seq'] as $context["i"] => $context["query"]) {
                 // line 67
                 echo "                    <li class=\"";
                 echo twig_escape_filter($this->env, twig_cycle(array(0 => "odd", 1 => "even"), isset($context["i"]) ? $context["i"] : $this->getContext($context, "i")), "html", null, true);
                 echo "\" data-extra-info=\"";
                 echo twig_escape_filter($this->env, sprintf("%0.2f", $this->getAttribute(isset($context["query"]) ? $context["query"] : $this->getContext($context, "query"), "executionMS") * 1000), "html", null, true);
                 echo "\" data-target-id=\"";
                 echo twig_escape_filter($this->env, isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"), "html", null, true);
                 echo "\">\n                        <div style=\"margin-top: 4px\" id=\"queryNo-";
                 // line 68
                 echo twig_escape_filter($this->env, isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"), "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute(isset($context["loop"]) ? $context["loop"] : $this->getContext($context, "loop"), "parent"), "loop"), "index"), "html", null, true);
                 echo "\">\n                            <div onclick=\"return expandQuery(this);\" title=\"Expand query\" data-target-id=\"code-";
                 // line 69
                 echo twig_escape_filter($this->env, isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"), "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute(isset($context["loop"]) ? $context["loop"] : $this->getContext($context, "loop"), "parent"), "loop"), "index"), "html", null, true);
                 echo "\" style=\"cursor: pointer;\">\n                                <img alt=\"+\" src=\"";
                 // line 70
                 echo twig_escape_filter($this->env, $this->env->getExtension('assets')->getAssetUrl("bundles/framework/images/blue_picto_more.gif"), "html", null, true);
                 echo "\" style=\"display: inline;\" />\n                                <img alt=\"-\" src=\"";
                 // line 71
                 echo twig_escape_filter($this->env, $this->env->getExtension('assets')->getAssetUrl("bundles/framework/images/blue_picto_less.gif"), "html", null, true);
                 echo "\" style=\"display: none;\" />\n                                <span style=\"display: none\">Shrink query</span>\n                                <span id=\"smallcode-";
                 // line 73
                 echo twig_escape_filter($this->env, isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"), "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute(isset($context["loop"]) ? $context["loop"] : $this->getContext($context, "loop"), "parent"), "loop"), "index"), "html", null, true);
                 echo "\">\n                                    ";
                 // line 74
                 echo $this->env->getExtension('doctrine_extension')->minifyQuery($this->getAttribute(isset($context["query"]) ? $context["query"] : $this->getContext($context, "query"), "sql"));
                 echo "\n                                </span>\n                            </div>\n                            <code id=\"code-";
                 // line 77
                 echo twig_escape_filter($this->env, isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"), "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute(isset($context["loop"]) ? $context["loop"] : $this->getContext($context, "loop"), "parent"), "loop"), "index"), "html", null, true);
                 echo "\">\n                                ";
                 // line 78
                 echo SqlFormatter::format($this->getAttribute(isset($context["query"]) ? $context["query"] : $this->getContext($context, "query"), "sql"), isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"), $this->getAttribute($this->getAttribute($this->getAttribute(isset($context["loop"]) ? $context["loop"] : $this->getContext($context, "loop"), "parent"), "loop"), "index"));
                 echo "\n                            </code>\n                            <span id=\"original-query-";
                 // line 80
                 echo twig_escape_filter($this->env, isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"), "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute(isset($context["loop"]) ? $context["loop"] : $this->getContext($context, "loop"), "parent"), "loop"), "index"), "html", null, true);
                 echo "\" style=\"display: none;\">\n                                ";
                 // line 81
                 echo $this->env->getExtension('doctrine_extension')->replaceQueryParameters($this->getAttribute(isset($context["query"]) ? $context["query"] : $this->getContext($context, "query"), "sql"), $this->getAttribute(isset($context["query"]) ? $context["query"] : $this->getContext($context, "query"), "params"));
                 echo "\n                            </span>\n                            <small>\n                                <strong>Parameters</strong>: ";
                 // line 84
                 echo twig_escape_filter($this->env, $this->env->getExtension('yaml')->encode($this->getAttribute(isset($context["query"]) ? $context["query"] : $this->getContext($context, "query"), "params")), "html", null, true);
                 echo " <br />\n                                [<span id=\"expandParams-";
                 // line 85
                 echo twig_escape_filter($this->env, isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"), "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute(isset($context["loop"]) ? $context["loop"] : $this->getContext($context, "loop"), "parent"), "loop"), "index"), "html", null, true);
                 echo "\" onclick=\"javascript:toggleRunnableQuery(this);\" target-data-id=\"original-query-";
                 echo twig_escape_filter($this->env, isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"), "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute(isset($context["loop"]) ? $context["loop"] : $this->getContext($context, "loop"), "parent"), "loop"), "index"), "html", null, true);
                 echo "\" style=\"cursor: pointer;\">Display runnable query</span>]<br/>\n                                <strong>Time</strong>: ";
                 // line 86
                 echo twig_escape_filter($this->env, sprintf("%0.2f", $this->getAttribute(isset($context["query"]) ? $context["query"] : $this->getContext($context, "query"), "executionMS") * 1000), "html", null, true);
                 echo " ms\n                            </small>\n                            ";
                 // line 88
                 if ($this->getAttribute(isset($context["query"]) ? $context["query"] : $this->getContext($context, "query"), "explainable")) {
                     // line 89
                     echo "                                [<a href=\"";
                     echo twig_escape_filter($this->env, $this->env->getExtension('routing')->getPath("_profiler", array("panel" => "db", "token" => isset($context["token"]) ? $context["token"] : $this->getContext($context, "token"), "page" => "explain", "connection" => isset($context["connection"]) ? $context["connection"] : $this->getContext($context, "connection"), "query" => isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"))), "html", null, true);
                     echo "\" onclick=\"return explain(this);\" style=\"text-decoration: none;\" title=\"Explains the query\" data-target-id=\"explain-";
                     echo twig_escape_filter($this->env, isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"), "html", null, true);
                     echo "-";
                     echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute(isset($context["loop"]) ? $context["loop"] : $this->getContext($context, "loop"), "parent"), "loop"), "index"), "html", null, true);
                     echo "\" >\n                                    <img alt=\"+\" src=\"";
                     // line 90
                     echo twig_escape_filter($this->env, $this->env->getExtension('assets')->getAssetUrl("bundles/framework/images/blue_picto_more.gif"), "html", null, true);
                     echo "\" style=\"display: inline; width: 12px; height: 12px;\" />\n                                    <img alt=\"-\" src=\"";
                     // line 91
                     echo twig_escape_filter($this->env, $this->env->getExtension('assets')->getAssetUrl("bundles/framework/images/blue_picto_less.gif"), "html", null, true);
                     echo "\" style=\"display: none; width: 12px; height: 12px;\" />\n                                    <span style=\"vertical-align:top\">Explain query</span>\n                                </a>]\n                            ";
                 } else {
                     // line 95
                     echo "                                This query cannot be explained\n                            ";
                 }
                 // line 97
                 echo "                        </div>\n                        ";
                 // line 98
                 if ($this->getAttribute(isset($context["query"]) ? $context["query"] : $this->getContext($context, "query"), "explainable")) {
                     // line 99
                     echo "                        <div id=\"explain-";
                     echo twig_escape_filter($this->env, isset($context["i"]) ? $context["i"] : $this->getContext($context, "i"), "html", null, true);
                     echo "-";
                     echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute(isset($context["loop"]) ? $context["loop"] : $this->getContext($context, "loop"), "parent"), "loop"), "index"), "html", null, true);
                     echo "\" class=\"loading\"></div>\n                        ";
                 }
                 // line 101
                 echo "                    </li>\n                ";
                 ++$context['loop']['index0'];
                 ++$context['loop']['index'];
                 $context['loop']['first'] = false;
                 if (isset($context['loop']['length'])) {
                     --$context['loop']['revindex0'];
                     --$context['loop']['revindex'];
                     $context['loop']['last'] = 0 === $context['loop']['revindex0'];
                 }
             }
             $_parent = $context['_parent'];
             unset($context['_seq'], $context['_iterated'], $context['i'], $context['query'], $context['_parent'], $context['loop']);
             $context = array_intersect_key($context, $_parent) + $_parent;
             // line 103
             echo "            </ul>\n        ";
         }
         // line 105
         echo "    ";
         ++$context['loop']['index0'];
         ++$context['loop']['index'];
         $context['loop']['first'] = false;
         if (isset($context['loop']['length'])) {
             --$context['loop']['revindex0'];
             --$context['loop']['revindex'];
             $context['loop']['last'] = 0 === $context['loop']['revindex0'];
         }
     }
     $_parent = $context['_parent'];
     unset($context['_seq'], $context['_iterated'], $context['connection'], $context['queries'], $context['_parent'], $context['loop']);
     $context = array_intersect_key($context, $_parent) + $_parent;
     // line 106
     echo "\n    <h2>Database Connections</h2>\n\n    ";
     // line 109
     if ($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "connections")) {
         // line 110
         echo "        ";
         $this->env->loadTemplate("WebProfilerBundle:Profiler:table.html.twig")->display(array("data" => $this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "connections")));
         // line 111
         echo "    ";
     } else {
         // line 112
         echo "        <p>\n            <em>No connections.</em>\n        </p>\n    ";
     }
     // line 116
     echo "\n    <h2>Entity Managers</h2>\n\n    ";
     // line 119
     if ($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "managers")) {
         // line 120
         echo "        ";
         $this->env->loadTemplate("WebProfilerBundle:Profiler:table.html.twig")->display(array("data" => $this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "managers")));
         // line 121
         echo "    ";
     } else {
         // line 122
         echo "        <p>\n            <em>No entity managers.</em>\n        </p>\n    ";
     }
     // line 126
     echo "\n    <h2>Mapping</h2>\n\n    ";
     // line 129
     $context['_parent'] = (array) $context;
     $context['_seq'] = twig_ensure_traversable($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "entities"));
     foreach ($context['_seq'] as $context["manager"] => $context["classes"]) {
         // line 130
         echo "        <h3>Manager <em>";
         echo twig_escape_filter($this->env, isset($context["manager"]) ? $context["manager"] : $this->getContext($context, "manager"), "html", null, true);
         echo "</em></h3>\n        ";
         // line 131
         if (twig_test_empty(isset($context["classes"]) ? $context["classes"] : $this->getContext($context, "classes"))) {
             // line 132
             echo "            <p><em>No loaded entities.</em></p>\n        ";
         } else {
             // line 134
             echo "            <table>\n                <thead>\n                <tr>\n                    <th scope=\"col\">Class</th>\n                    <th scope=\"col\">Mapping errors</th>\n                </tr>\n                </thead>\n                <tbody>\n                ";
             // line 142
             $context['_parent'] = (array) $context;
             $context['_seq'] = twig_ensure_traversable(isset($context["classes"]) ? $context["classes"] : $this->getContext($context, "classes"));
             foreach ($context['_seq'] as $context["_key"] => $context["class"]) {
                 // line 143
                 echo "                    <tr>\n                        <td>";
                 // line 144
                 echo twig_escape_filter($this->env, isset($context["class"]) ? $context["class"] : $this->getContext($context, "class"), "html", null, true);
                 echo "</td>\n                        <td>\n                            ";
                 // line 146
                 if ($this->getAttribute($this->getAttribute($this->getAttribute(isset($context["collector"]) ? $context["collector"] : null, "mappingErrors", array(), "any", false, true), isset($context["manager"]) ? $context["manager"] : $this->getContext($context, "manager"), array(), "array", false, true), isset($context["class"]) ? $context["class"] : $this->getContext($context, "class"), array(), "array", true, true)) {
                     // line 147
                     echo "                                <ul>\n                                    ";
                     // line 148
                     $context['_parent'] = (array) $context;
                     $context['_seq'] = twig_ensure_traversable($this->getAttribute($this->getAttribute($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "mappingErrors"), isset($context["manager"]) ? $context["manager"] : $this->getContext($context, "manager"), array(), "array"), isset($context["class"]) ? $context["class"] : $this->getContext($context, "class"), array(), "array"));
                     foreach ($context['_seq'] as $context["_key"] => $context["error"]) {
                         // line 149
                         echo "                                        <li>";
                         echo twig_escape_filter($this->env, isset($context["error"]) ? $context["error"] : $this->getContext($context, "error"), "html", null, true);
                         echo "</li>\n                                    ";
                     }
                     $_parent = $context['_parent'];
                     unset($context['_seq'], $context['_iterated'], $context['_key'], $context['error'], $context['_parent'], $context['loop']);
                     $context = array_intersect_key($context, $_parent) + $_parent;
                     // line 151
                     echo "                                </ul>\n                            ";
                 } else {
                     // line 153
                     echo "                                Valid\n                            ";
                 }
                 // line 155
                 echo "                        </td>\n                    </tr>\n                ";
             }
             $_parent = $context['_parent'];
             unset($context['_seq'], $context['_iterated'], $context['_key'], $context['class'], $context['_parent'], $context['loop']);
             $context = array_intersect_key($context, $_parent) + $_parent;
             // line 158
             echo "                </tbody>\n            </table>\n        ";
         }
         // line 161
         echo "    ";
     }
     $_parent = $context['_parent'];
     unset($context['_seq'], $context['_iterated'], $context['manager'], $context['classes'], $context['_parent'], $context['loop']);
     $context = array_intersect_key($context, $_parent) + $_parent;
     // line 162
     echo "\n    <script type=\"text/javascript\">//<![CDATA[\n        function explain(link) {\n            \"use strict\";\n\n            var imgs = link.children,\n                target = link.getAttribute('data-target-id');\n\n            Sfjs.toggle(target, imgs[0], imgs[1])\n                .load(\n                    target,\n                    link.href,\n                    null,\n                    function(xhr, el) {\n                        el.innerHTML = 'An error occurred while loading the details';\n                        Sfjs.removeClass(el, 'loading');\n                    }\n                );\n\n            return false;\n        }\n\n        function expandQuery(link) {\n            var sections = link.children,\n                target = link.getAttribute('data-target-id'),\n                targetId = target.replace('code', ''),\n                queriesParameters = document.getElementById('original-query' + targetId);\n\n            if (queriesParameters.style.display != 'none') {\n                queriesParameters.style.display = 'none';\n                document.getElementById('small' + target).style.display = 'inline';\n                document.getElementById('expandParams' + targetId).innerHTML = 'Display runnable query';\n            }\n\n            if (document.getElementById('small' + target).style.display != 'none') {\n                document.getElementById('small' + target).style.display = 'none';\n                document.getElementById(target).style.display = 'inline';\n\n                sections[0].style.display = 'none';\n                sections[1].style.display = 'inline';\n                sections[2].style.display = 'inline';\n            } else {\n                document.getElementById('small' + target).style.display = 'inline';\n                document.getElementById(target).style.display = 'none';\n\n                sections[0].style.display = 'inline';\n                sections[1].style.display = 'none';\n                sections[2].style.display = 'none';\n            }\n\n            return false;\n        }\n\n        function toggleRunnableQuery(target) {\n            var targetId = target.getAttribute('target-data-id').replace('original-query', ''),\n                targetElement = document.getElementById(target.getAttribute('target-data-id')),\n                elem;\n\n            if (targetElement.style.display != 'block') {\n                targetElement.style.display = 'block';\n                target.innerHTML = 'Hide runnable query';\n\n                document.getElementById('smallcode' + targetId).style.display = 'none';\n                document.getElementById('code' + targetId).style.display = 'none';\n\n                elem = document.getElementById('code' + targetId).parentElement.children[0];\n\n                elem.children[0].style.display = 'inline';\n                elem.children[1].style.display = 'none';\n                elem.children[2].style.display = 'none';\n\n            } else {\n                targetElement.style.display = 'none';\n                target.innerHTML = 'Display runnable query';\n\n                document.getElementById('smallcode' + targetId).style.display = 'inline';\n            }\n        }\n\n    //]]></script>\n\n    <style>\n        h3 {\n            margin-bottom: 0px;\n        }\n\n        code {\n            display: none;\n        }\n\n        code pre {\n            padding: 5px;\n        }\n    </style>\n";
 }
 /**
  * Stuff that only needs to be done once.  Builds regular expressions and sorts the reserved words.
  */
 protected static function init()
 {
     if (self::$init) {
         return;
     }
     // Sort reserved word list from longest word to shortest, 3x faster than usort
     $reservedMap = array_combine(self::$reserved, array_map('strlen', self::$reserved));
     arsort($reservedMap);
     self::$reserved = array_keys($reservedMap);
     // Set up regular expressions
     self::$regex_boundaries = '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$boundaries)) . ')';
     self::$regex_reserved = '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved)) . ')';
     self::$regex_reserved_toplevel = str_replace(' ', '\\s+', '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved_toplevel)) . ')');
     self::$regex_reserved_newline = str_replace(' ', '\\s+', '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved_newline)) . ')');
     self::$regex_function = '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$functions)) . ')';
     self::$init = true;
 }
Example #20
0
 /**
  * Row::buildTableSchema()
  *
  * @return
  */
 public function buildTableSchema()
 {
     $this->cells['table']->info = 'No table schema informations';
     try {
         $table_schema = DB::conn()->fetchPairs("SHOW CREATE TABLE `{$this->cells['table']->v}`");
         $this->cells['table']->info = '<p>Table Schema</p>';
         $this->cells['table']->info .= \SqlFormatter::format($table_schema[$this->cells['table']->v]);
         $this->uses_table = true;
     } catch (DB_Exception $e) {
     }
 }
 /**
  * format
  *
  * @param   string  $sql
  *
  * @return  String
  */
 protected function format($sql)
 {
     return \SqlFormatter::format((string) $sql, false);
 }
 /**
  *  Shows the debugging console, <i>if</i> {@link debug} is TRUE and the viewer's IP address is in the
  *  {@link debugger_ip} array (or <i>$debugger_ip</i> is an empty array).
  *
  *  <i>This method must be called after all the queries in a script, preferably before </body>!</i>
  *
  *  <b>You should ALWAYS have this method called at the end of your scripts and control whether the debugging console
  *  will show or not with the {@link debug} property.</b>
  *
  *  @param  boolean $return         (Optional) If set to TRUE, the output will be returned instead of being printed
  *                                  to the screen.
  *
  *                                  Default is FALSE.
  *
  *  @return void
  */
 function show_debug_console($return = false)
 {
     // if
     if ($this->debug && is_array($this->debugger_ip) && (empty($this->debugger_ip) || in_array($_SERVER['REMOTE_ADDR'], $this->debugger_ip))) {
         // include the SqlFormatter library
         require 'includes/SqlFormatter.php';
         // set some properties for the formatter
         SqlFormatter::$number_attributes = SqlFormatter::$boundary_attributes = 'class="symbol"';
         SqlFormatter::$quote_attributes = 'class="string"';
         SqlFormatter::$reserved_attributes = 'class="keyword"';
         SqlFormatter::$tab = '    ';
         // if warnings are not disabled
         if (!$this->disable_warnings) {
             // if there are any warning messages iterate through them
             foreach (array_keys($this->warnings) as $warning) {
                 // add them to the debugging console
                 $this->_log('warnings', array('message' => $this->language['warning_' . $warning]), false);
             }
         }
         // blocks to be shown in the debugging console
         $blocks = array('errors' => array('counter' => 0, 'identifier' => 'e', 'generated' => ''), 'successful-queries' => array('counter' => 0, 'identifier' => 'sq', 'generated' => ''), 'unsuccessful-queries' => array('counter' => 0, 'identifier' => 'uq', 'generated' => ''), 'warnings' => array('counter' => 0, 'identifier' => 'w', 'generated' => ''), 'globals' => array('generated' => ''));
         // there are no warnings
         $warnings = false;
         // prepare output for each block
         foreach (array_keys($blocks) as $block) {
             $output = '';
             // if there is any information for the current block
             if (isset($this->debug_info[$block])) {
                 // iterate through the error message
                 foreach ($this->debug_info[$block] as $debug_info) {
                     // increment the messages counter
                     $counter = ++$blocks[$block]['counter'];
                     $identifier = $blocks[$block]['identifier'];
                     // if block is about queries
                     if ($block == 'successful-queries' || $block == 'unsuccessful-queries') {
                         // format and highlight query
                         $debug_info['query'] = SqlFormatter::format($debug_info['query']);
                     }
                     // all blocks are enclosed in tables
                     $output .= '
                         <table cellspacing="0" cellpadding="0" border="0" class="zdc-entry' . ($counter % 2 == 0 ? ' even' : '') . (isset($debug_info['highlight']) && $debug_info['highlight'] == 1 ? ' zdc-highlight' : '') . '">
                             <tr>
                                 <td class="zdc-counter" valign="top">' . str_pad($counter, 3, '0', STR_PAD_LEFT) . '</td>
                                 <td class="zdc-data">
                     ';
                     // are there any error messages issued by the script?
                     if (isset($debug_info['message']) && trim($debug_info['message']) != '') {
                         $output .= '
                             <div class="zdc-box zdc-error">
                                 ' . $debug_info['message'] . '
                             </div>
                         ';
                     }
                     // are there any error messages issued by MySQL?
                     if (isset($debug_info['error']) && trim($debug_info['error']) != '') {
                         $output .= '
                             <div class="zdc-box zdc-error">
                                 ' . $debug_info['error'] . '
                             </div>
                         ';
                     }
                     // are there any warning messages issued by the script?
                     if (isset($debug_info['warning']) && trim($debug_info['warning']) != '') {
                         $output .= '
                             <div class="zdc-box zdc-error">' . $debug_info['warning'] . '
                             </div>
                         ';
                         // set a flag so that we show in the minimized debugging console that there are warnings
                         $warnings = true;
                     }
                     // is there a query to be displayed?
                     if (isset($debug_info['query'])) {
                         $output .= '
                             <div class="zdc-box' . (isset($debug_info['transaction']) && $debug_info['transaction'] ? ' zdc-transaction' : '') . '">' . preg_replace('/^\\<br\\>/', '', html_entity_decode($debug_info['query'])) . '
                             </div>
                         ';
                     }
                     // start generating the actions box
                     $output .= '
                         <div class="zdc-box zdc-actions">
                             <ul>
                     ';
                     // actions specific to successful queries
                     if ($block == 'successful-queries') {
                         // info about whether the query results were taken from cache or not
                         if ($debug_info['from_cache'] != 'nocache') {
                             $output .= '
                                 <li class="zdc-cache">
                                     <strong>' . $this->language['from_cache'] . ' (' . $this->caching_method . ')</strong>
                                 </li>
                             ';
                         }
                         // info about execution time
                         $output .= '
                             <li class="zdc-time">' . $this->language['execution_time'] . ': ' . $this->_fix_pow($debug_info['execution_time']) . ' ' . $this->language['miliseconds'] . ' (<strong>' . number_format($this->total_execution_time != 0 ? $debug_info['execution_time'] * 100 / $this->total_execution_time : 0, 2, '.', ',') . '</strong>%)
                             </li>
                         ';
                         // if not an action query
                         if ($debug_info['affected_rows'] === false) {
                             // button for reviewing returned rows
                             $output .= '
                                 <li class="zdc-records">
                                     <a href="javascript:zdc_toggle(\'zdc-records-sq' . $counter . '\')">' . $this->language['returned_rows'] . ': <strong>' . $debug_info['returned_rows'] . '</strong>
                                     </a>
                                 </li>
                             ';
                         } else {
                             // info about affected rows
                             $output .= '
                                 <li class="zdc-affected">' . $this->language['affected_rows'] . ': <strong>' . $debug_info['affected_rows'] . '</strong>
                                 </li>
                             ';
                         }
                         // if EXPLAIN is available (only for SELECT queries)
                         if (is_array($debug_info['explain'])) {
                             // button for reviewing EXPLAIN results
                             $output .= '
                                 <li class="zdc-explain">
                                     <a href="javascript:zdc_toggle(\'zdc-explain-sq' . $counter . '\')">' . $this->language['explain'] . '
                                     </a>
                                 </li>
                             ';
                         }
                     }
                     // if backtrace information is available
                     if (isset($debug_info['backtrace'])) {
                         $output .= '
                             <li class="zdc-backtrace">
                                 <a href="javascript:zdc_toggle(\'zdc-backtrace-' . $identifier . $counter . '\')">' . $this->language['backtrace'] . '
                                 </a>
                             </li>
                         ';
                     }
                     // common actions (to top, close all)
                     $output .= '
                         <li class="zdc-top">
                             <a href="' . preg_replace('/\\#zdc\\-top$/i', '', $_SERVER['REQUEST_URI']) . '#zdc-top">' . $this->language['to_top'] . '
                             </a>
                         </li>
                         <li class="zdc-close">
                             <a href="javascript:zdc_closeAll(\'\')">' . $this->language['close_all'] . '
                             </a>
                         </li>
                     ';
                     // wrap up actions bar
                     $output .= '
                             </ul>
                             <div class="clear"></div>
                         </div>
                     ';
                     // data tables (backtrace, returned rows, explain)
                     // let's see what tables do we need to display
                     $tables = array();
                     // if query did return records
                     if (!empty($debug_info['records'])) {
                         $tables[] = 'records';
                     }
                     // if explain is available
                     if (isset($debug_info['explain']) && is_array($debug_info['explain'])) {
                         $tables[] = 'explain';
                     }
                     // if backtrace is available
                     if (isset($debug_info['backtrace'])) {
                         $tables[] = 'backtrace';
                     }
                     // let's display data
                     foreach ($tables as $table) {
                         // start generating output
                         $output .= '
                             <div id="zdc-' . $table . '-' . $identifier . $counter . '" class="zdc-box zdc-' . $table . '-table">
                                 <table cellspacing="0" cellpadding="0" border="0">
                                     <tr>
                         ';
                         // print table headers
                         foreach (array_keys($debug_info[$table][0]) as $header) {
                             $output .= '<th>' . $header . '</th>';
                         }
                         $output .= '</tr>';
                         // print table rows and columns
                         foreach ($debug_info[$table] as $index => $row) {
                             $output .= '<tr class="' . (($index + 1) % 2 == 0 ? 'even' : '') . '">';
                             foreach (array_values($row) as $column) {
                                 $output .= '<td valign="top">' . $column . '</td>';
                             }
                             $output .= '</tr>';
                         }
                         // wrap up data tables
                         $output .= '
                                 </table>
                             </div>
                         ';
                     }
                     // finish block
                     $output .= '
                                 </td>
                             </tr>
                         </table>
                     ';
                 }
                 // if anything was generated for the current block
                 // enclose generated output in a special div
                 if ($counter > 0) {
                     $blocks[$block]['generated'] = '<div id="zdc-' . $block . '">' . $output . '</div>';
                 }
             } elseif ($block == 'globals') {
                 // globals to show
                 $globals = array('POST', 'GET', 'SESSION', 'COOKIE', 'FILES', 'SERVER');
                 // start building output
                 $output = '
                     <div id="zdc-globals-submenu">
                         <ul>
                 ';
                 // iterate through the superglobals to show
                 foreach ($globals as $global) {
                     // add button to submenu
                     $output .= '<li>
                             <a href="javascript:zdc_toggle(\'zdc-globals-' . strtolower($global) . '\')">$_' . $global . '
                             </a>
                         </li>
                     ';
                 }
                 // finish building the submenu
                 $output .= '
                         </ul>
                         <div class="clear"></div>
                     </div>
                 ';
                 // iterate thought the superglobals to show
                 foreach ($globals as $global) {
                     // make the superglobal available
                     global ${'_' . $global};
                     // add to the generated output
                     $output .= '
                         <table cellspacing="0" cellpadding="0" border="0" id="zdc-globals-' . strtolower($global) . '" class="zdc-entry">
                             <tr>
                                 <td class="zdc-counter" valign="top">001</td>
                                 <td class="zdc-data">
                                     <div class="zdc-box">
                                         <strong>$_' . $global . '</strong>
                                         <pre>' . htmlentities(var_export(${'_' . $global}, true)) . '</pre>
                                     </div>
                                 </td>
                             </tr>
                         </table>
                     ';
                 }
                 // enclose generated output in a special div
                 $output = '<div id="zdc-globals">' . $output . '</div>';
                 $blocks[$block]['generated'] = $output;
             }
         }
         // if there's an error, show the console
         if ($blocks['unsuccessful-queries']['counter'] > 0 || $blocks['errors']['counter'] > 0) {
             $this->minimize_console = false;
         }
         // finalize output by enclosing the debugging console's menu and generated blocks in a container
         $output = '
             <div id="zdc" style="display:' . ($this->minimize_console ? 'none' : 'block') . '">
                 <a name="zdc-top"></a>
                 <ul class="zdc-main">
         ';
         // are there any error messages?
         if ($blocks['errors']['counter'] > 0) {
             // button for reviewing errors
             $output .= '
                 <li>
                     <a href="javascript:zdc_toggle(\'zdc-errors\')">' . $this->language['errors'] . ': <span>' . $blocks['errors']['counter'] . '</span>
                     </a>
                 </li>
             ';
         }
         // common buttons
         $output .= '
             <li>
                 <a href="javascript:zdc_toggle(\'zdc-successful-queries\')">' . $this->language['successful_queries'] . ': <span>' . $blocks['successful-queries']['counter'] . '</span>&nbsp;(' . $this->_fix_pow($this->total_execution_time) . ' ' . $this->language['miliseconds'] . ')
                 </a>
             </li>
             <li>
                 <a href="javascript:zdc_toggle(\'zdc-unsuccessful-queries\')">' . $this->language['unsuccessful_queries'] . ': <span>' . $blocks['unsuccessful-queries']['counter'] . '</span>
                 </a>
             </li>
         ';
         if (isset($this->debug_info['warnings'])) {
             $output .= '
                 <li>
                     <a href="javascript:zdc_toggle(\'zdc-warnings\')">' . $this->language['warnings'] . ': <span>' . count($this->warnings) . '</span>
                     </a>
                 </li>
             ';
         }
         $output .= '
             <li>
                 <a href="javascript:zdc_toggle(\'zdc-globals-submenu\')">' . $this->language['globals'] . '
                 </a>
             </li>
         ';
         // wrap up debugging console's menu
         $output .= '
             </ul>
             <div class="clear"></div>
         ';
         foreach (array_keys($blocks) as $block) {
             $output .= $blocks[$block]['generated'];
         }
         // wrap up
         $output .= '</div>';
         // add the minified version of the debugging console
         $output .= '
             <div id="zdc-mini">
                 <a href="javascript:zdc_toggle(\'console\')">' . $blocks['successful-queries']['counter'] . ($warnings ? '<span>!</span>' : '') . ' / ' . $blocks['unsuccessful-queries']['counter'] . '
                 </a>
             </div>
         ';
         // use the provided resource path for stylesheets and javascript (if any)
         if (!is_null($this->resource_path)) {
             $path = rtrim(preg_replace('/\\\\/', '/', '//' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '') . DIRECTORY_SEPARATOR . $this->resource_path), '/');
         } else {
             // this is the url that will be used for automatically including
             // the CSS and the JavaScript files
             $path = rtrim(preg_replace('/\\\\/', '/', '//' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '') . DIRECTORY_SEPARATOR . substr(dirname(__FILE__), strlen(realpath($_SERVER['DOCUMENT_ROOT'])))), '/');
         }
         // link the required javascript
         $output = '<script type="text/javascript" src="' . $path . '/public/javascript/database.js"></script>' . $output;
         // link the required css file
         $output = '<link rel="stylesheet" href="' . $path . '/public/css/database.css" type="text/css">' . $output;
         // if output is to be returned rather than printed to the screen
         if ($return) {
             return $output;
         }
         // show generated output
         echo $output;
     }
 }
Example #23
0
 /**
  * {@inheritdoc}
  */
 public function formatPlain($text)
 {
     return \SqlFormatter::format($text, false);
 }
Example #24
0
<?php

if (isset($_POST['query'])) {
    $query = $_POST['query'];
    require dirname(__FILE__) . '/sqlFormatter.php';
    $o = new SqlFormatter();
    $formattedQuery = $o->format($query);
} else {
    $query = '';
    $formattedQuery = '';
}
?>
<form method="POST">
<label for="query">Query to format<label><br />
<textarea name="query" rows="10" cols="100"><?php 
echo $query;
?>
</textarea><br />
<input type="submit" value="Format!" />
<?php 
if ($formattedQuery) {
    ?>
<br />
<br />
<br />
<label for="formattedQuery">Formatted query<label><br />
<textarea name="formattedQuery" rows="10" cols="100"><?php 
    echo $formattedQuery;
    ?>
</textarea>
<?php 
Example #25
0
require '../lib/SqlFormatter.php';
//this is the default value
//set to '0' to disable caching
//a value between 10 and 20 seems to give the best result
SqlFormatter::$max_cachekey_size = 15;
$contents = file('sql.sql');
//track time and memory usage
$start = microtime(true);
$ustart = memory_get_usage(true);
//track number of queries and size of queries
$queries = 0;
$bytes = 0;
//format each query 3 times
for ($i = 0; $i < 3; $i++) {
    foreach ($contents as $query) {
        //this tries to mix up the queries so we aren't just running the same thing a bunch of times
        $query = str_replace('tablename', rand(1, 10000), $query);
        //do formatting and highlighting
        SqlFormatter::format($query);
        $queries++;
        $bytes += strlen($query);
    }
}
$uend = memory_get_usage(true);
$end = microtime(true);
echo "<p>Formatted {$queries} queries.</p>";
echo "<p>Average query length of " . number_format($bytes / $queries, 5) . " characters</p>";
echo "<p>Took " . number_format($end - $start, 5) . " seconds total, " . number_format(($end - $start) / $queries, 5) . " seconds per query, " . number_format(1000 * ($end - $start) / $bytes, 5) . " seconds per 1000 characters</p>";
echo "<p>Used " . number_format($uend - $ustart) . " bytes of memory</p>";
echo "<h3>Cache Stats</h3><pre>" . print_r(SqlFormatter::getCacheStats(), true) . "</pre>";
Example #26
0
</div>
<table>
    <tr>
        <th>Original</th>
        <th>Comments Removed</th>
    </tr>
    <?php 
foreach ($comment_statements as $sql) {
    ?>
    <tr>
        <td>
            <pre><?php 
    echo SqlFormatter::highlight($sql);
    ?>
</pre>
        </td>
        <td>
            <pre><?php 
    echo SqlFormatter::highlight(SqlFormatter::removeComments($sql));
    ?>
</pre>
        </td>
    </tr>
    <?php 
}
?>
</table>

</body>
</html>
Example #27
0
 function pq($query, $args = array())
 {
     if ($this->debug) {
         print '<h1 class="debug">Debug: Oracle</h1>';
         print SqlFormatter::format($query);
         print_r($args);
     }
     if ($this->stats) {
         $query = preg_replace('/SELECT /', 'SELECT /*+ gather_plan_statistics */ ', $query, 1);
     }
     $stid = oci_parse($this->conn, $query);
     if (!$stid) {
         $e = oci_error($this->conn);
         $this->error('There was an error with Oracle', htmlentities($e['message']));
     }
     oci_set_prefetch($stid, 100);
     // Get variables for prepared query
     $arg_count = preg_match_all('/:\\d+/', $query, $mat);
     for ($i = 0; $i < $arg_count; $i++) {
         oci_bind_by_name($stid, ':' . ($i + 1), $args[$i]);
     }
     // Add a bound variable incase we need it
     if (strpos($query, ':id') !== false) {
         oci_bind_by_name($stid, ":id", $this->id, 8);
     }
     // Add Explain Plan if requested
     if ($this->explain) {
         $exp = oci_parse($this->conn, 'EXPLAIN PLAN FOR ' . $query);
         $arg_count = preg_match_all('/:\\d+/', $query, $mat);
         $r = oci_execute($exp);
         oci_free_statement($exp);
         $plan = oci_parse($this->conn, 'SELECT * FROM TABLE(dbms_xplan.display)');
         $pl = oci_execute($plan);
         $this->plan .= "{$query}\n" . implode(', ', $args) . "\n";
         while ($row = oci_fetch_array($plan, OCI_ASSOC + OCI_RETURN_NULLS)) {
             $this->plan .= $row['PLAN_TABLE_OUTPUT'] . "\n";
         }
         oci_free_statement($plan);
     }
     // Perform the logic of the query
     $r = oci_execute($stid);
     if (!$r) {
         $e = oci_error($stid);
         //trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
         $this->error('There was an error with Oracle', htmlentities($e['message']));
     }
     $data = array();
     if (strpos($query, 'SELECT') !== false) {
         while ($row = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) {
             #array_push($data, json_decode(json_encode($row), FALSE));
             array_push($data, $row);
         }
     }
     oci_free_statement($stid);
     if ($this->stats) {
         $stat = oci_parse($this->conn, "select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'))");
         $pl = oci_execute($stat);
         $this->stat .= "{$query}\n" . implode(', ', $args) . "\n";
         while ($row = oci_fetch_array($stat, OCI_ASSOC + OCI_RETURN_NULLS)) {
             $this->stat .= $row['PLAN_TABLE_OUTPUT'] . "\n";
         }
         oci_free_statement($stat);
     }
     return sizeof($data) == 0 ? array() : $data;
 }
 public function block_queries($context, array $blocks = array())
 {
     // line 73
     echo "    <h2>Queries</h2>\n\n    ";
     // line 75
     $context['_parent'] = (array) $context;
     $context['_seq'] = twig_ensure_traversable($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "queries", array()));
     $context['loop'] = array('parent' => $context['_parent'], 'index0' => 0, 'index' => 1, 'first' => true);
     if (is_array($context['_seq']) || is_object($context['_seq']) && $context['_seq'] instanceof Countable) {
         $length = count($context['_seq']);
         $context['loop']['revindex0'] = $length - 1;
         $context['loop']['revindex'] = $length;
         $context['loop']['length'] = $length;
         $context['loop']['last'] = 1 === $length;
     }
     foreach ($context['_seq'] as $context["connection"] => $context["queries"]) {
         // line 76
         echo "        <h3>Connection <em>";
         echo twig_escape_filter($this->env, $context["connection"], "html", null, true);
         echo "</em></h3>\n        ";
         // line 77
         if (twig_test_empty($context["queries"])) {
             // line 78
             echo "            <p>\n                <em>No queries.</em>\n            </p>\n        ";
         } else {
             // line 82
             echo "            <p>\n                <button type=\"button\" class=\"sf-button\" onclick=\"expandAllQueries(this);\" data-action=\"expand\">\n                    <span class=\"border-l\">\n                        <span class=\"border-r\">\n                            <span class=\"btn-bg\">Expand all queries</span>\n                        </span>\n                    </span>\n                </button>\n            </p>\n            <table class=\"alt\" id=\"queriesPlaceholder-";
             // line 91
             echo twig_escape_filter($this->env, $this->getAttribute($context["loop"], "index", array()), "html", null, true);
             echo "\">\n                <thead>\n                    <tr>\n                        <th onclick=\"javascript:sortTable(this, 0, 'queries-";
             // line 94
             echo twig_escape_filter($this->env, $this->getAttribute($context["loop"], "index", array()), "html", null, true);
             echo "')\" data-sort-direction=\"-1\" style=\"cursor: pointer;\">#<span>&#9650;</span></th>\n                        <th onclick=\"javascript:sortTable(this, 1, 'queries-";
             // line 95
             echo twig_escape_filter($this->env, $this->getAttribute($context["loop"], "index", array()), "html", null, true);
             echo "')\" style=\"cursor: pointer;\">Time<span></span></th>\n                        <th style=\"width: 100%;\">Info</th>\n                    </tr>\n                </thead>\n                <tbody id=\"queries-";
             // line 99
             echo twig_escape_filter($this->env, $this->getAttribute($context["loop"], "index", array()), "html", null, true);
             echo "\">\n                ";
             // line 100
             $context['_parent'] = (array) $context;
             $context['_seq'] = twig_ensure_traversable($context["queries"]);
             $context['loop'] = array('parent' => $context['_parent'], 'index0' => 0, 'index' => 1, 'first' => true);
             if (is_array($context['_seq']) || is_object($context['_seq']) && $context['_seq'] instanceof Countable) {
                 $length = count($context['_seq']);
                 $context['loop']['revindex0'] = $length - 1;
                 $context['loop']['revindex'] = $length;
                 $context['loop']['length'] = $length;
                 $context['loop']['last'] = 1 === $length;
             }
             foreach ($context['_seq'] as $context["i"] => $context["query"]) {
                 // line 101
                 echo "                    <tr id=\"queryNo-";
                 echo twig_escape_filter($this->env, $context["i"], "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute($context["loop"], "parent", array()), "loop", array()), "index", array()), "html", null, true);
                 echo "\" class=\"";
                 echo twig_escape_filter($this->env, twig_cycle(array(0 => "odd", 1 => "even"), $context["i"]), "html", null, true);
                 echo "\">\n                        <td>";
                 // line 102
                 echo twig_escape_filter($this->env, $this->getAttribute($context["loop"], "index", array()), "html", null, true);
                 echo "</td>\n                        <td>";
                 // line 103
                 echo twig_escape_filter($this->env, sprintf("%0.2f", $this->getAttribute($context["query"], "executionMS", array()) * 1000), "html", null, true);
                 echo "&nbsp;ms</td>\n                        <td>\n                            <div class=\"query-section\" data-state=\"collapsed\" onclick=\"return expandQuery(this);\" title=\"Expand query\" data-target-id=\"code-";
                 // line 105
                 echo twig_escape_filter($this->env, $context["i"], "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute($context["loop"], "parent", array()), "loop", array()), "index", array()), "html", null, true);
                 echo "\" style=\"cursor: pointer;\">\n                                <img alt=\"+\" src=\"data:image/gif;base64,R0lGODlhEgASAMQTANft99/v+Ga44bHb8ITG52S44dXs9+z1+uPx+YvK6WC24G+944/M6W28443L6dnu+Ge54v/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABMALAAAAAASABIAQAVS4DQBTiOd6LkwgJgeUSzHSDoNaZ4PU6FLgYBA5/vFID/DbylRGiNIZu74I0h1hNsVxbNuUV4d9SsZM2EzWe1qThVzwWFOAFCQFa1RQq6DJB4iIQA7\" style=\"display: inline;\" />\n                                <img alt=\"-\" src=\"data:image/gif;base64,R0lGODlhEgASAMQSANft94TG57Hb8GS44ez1+mC24IvK6ePx+Wa44dXs92+942e54o3L6W2844/M6dnu+P/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABIALAAAAAASABIAQAVCoCQBTBOd6Kk4gJhGBCTPxysJb44K0qD/ER/wlxjmisZkMqBEBW5NHrMZmVKvv9hMVsO+hE0EoNAstEYGxG9heIhCADs=\" style=\"display: none;\" />\n                                <span style=\"display: none\">Shrink query</span>\n                                <span id=\"smallcode-";
                 // line 109
                 echo twig_escape_filter($this->env, $context["i"], "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute($context["loop"], "parent", array()), "loop", array()), "index", array()), "html", null, true);
                 echo "\">\n                                    ";
                 // line 110
                 echo $this->env->getExtension('doctrine_extension')->minifyQuery($this->getAttribute($context["query"], "sql", array()));
                 echo "\n                                </span>\n                            </div>\n                            <code id=\"code-";
                 // line 113
                 echo twig_escape_filter($this->env, $context["i"], "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute($context["loop"], "parent", array()), "loop", array()), "index", array()), "html", null, true);
                 echo "\">\n                                ";
                 // line 114
                 echo SqlFormatter::format($this->getAttribute($context["query"], "sql", array()), $context["i"], $this->getAttribute($this->getAttribute($this->getAttribute($context["loop"], "parent", array()), "loop", array()), "index", array()));
                 echo "\n                            </code>\n                            <span id=\"original-query-";
                 // line 116
                 echo twig_escape_filter($this->env, $context["i"], "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute($context["loop"], "parent", array()), "loop", array()), "index", array()), "html", null, true);
                 echo "\" style=\"display: none;\">\n                                ";
                 // line 117
                 echo $this->env->getExtension('doctrine_extension')->replaceQueryParameters($this->getAttribute($context["query"], "sql", array()), $this->getAttribute($context["query"], "params", array()));
                 echo "\n                            </span>\n                            <small>\n                                <strong>Parameters</strong>: ";
                 // line 120
                 echo twig_escape_filter($this->env, $this->env->getExtension('yaml')->encode($this->getAttribute($context["query"], "params", array())), "html", null, true);
                 echo " <br />\n                                [<span id=\"expandParams-";
                 // line 121
                 echo twig_escape_filter($this->env, $context["i"], "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute($context["loop"], "parent", array()), "loop", array()), "index", array()), "html", null, true);
                 echo "\" onclick=\"javascript:toggleRunnableQuery(this);\" target-data-id=\"original-query-";
                 echo twig_escape_filter($this->env, $context["i"], "html", null, true);
                 echo "-";
                 echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute($context["loop"], "parent", array()), "loop", array()), "index", array()), "html", null, true);
                 echo "\" style=\"cursor: pointer;\">Display runnable query</span>]<br/>\n                            </small>\n\n                            ";
                 // line 124
                 if ($this->getAttribute($context["query"], "explainable", array())) {
                     // line 125
                     echo "                                [<a href=\"";
                     echo twig_escape_filter($this->env, $this->env->getExtension('routing')->getPath("_profiler", array("panel" => "db", "token" => isset($context["token"]) ? $context["token"] : $this->getContext($context, "token"), "page" => "explain", "connection" => $context["connection"], "query" => $context["i"])), "html", null, true);
                     echo "\" onclick=\"return explain(this);\" style=\"text-decoration: none;\" title=\"Explains the query\" data-target-id=\"explain-";
                     echo twig_escape_filter($this->env, $context["i"], "html", null, true);
                     echo "-";
                     echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute($context["loop"], "parent", array()), "loop", array()), "index", array()), "html", null, true);
                     echo "\" >\n                                    <img alt=\"+\" src=\"data:image/gif;base64,R0lGODlhEgASAMQTANft99/v+Ga44bHb8ITG52S44dXs9+z1+uPx+YvK6WC24G+944/M6W28443L6dnu+Ge54v/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABMALAAAAAASABIAQAVS4DQBTiOd6LkwgJgeUSzHSDoNaZ4PU6FLgYBA5/vFID/DbylRGiNIZu74I0h1hNsVxbNuUV4d9SsZM2EzWe1qThVzwWFOAFCQFa1RQq6DJB4iIQA7\" style=\"display: inline; width: 12px; height: 12px;\" />\n                                    <img alt=\"-\" src=\"data:image/gif;base64,R0lGODlhEgASAMQSANft94TG57Hb8GS44ez1+mC24IvK6ePx+Wa44dXs92+942e54o3L6W2844/M6dnu+P/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABIALAAAAAASABIAQAVCoCQBTBOd6Kk4gJhGBCTPxysJb44K0qD/ER/wlxjmisZkMqBEBW5NHrMZmVKvv9hMVsO+hE0EoNAstEYGxG9heIhCADs=\" style=\"display: none; width: 12px; height: 12px;\" />\n                                    <span style=\"vertical-align:top\">Explain query</span>\n                                </a>]\n                            ";
                 } else {
                     // line 131
                     echo "                                This query cannot be explained\n                            ";
                 }
                 // line 133
                 echo "\n                            ";
                 // line 134
                 if ($this->getAttribute($context["query"], "explainable", array())) {
                     // line 135
                     echo "                                <div id=\"explain-";
                     echo twig_escape_filter($this->env, $context["i"], "html", null, true);
                     echo "-";
                     echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute($this->getAttribute($context["loop"], "parent", array()), "loop", array()), "index", array()), "html", null, true);
                     echo "\" class=\"loading\"></div>\n                            ";
                 }
                 // line 137
                 echo "                        </td>\n                    </tr>\n                ";
                 ++$context['loop']['index0'];
                 ++$context['loop']['index'];
                 $context['loop']['first'] = false;
                 if (isset($context['loop']['length'])) {
                     --$context['loop']['revindex0'];
                     --$context['loop']['revindex'];
                     $context['loop']['last'] = 0 === $context['loop']['revindex0'];
                 }
             }
             $_parent = $context['_parent'];
             unset($context['_seq'], $context['_iterated'], $context['i'], $context['query'], $context['_parent'], $context['loop']);
             $context = array_intersect_key($context, $_parent) + $_parent;
             // line 140
             echo "                </tbody>\n            </table>\n        ";
         }
         // line 143
         echo "    ";
         ++$context['loop']['index0'];
         ++$context['loop']['index'];
         $context['loop']['first'] = false;
         if (isset($context['loop']['length'])) {
             --$context['loop']['revindex0'];
             --$context['loop']['revindex'];
             $context['loop']['last'] = 0 === $context['loop']['revindex0'];
         }
     }
     $_parent = $context['_parent'];
     unset($context['_seq'], $context['_iterated'], $context['connection'], $context['queries'], $context['_parent'], $context['loop']);
     $context = array_intersect_key($context, $_parent) + $_parent;
     // line 144
     echo "\n    <h2>Database Connections</h2>\n\n    ";
     // line 147
     if ($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "connections", array())) {
         // line 148
         echo "        ";
         $this->loadTemplate("WebProfilerBundle:Profiler:table.html.twig", "@Doctrine/Collector/db.html.twig", 148)->display(array("data" => $this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "connections", array())));
         // line 149
         echo "    ";
     } else {
         // line 150
         echo "        <p>\n            <em>No connections.</em>\n        </p>\n    ";
     }
     // line 154
     echo "\n    <h2>Entity Managers</h2>\n\n    ";
     // line 157
     if ($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "managers", array())) {
         // line 158
         echo "        ";
         $this->loadTemplate("WebProfilerBundle:Profiler:table.html.twig", "@Doctrine/Collector/db.html.twig", 158)->display(array("data" => $this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "managers", array())));
         // line 159
         echo "    ";
     } else {
         // line 160
         echo "        <p>\n            <em>No entity managers.</em>\n        </p>\n    ";
     }
     // line 164
     echo "\n    <h2>Second Level Cache</h2>\n\n    ";
     // line 167
     if ($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "cacheCounts", array())) {
         // line 168
         echo "        ";
         $this->loadTemplate("WebProfilerBundle:Profiler:table.html.twig", "@Doctrine/Collector/db.html.twig", 168)->display(array("data" => $this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "cacheCounts", array())));
         // line 169
         echo "\n        ";
         // line 170
         if ($this->getAttribute($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "cacheRegions", array()), "hits", array())) {
             // line 171
             echo "            <h3>Number of cache hits</h3>\n            ";
             // line 172
             $this->loadTemplate("WebProfilerBundle:Profiler:table.html.twig", "@Doctrine/Collector/db.html.twig", 172)->display(array("data" => $this->getAttribute($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "cacheRegions", array()), "hits", array())));
             // line 173
             echo "        ";
         }
         // line 174
         echo "\n        ";
         // line 175
         if ($this->getAttribute($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "cacheRegions", array()), "misses", array())) {
             // line 176
             echo "            <h3>Number of cache misses</h3>\n            ";
             // line 177
             $this->loadTemplate("WebProfilerBundle:Profiler:table.html.twig", "@Doctrine/Collector/db.html.twig", 177)->display(array("data" => $this->getAttribute($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "cacheRegions", array()), "misses", array())));
             // line 178
             echo "        ";
         }
         // line 179
         echo "\n        ";
         // line 180
         if ($this->getAttribute($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "cacheRegions", array()), "puts", array())) {
             // line 181
             echo "            <h3>Number of cache puts</h3>\n            ";
             // line 182
             $this->loadTemplate("WebProfilerBundle:Profiler:table.html.twig", "@Doctrine/Collector/db.html.twig", 182)->display(array("data" => $this->getAttribute($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "cacheRegions", array()), "puts", array())));
             // line 183
             echo "        ";
         }
         // line 184
         echo "    ";
     } else {
         // line 185
         echo "        <p>\n            <em>No cache.</em>\n        </p>\n    ";
     }
     // line 189
     echo "\n    <h2>Mapping</h2>\n\n    ";
     // line 192
     $context['_parent'] = (array) $context;
     $context['_seq'] = twig_ensure_traversable($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "entities", array()));
     foreach ($context['_seq'] as $context["manager"] => $context["classes"]) {
         // line 193
         echo "        <h3>Manager <em>";
         echo twig_escape_filter($this->env, $context["manager"], "html", null, true);
         echo "</em></h3>\n        ";
         // line 194
         if (twig_test_empty($context["classes"])) {
             // line 195
             echo "            <p><em>No loaded entities.</em></p>\n        ";
         } else {
             // line 197
             echo "            <table>\n                <thead>\n                <tr>\n                    <th scope=\"col\">Class</th>\n                    <th scope=\"col\">Mapping errors</th>\n                </tr>\n                </thead>\n                <tbody>\n                ";
             // line 205
             $context['_parent'] = (array) $context;
             $context['_seq'] = twig_ensure_traversable($context["classes"]);
             foreach ($context['_seq'] as $context["_key"] => $context["class"]) {
                 // line 206
                 echo "                    <tr>\n                        <td>";
                 // line 207
                 echo twig_escape_filter($this->env, $context["class"], "html", null, true);
                 echo "</td>\n                        <td>\n                            ";
                 // line 209
                 if ($this->getAttribute($this->getAttribute($this->getAttribute(isset($context["collector"]) ? $context["collector"] : null, "mappingErrors", array(), "any", false, true), $context["manager"], array(), "array", false, true), $context["class"], array(), "array", true, true)) {
                     // line 210
                     echo "                                <ul>\n                                    ";
                     // line 211
                     $context['_parent'] = (array) $context;
                     $context['_seq'] = twig_ensure_traversable($this->getAttribute($this->getAttribute($this->getAttribute(isset($context["collector"]) ? $context["collector"] : $this->getContext($context, "collector"), "mappingErrors", array()), $context["manager"], array(), "array"), $context["class"], array(), "array"));
                     foreach ($context['_seq'] as $context["_key"] => $context["error"]) {
                         // line 212
                         echo "                                        <li>";
                         echo twig_escape_filter($this->env, $context["error"], "html", null, true);
                         echo "</li>\n                                    ";
                     }
                     $_parent = $context['_parent'];
                     unset($context['_seq'], $context['_iterated'], $context['_key'], $context['error'], $context['_parent'], $context['loop']);
                     $context = array_intersect_key($context, $_parent) + $_parent;
                     // line 214
                     echo "                                </ul>\n                            ";
                 } else {
                     // line 216
                     echo "                                Valid\n                            ";
                 }
                 // line 218
                 echo "                        </td>\n                    </tr>\n                ";
             }
             $_parent = $context['_parent'];
             unset($context['_seq'], $context['_iterated'], $context['_key'], $context['class'], $context['_parent'], $context['loop']);
             $context = array_intersect_key($context, $_parent) + $_parent;
             // line 221
             echo "                </tbody>\n            </table>\n        ";
         }
         // line 224
         echo "    ";
     }
     $_parent = $context['_parent'];
     unset($context['_seq'], $context['_iterated'], $context['manager'], $context['classes'], $context['_parent'], $context['loop']);
     $context = array_intersect_key($context, $_parent) + $_parent;
     // line 225
     echo "\n    <script type=\"text/javascript\">//<![CDATA[\n        function explain(link) {\n            \"use strict\";\n\n            var imgs = link.children,\n                target = link.getAttribute('data-target-id');\n\n            Sfjs.toggle(target, imgs[0], imgs[1])\n                .load(\n                    target,\n                    link.href,\n                    null,\n                    function(xhr, el) {\n                        el.innerHTML = 'An error occurred while loading the details';\n                        Sfjs.removeClass(el, 'loading');\n                    }\n                );\n\n            return false;\n        }\n\n        function expandAllQueries(button) {\n            var queries = document.getElementsByClassName('query-section'),\n                i = queries.length,\n                action = button.getAttribute('data-action');\n\n            if (action == 'expand') {\n                button.getElementsByClassName('btn-bg')[0].innerHTML = 'Collapse all queries';\n\n                while (i--) {\n                    if (queries[i].getAttribute('data-state') == 'collapsed') {\n                        expandQuery(queries[i]);\n                    }\n                }\n            } else {\n                button.getElementsByClassName('btn-bg')[0].innerHTML = 'Expand all queries';\n\n                while (i--) {\n                    if (queries[i].getAttribute('data-state') == 'expanded') {\n                        expandQuery(queries[i]);\n                    }\n                }\n            }\n\n            button.setAttribute('data-action', action == 'expand' ? 'collapse' : 'expand');\n        }\n\n        function expandQuery(link) {\n            var sections = link.children,\n                target = link.getAttribute('data-target-id'),\n                targetId = target.replace('code', ''),\n                queriesParameters = document.getElementById('original-query' + targetId);\n\n            if (queriesParameters.style.display != 'none') {\n                queriesParameters.style.display = 'none';\n                document.getElementById('small' + target).style.display = 'inline';\n                document.getElementById('expandParams' + targetId).innerHTML = 'Display runnable query';\n            }\n\n            if (document.getElementById('small' + target).style.display != 'none') {\n                document.getElementById('small' + target).style.display = 'none';\n                document.getElementById(target).style.display = 'inline';\n\n                sections[0].style.display = 'none';\n                sections[1].style.display = 'inline';\n                sections[2].style.display = 'inline';\n\n                link.setAttribute('data-state', 'expanded');\n            } else {\n                document.getElementById('small' + target).style.display = 'inline';\n                document.getElementById(target).style.display = 'none';\n\n                sections[0].style.display = 'inline';\n                sections[1].style.display = 'none';\n                sections[2].style.display = 'none';\n\n                link.setAttribute('data-state', 'collapsed');\n            }\n\n            return false;\n        }\n\n        function toggleRunnableQuery(target) {\n            var targetId = target.getAttribute('target-data-id').replace('original-query', ''),\n                targetElement = document.getElementById(target.getAttribute('target-data-id')),\n                elem;\n\n            if (targetElement.style.display != 'block') {\n                targetElement.style.display = 'block';\n                target.innerHTML = 'Hide runnable query';\n\n                document.getElementById('smallcode' + targetId).style.display = 'none';\n                document.getElementById('code' + targetId).style.display = 'none';\n\n                elem = document.getElementById('code' + targetId).parentElement.children[0];\n\n                elem.children[0].style.display = 'inline';\n                elem.children[1].style.display = 'none';\n                elem.children[2].style.display = 'none';\n\n            } else {\n                targetElement.style.display = 'none';\n                target.innerHTML = 'Display runnable query';\n\n                document.getElementById('smallcode' + targetId).style.display = 'inline';\n            }\n        }\n\n        function sortTable(header, column, targetId) {\n            \"use strict\";\n\n            var direction = parseInt(header.getAttribute('data-sort-direction')) || 1,\n                items = [],\n                target = document.getElementById(targetId),\n                rows = target.children,\n                headers = header.parentElement.children,\n                i;\n\n            for (i = 0; i < rows.length; ++i) {\n                items.push(rows[i]);\n            }\n\n            for (i = 0; i < headers.length; ++i) {\n                headers[i].removeAttribute('data-sort-direction');\n                if (headers[i].children.length > 0) {\n                    headers[i].children[0].innerHTML = '';\n                }\n            }\n\n            header.setAttribute('data-sort-direction', (-1*direction).toString());\n            header.children[0].innerHTML = direction > 0 ? '&#9650;' : '&#9660;';\n\n            items.sort(function(a, b) {\n                return direction*(parseFloat(a.children[column].innerHTML) - parseFloat(b.children[column].innerHTML));\n            });\n\n            for (i = 0; i < items.length; ++i) {\n                Sfjs.removeClass(items[i], i % 2 ? 'even' : 'odd');\n                Sfjs.addClass(items[i], i % 2 ? 'odd' : 'even');\n                target.appendChild(items[i]);\n            }\n        }\n\n    //]]></script>\n\n    <style>\n        h3 {\n            margin-bottom: 0px;\n        }\n\n        code {\n            display: none;\n        }\n\n        code pre {\n            padding: 5px;\n        }\n    </style>\n";
 }
Example #29
0
 /**
  * Method to test union().
  *
  * @return void
  *
  * @covers Windwalker\Query\Query::union
  */
 public function testUnionAll()
 {
     $query = $this->getQuery();
     $query->unionAll($this->getQuery()->select('*')->from('foo')->where('a = b')->order('id'))->union($this->getQuery()->select('*')->from('foo')->where('a = b')->order('id'));
     $sql = '( SELECT * FROM foo WHERE a = b ORDER BY id) UNION ALL ( SELECT * FROM foo WHERE a = b ORDER BY id)';
     $this->assertEquals(\SqlFormatter::compress($sql), \SqlFormatter::compress($query));
 }
Example #30
0
 /**
  * Return a query with the parameters replaced
  *
  * @param string $query
  * @param array  $parameters
  * @param bool   $highlight
  *
  * @return string
  */
 public function replaceQueryParameters($query, array $parameters, $highlight = true)
 {
     $i = 0;
     $result = preg_replace_callback('/\\?|((?<!:):[a-z0-9_]+)/i', function ($matches) use($parameters, &$i) {
         $key = substr($matches[0], 1);
         if (!array_key_exists($i, $parameters) && (false === $key || !array_key_exists($key, $parameters))) {
             return $matches[0];
         }
         $value = array_key_exists($i, $parameters) ? $parameters[$i] : $parameters[$key];
         $result = DoctrineExtension::escapeFunction($value);
         $i++;
         return $result;
     }, $query);
     if ($highlight) {
         $result = \SqlFormatter::highlight($result);
         $result = str_replace(array('<pre ', '</pre>'), array('<span ', '</span>'), $result);
     }
     return $result;
 }