本文整理汇总了PHP中SqlFormatter类的典型用法代码示例。如果您正苦于以下问题:PHP SqlFormatter类的具体用法?PHP SqlFormatter怎么用?PHP SqlFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SqlFormatter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: runQueryWithView
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]));
}
开发者ID:bubach,项目名称:VisualQuery,代码行数:22,代码来源:table.php
示例2: leftJoinStartsOnNewLine
/**
* @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);
}
开发者ID:nicoder,项目名称:sqlFormatter,代码行数:11,代码来源:test.php
示例3: collect
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']);
}
}
开发者ID:bwgraves,项目名称:forkcms,代码行数:7,代码来源:DatabaseDataCollector.php
示例4: format
/**
* @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);
}
开发者ID:willoucom,项目名称:php-sql-query,代码行数:13,代码来源:Generic.php
示例5: setupTextArea
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']);
}
}
}
}
开发者ID:MichaelJ2324,项目名称:sugarcrm-tools,代码行数:27,代码来源:class.query.php
示例6: renderResults
/**
* @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();
}
开发者ID:settermjd,项目名称:powerful-and-flexible-sql-generation-without-the-hassle,代码行数:30,代码来源:output-results.php
示例7: view
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);
}
开发者ID:mp-php,项目名称:fuel-packages-dbdocs,代码行数:7,代码来源:view.php
示例8: disp_val
public function disp_val()
{
if (Rend::$sql_pretty) {
return \SqlFormatter::format($this->raw, false);
} else {
return parent::disp_val();
}
}
开发者ID:swim,项目名称:dump_r.php,代码行数:8,代码来源:_SQL.php
示例9: validate
/**
* @return bool
* @throws ValidationFailedException
*/
public function validate()
{
$queryArray = \SqlFormatter::splitQuery($this->queryString);
$pattern = '/\\*/';
if ($this->stringHasRegexInstance($queryArray, $pattern)) {
throw new ValidationFailedException("Query has to have all wished columns defined, no '*' is allowed", 500);
}
return true;
}
开发者ID:arnulfojr,项目名称:qcharts,代码行数:13,代码来源:NoAsteriscValidator.php
示例10: showCreates
/**
* @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");
}
}
}
开发者ID:gandalf3,项目名称:bolt,代码行数:15,代码来源:DatabaseCheck.php
示例11: getDoctrineQueries
/**
* 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;
}
开发者ID:shopwareLabs,项目名称:SwagProfiling,代码行数:19,代码来源:QueryProfiler.php
示例12: startQuery
/**
* {@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);
}
开发者ID:GruppoMeta,项目名称:Movio,代码行数:16,代码来源:EchoSQLLogger.php
示例13: print_sql
function print_sql($query)
{
if ($GLOBALS['cli']) {
print_vars($query);
} else {
if (class_exists('SqlFormatter')) {
// Hide it under a "database icon" popup.
#echo overlib_link('#', '<i class="oicon-databases"> </i>', SqlFormatter::highlight($query));
echo '<p>', SqlFormatter::highlight($query), '</p>';
} else {
print_vars($query);
}
}
}
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:14,代码来源:common.php
示例14: execute
/**
* 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']];
}
开发者ID:pomm-project,项目名称:pomm-profiler-service-provider,代码行数:26,代码来源:DatabaseDataCollector.php
示例15: validate
/**
* @return bool
* @throws ValidationFailedException
*/
public function validate()
{
$arrayOfQueries = \SqlFormatter::splitQuery($this->queryString);
$queryString = array_map("strtolower", $arrayOfQueries);
$tableNames = array_map("strtolower", $this->limits["table_names"]);
$tableNamesString = $this->getTableNamesStringForRegex($tableNames);
$regex = "/(from" . ValidTableNameValidator::ANY_SPACE_META_SEQUENCE_PATTERN . "({$tableNamesString}))/";
$hasJoinCommand = "/join/";
if ($this->stringHasRegexInstance($queryString, $hasJoinCommand)) {
$regexJoinCommand = "/(join" . ValidTableNameValidator::ANY_SPACE_META_SEQUENCE_PATTERN . "({$tableNamesString}))/";
$result = $this->stringHasRegexInstance($queryString, $regex) && $this->stringHasRegexInstance($queryString, $regexJoinCommand);
if (!$result) {
throw new ValidationFailedException("The given query does not contain a valid table in the Join statement.", 500);
}
return $result;
}
if (!$this->stringHasRegexInstance($queryString, $regex)) {
$helper = "<em>Check that the tables specify the schema</em>";
throw new ValidationFailedException("<p>The given query does not contain a valid table.</p>{$helper}", 500);
}
return true;
}
开发者ID:arnulfojr,项目名称:qcharts,代码行数:26,代码来源:ValidTableNameValidator.php
示例16: query
/**
* @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];
}
开发者ID:alfhan,项目名称:plansys,代码行数:42,代码来源:DataSource.php
示例17: WHERE
<?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 \\"testing\\");\"</code></pre>";
echo "<pre><code>echo \"SELECT * FROM MyTable WHERE (id>5 AND \\`name\\` LIKE \\"testing\\");\" | 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);
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:14,代码来源:cli.php
示例18: block_queries
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);
//.........这里部分代码省略.........
开发者ID:andonii21,项目名称:Marca,代码行数:101,代码来源:08e17d5ea91b0a2c4d2014eaf4481f3efc16318f2f229bfdf4e540d2d63b.php
示例19: buildTableSchema
/**
* 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) {
}
}
开发者ID:9618211,项目名称:mysql-xplain-xplain,代码行数:16,代码来源:Row.php
示例20: format
/**
* format
*
* @param string $sql
*
* @return String
*/
protected function format($sql)
{
return \SqlFormatter::format((string) $sql, false);
}
开发者ID:im286er,项目名称:windwalker,代码行数:11,代码来源:AbstractQueryTestCase.php
注:本文中的SqlFormatter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论