diff options
author | Haru <haru@dotalux.com> | 2019-11-18 21:02:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-18 21:02:01 +0100 |
commit | 5e61cd4f23492fded25d48a4d6609603d916c5e5 (patch) | |
tree | fae5542ba5319753087129d92b6f8032b9a09147 /tools/php-sqllint/src/phpsqllint/Renderer/Text.php | |
parent | fac2eef6c66b1da34c68963732f8afece3a5289f (diff) | |
parent | 8312581eb96d1d497fbce59a7a33fc55a6c236b5 (diff) | |
download | hercules-5e61cd4f23492fded25d48a4d6609603d916c5e5.tar.gz hercules-5e61cd4f23492fded25d48a4d6609603d916c5e5.tar.bz2 hercules-5e61cd4f23492fded25d48a4d6609603d916c5e5.tar.xz hercules-5e61cd4f23492fded25d48a4d6609603d916c5e5.zip |
Merge pull request #2582 from 4144/sqlvalidation
Add script for sql files syntax validation
Diffstat (limited to 'tools/php-sqllint/src/phpsqllint/Renderer/Text.php')
-rw-r--r-- | tools/php-sqllint/src/phpsqllint/Renderer/Text.php | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tools/php-sqllint/src/phpsqllint/Renderer/Text.php b/tools/php-sqllint/src/phpsqllint/Renderer/Text.php new file mode 100644 index 000000000..44e7ecbd4 --- /dev/null +++ b/tools/php-sqllint/src/phpsqllint/Renderer/Text.php @@ -0,0 +1,102 @@ +<?php +/** + * Part of php-sqllint + * + * PHP version 5 + * + * @category Tools + * @package PHP-SQLlint + * @author Christian Weiske <cweiske@cweiske.de> + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/php-sqllint.htm + */ +namespace phpsqllint; + +/** + * Textual output, easily readable by humans. + * + * @category Tools + * @package PHP-SQLlint + * @author Christian Weiske <cweiske@cweiske.de> + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://www.emacswiki.org/emacs/CreatingYourOwnCompileErrorRegexp + */ +class Renderer_Text implements Renderer +{ + protected $fileshown = false; + protected $filename = null; + + /** + * Begin syntax check output rendering + * + * @param string $filename Path to the SQL file + * + * @return void + */ + public function startRendering($filename) + { + $this->filename = $filename; + $this->fileshown = false; + } + + + protected function showFile() + { + if ($this->fileshown) { + return; + } + + echo "Checking SQL syntax of " . $this->filename . "\n"; + $this->fileshown = true; + } + + /** + * Show the error to the user. + * + * @param string $msg Error message + * @param string $token Character which caused the error + * @param integer $line Line at which the error occured + * @param integer $col Column at which the error occured + * + * @return void + */ + public function displayError($msg, $token, $line, $col) + { + $this->showFile(); + echo ' Line ' . $line + . ', col ' . $col + . ' at "' . $this->niceToken($token) . '":' + . ' ' . $msg + . "\n"; + } + + /** + * Finish syntax check output rendering; no syntax errors found + * + * @return void + */ + public function finishOk() + { + if ($this->fileshown) { + echo " OK\n"; + } + } + + /** + * Convert the token string to a readable one, especially special + * characters like newline and tabs + * + * @param string $str String with possibly special characters + * + * @return string Escaped string + */ + protected function niceToken($str) + { + return str_replace( + ["\n", "\r", "\t"], + ['\n', '\r', '\t'], + $str + ); + } +} +?> |