Report correct position for SQL files with unicode characters
[php-sqllint.git] / src / phpsqllint / Cli.php
index 4edcf666c777db965c544c1840aa0967f28150b8..61acfa0e59c1d0c434958711d373a5702f07107f 100644 (file)
@@ -11,9 +11,7 @@
  * @link     http://cweiske.de/php-sqllint.htm
  */
 namespace phpsqllint;
-use SqlParser\Parser;
-
-require_once 'Console/CommandLine.php';
+use PhpMyAdmin\SqlParser\Parser;
 
 /**
  * Command line interface
@@ -84,7 +82,7 @@ class Cli
             return false;
         }
 
-        $parser = new \SqlParser\Parser($sql);
+        $parser = new \PhpMyAdmin\SqlParser\Parser($sql);
         if (count($parser->errors) == 0) {
             $this->renderer->finishOk();
             return true;
@@ -93,12 +91,12 @@ class Cli
         $lines = array(1 => 0);
         $pos = -1;
         $line = 1;
-        while (false !== $pos = strpos($sql, "\n", ++$pos)) {
+        while (false !== $pos = mb_strpos($sql, "\n", ++$pos)) {
             $lines[++$line] = $pos;
         }
 
         foreach ($parser->errors as $error) {
-            /* @var SqlParser\Exceptions\ParserException $error) */
+            /* @var PhpMyAdmin\SqlParser\Exceptions\ParserException $error) */
             reset($lines);
             $line = 1;
             while (next($lines) && $error->token->position >= current($lines)) {
@@ -137,7 +135,7 @@ class Cli
         $options = array(
             'type' => $typeMap[$this->highlight],
         );
-        echo \SqlParser\Utils\Formatter::format($sql, $options) . "\n";
+        echo \PhpMyAdmin\SqlParser\Utils\Formatter::format($sql, $options) . "\n";
     }
 
     protected function loadSql($filename)