Ejemplo n.º 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]));
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
 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();
}
Ejemplo n.º 5
0
 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']);
     }
 }
 function testRemoveComments()
 {
     $expected = SqlFormatter::format("SELECT\n * FROM\n MyTable", false);
     $sql = "/* this is a comment */SELECT#This is another comment\n * FROM-- One final comment\n MyTable";
     $actual = SqlFormatter::removeComments($sql);
     $this->assertEquals($expected, $actual);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
0
 public function disp_val()
 {
     if (Rend::$sql_pretty) {
         return \SqlFormatter::format($this->raw, false);
     } else {
         return parent::disp_val();
     }
 }
Ejemplo n.º 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");
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * 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;
 }
Ejemplo n.º 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);
 }
 /**
  * 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']];
 }
Ejemplo n.º 14
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];
 }
Ejemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function formatPlain($text)
 {
     return \SqlFormatter::format($text, false);
 }
Ejemplo n.º 16
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 
Ejemplo n.º 17
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>";
Ejemplo n.º 18
0
    <tr>
        <th>Original</th>
        <th>Formatted</th>
    </tr>
    <?php 
foreach ($statements as $sql) {
    ?>
    <tr>
        <td>
            <pre><?php 
    echo $sql;
    ?>
</pre>
        </td>
        <td><pre><?php 
    echo htmlentities(SqlFormatter::format($sql, false));
    ?>
</pre></td>
    </tr>
    <?php 
}
?>
</table>


<h1>Syntax Highlighting Only</h1>

<div>
    Usage:
    <pre>
    <?php 
Ejemplo n.º 19
0
 private function buildCodeFromSql(Configuration $configuration, array $sql, $formatted = false, $lineLength = 120)
 {
     $currentPlatform = $configuration->getConnection()->getDatabasePlatform()->getName();
     $code = [];
     foreach ($sql as $query) {
         if (stripos($query, $configuration->getMigrationsTableName()) !== false) {
             continue;
         }
         if ($formatted) {
             if (!class_exists('\\SqlFormatter')) {
                 throw new \InvalidArgumentException('The "--formatted" option can only be used if the sql formatter is installed.' . 'Please run "composer require jdorn/sql-formatter".');
             }
             $maxLength = $lineLength - 18 - 8;
             // max - php code length - indentation
             if (strlen($query) > $maxLength) {
                 $query = \SqlFormatter::format($query, false);
             }
         }
         $code[] = sprintf("\$this->addSql(%s);", var_export($query, true));
     }
     if (!empty($code)) {
         array_unshift($code, sprintf("\$this->abortIf(\$this->connection->getDatabasePlatform()->getName() !== %s, %s);", var_export($currentPlatform, true), var_export(sprintf("Migration can only be executed safely on '%s'.", $currentPlatform), true)), "");
     }
     return implode("\n", $code);
 }
Ejemplo n.º 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) {
     }
 }
Ejemplo n.º 21
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);
Ejemplo n.º 22
0
 public static function run(&$report)
 {
     $macros = $report->macros;
     foreach ($macros as $key => $value) {
         if (is_array($value)) {
             $first = true;
             foreach ($value as $key2 => $value2) {
                 $value[$key2] = mysql_real_escape_string(trim($value2));
                 $first = false;
             }
             $macros[$key] = $value;
         } else {
             $macros[$key] = mysql_real_escape_string($value);
         }
         if ($value === 'ALL') {
             $macros[$key . '_all'] = true;
         }
     }
     //add the config and environment settings as macros
     $macros['config'] = PhpReports::$config;
     $macros['environment'] = PhpReports::$config['environments'][$report->options['Environment']];
     //expand macros in query
     $sql = PhpReports::render($report->raw_query, $macros);
     $report->options['Query'] = $sql;
     $report->options['Query_Formatted'] = SqlFormatter::format($sql);
     //split into individual queries and run each one, saving the last result
     $queries = SqlFormatter::splitQuery($sql);
     $datasets = array();
     $explicit_datasets = preg_match('/--\\s+@dataset(\\s*=\\s*|\\s+)true/', $sql);
     foreach ($queries as $i => $query) {
         $is_last = $i === count($queries) - 1;
         //skip empty queries
         $query = trim($query);
         if (!$query) {
             continue;
         }
         $result = mysql_query($query, $report->conn);
         if (!$result) {
             throw new Exception("Query failed: " . mysql_error($report->conn));
         }
         //if this query had an assert=empty flag and returned results, throw error
         if (preg_match('/^--[\\s+]assert[\\s]*=[\\s]*empty[\\s]*\\n/', $query)) {
             if (mysql_fetch_assoc($result)) {
                 throw new Exception("Assert failed.  Query did not return empty results.");
             }
         }
         // If this query should be included as a dataset
         if (!$explicit_datasets && $is_last || preg_match('/--\\s+@dataset(\\s*=\\s*|\\s+)true/', $query)) {
             $dataset = array('rows' => array());
             while ($row = mysql_fetch_assoc($result)) {
                 $dataset['rows'][] = $row;
             }
             // Get dataset title if it has one
             if (preg_match('/--\\s+@title(\\s*=\\s*|\\s+)(.*)/', $query, $matches)) {
                 $dataset['title'] = $matches[2];
             }
             $datasets[] = $dataset;
         }
     }
     return $datasets;
 }
Ejemplo n.º 23
0
 /**
  *  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;
     }
 }
Ejemplo n.º 24
0
<?php

/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Format SQL for SQL editors
 *
 * @package PhpMyAdmin
 */
