本文整理汇总了PHP中SqlFormatter::format方法的典型用法代码示例。如果您正苦于以下问题:PHP SqlFormatter::format方法的具体用法?PHP SqlFormatter::format怎么用?PHP SqlFormatter::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlFormatter
的用法示例。
在下文中一共展示了SqlFormatter::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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]));
}
示例2: 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);
}
示例3: 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']);
}
}
}
}
示例4: 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
示例5: 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']);
}
}
示例6: testRemoveComments
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);
}
示例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);
}
示例8: 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);
}
示例9: disp_val
public function disp_val()
{
if (Rend::$sql_pretty) {
return \SqlFormatter::format($this->raw, false);
} else {
return parent::disp_val();
}
}
示例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");
}
}
}
示例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;
}
示例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);
}
示例13: 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']];
}
示例14: 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];
}
示例15: formatPlain
/**
* {@inheritdoc}
*/
public function formatPlain($text)
{
return \SqlFormatter::format($text, false);
}