File: sql-formatter

package info (click to toggle)
php-sql-formatter 1.2.17%2Bdct1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 692 kB
  • sloc: php: 1,819; sql: 301; xml: 18; makefile: 17
file content (20 lines) | stat: -rwxr-xr-x 753 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/php
<?php

if("cli" !== php_sapi_name()) {
    echo "<p>Run this PHP script from the command line to see CLI syntax highlighting and formatting.  It supports Unix pipes or command line argument style.</p>";
    echo "<pre><code>php bin/sql-formatter \"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 bin/sql-formatter</code></pre>";
    exit;
}

if(isset($argv[1])) {
    $sql = $argv[1];
}
else {
    $sql = stream_get_contents(fopen('php://stdin', 'r'));
}

require_once('Doctrine/SqlFormatter/autoload.php');

echo (new \Doctrine\SqlFormatter\SqlFormatter())->format($sql);