require_once 'libraries/common.inc.php';
require_once 'libraries/sql-formatter/lib/SqlFormatter.php';
$query = isset($_POST['sql']) ? $_POST['sql'] : '';
SqlFormatter::$tab = "\t";
$query = SqlFormatter::format($query, false);
$response = PMA_Response::getInstance();
$response->addJSON("sql", $query);
Ejemplo n.º 25
0
 /**
  * format
  *
  * @param   string  $sql
  *
  * @return  String
  */
 protected function format($sql)
 {
     return \SqlFormatter::format((string) $sql, false);
 }
Ejemplo n.º 26
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 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";
 }
<?php

require_once 'vendor/autoload.php';
use Zend\Db\Sql\Sql;
$adapter = (require_once 'adapter.php');
/** @var \Zend\Db\Adapter\Adapter $adapter ['sqlite'] */
$sql = new Sql($adapter['sqlite']);
$insert = $sql->insert();
$insert->into('Customer')->columns(['FirstName', 'LastName', 'Email', 'Country'])->values(['FirstName' => 'Matthew', 'LastName' => 'Setter', 'Email' => '*****@*****.**', 'Country' => 'Australia']);
$statement = $sql->prepareStatementForSqlObject($insert);
$results = $statement->execute();
echo SqlFormatter::format($statement->getSql());
 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";
 }
Ejemplo n.º 30
0
 function pq($query, $args = array())
 {
     list($query, $args) = $this->oracle2mysql($query, $args);
     $query = $this->tablelookup($query);
     if ($this->debug) {
         print '<h1 class="debug">MySQL Debug</h1>';
         print SqlFormatter::format($query);
         print_r($args);
         // error_log($query);
         // error_log(print_R($args));
     }
     $stmt = $this->conn->prepare($query);
     if (!$stmt) {
         $this->error('There was an error with MySQL', $this->conn->error . __LINE__);
     }
     if (sizeof($args)) {
         $vtypes = array('NULL' => 'i', 'integer' => 'i', 'double' => 'd', 'string' => 's');
         $strfs = '';
         foreach ($args as $a) {
             $t = gettype($a);
             $strfs .= $vtypes[$t];
         }
         array_unshift($args, $strfs);
         call_user_func_array(array(&$stmt, 'bind_param'), $this->refs($args));
     }
     if (!$stmt->execute()) {
         $this->error('There was an error with MySQL', $this->conn->error . __LINE__);
     }
     $data = array();
     if (strpos($query, 'SELECT') !== false) {
         $params = array();
         $row = array();
         $meta = $stmt->result_metadata();
         while ($field = $meta->fetch_field()) {
             array_push($params, &$row[$field->name]);
         }
         call_user_func_array(array($stmt, 'bind_result'), $params);
         while ($stmt->fetch()) {
             $c = array();
             // Oracle returns all values as strings - Need to be consistent :(
             foreach ($row as $key => $val) {
                 $c[strtoupper($key)] = $val === null ? null : strval($val);
             }
             $data[] = $c;
         }
     }
     if ($this->debug) {
         print_r(array('rows', sizeof($data)));
     }
     // Need mysqlnd for this :(
     // $result = $stmt->get_result();
     // $data = array();
     // if ($result) {
     //     if($result->num_rows > 0) {
     //         while($row = $result->fetch_assoc()) {
     //             array_push($data, array_change_key_case($row, CASE_UPPER));
     //         }
     //     }
     // }
     $stmt->close();
     return $data;
 }