Skip to content

Commit 80dc400

Browse files
committed
1. bug
2. parse null bug
1 parent e229abe commit 80dc400

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/ClickHouseSQLParser.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ public static function token_get_all($str, $options = array())
643643
$tokens = array();
644644
if ($dont_allow_comment) {
645645
\preg_match_all("{[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*|\\`(?:[^\\`\\\\]|\\\\.)*\\`|\\\"(?:[^\\\"\\\\]|\\\\.)*\\\"|\\'(?:[^\\'\\\\]|\\\\.)*\\'|\\s+|\\d+(?:\\.\\d*)?(?:[Ee][\\+\\-]?\\d+)?|\\<\\=\\>|\\!\\=|\\>\\=|\\<\\=|\\<\\>|\\<\\<|\\>\\>|\\:\\=|&&|\\|\\||@@|\\-\\>|.}s", $str, $m);
646+
646647
foreach ($m[0] as $token) {
647648
switch (isset($map[$token[0]]) ? $map[$token[0]] : -1) {
648649
case 1:
@@ -661,7 +662,11 @@ public static function token_get_all($str, $options = array())
661662
$tokens[] = array(self::T_WHITESPACE, $token);
662663
break;
663664
case 9:
664-
$tokens[] = array(self::T_IDENTIFIER_NOQUOTE, $token);
665+
if(strcasecmp($token,"NULL")==0){
666+
$tokens[] = array(self::T_CONSTANT_NULL,$token);
667+
}else{
668+
$tokens[] = array(self::T_IDENTIFIER_NOQUOTE, $token);
669+
}
665670
break;
666671
default:
667672
$tokens[] = $token;
@@ -693,7 +698,11 @@ public static function token_get_all($str, $options = array())
693698
$tokens[] = array(self::T_WHITESPACE, $token);
694699
break;
695700
case 9:
696-
$tokens[] = array(self::T_IDENTIFIER_NOQUOTE, $token);
701+
if(strcasecmp($token,"NULL")==0){
702+
$tokens[] = array(self::T_CONSTANT_NULL,$token);
703+
}else{
704+
$tokens[] = array(self::T_IDENTIFIER_NOQUOTE, $token);
705+
}
697706
break;
698707
default:
699708
$tokens[] = $token;

src/ClickHouseSQLParserExt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected static function parse_impl($sql, $options = array())
5252
if(count($tokens)==0){
5353
throw new \ErrorException("cannot parse as sql, empty string");
5454
}
55-
if ($expr = self::check_and_parse_select($tokens)) {
55+
if ($expr = self::check_and_parse_select($sql,$options)) {
5656
} elseif (self::is_token_of($tokens[0],"SHOW")) {
5757
list($expr, $index) = self::get_next_show($tokens, 0);
5858
if ($index != \count($tokens)) {

0 commit comments

Comments
 (0)