From c9eab7fad8a3bbd7ebfbd1353ed733da5b6693a0 Mon Sep 17 00:00:00 2001 From: xuanyuan300 Date: Sun, 19 Jun 2022 11:17:41 +0800 Subject: [PATCH 1/2] fix(parser): fix parsing `identifer.identifer` failed Signed-off-by: xuanyuan300 --- pisa-proxy/parser/mysql/src/lex.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pisa-proxy/parser/mysql/src/lex.rs b/pisa-proxy/parser/mysql/src/lex.rs index cf4b851c..685031c6 100644 --- a/pisa-proxy/parser/mysql/src/lex.rs +++ b/pisa-proxy/parser/mysql/src/lex.rs @@ -641,10 +641,16 @@ impl<'a> Scanner<'a> { } }); - self.is_ident_dot = self.peek() == '.'; - let ident_str = self.text[old_pos..self.pos].to_uppercase(); + // Check whether has the `ident.ident` format. + if self.is_ident_dot { + self.pos -= 1; + return DefaultLexeme::new(T_IDENT, old_pos, ident_str.len()); + } + + self.is_ident_dot = self.peek() == '.'; + if ident_str.starts_with('_') { // check `UNDERSCORE_CHARSET` token if CHARSETS.get(&*ident_str).is_some() { From a8f303f4167048f1bcbd1447d46f51a4e04fca4e Mon Sep 17 00:00:00 2001 From: xuanyuan300 Date: Sun, 19 Jun 2022 11:29:41 +0800 Subject: [PATCH 2/2] fix(parser): fix unit test faield Signed-off-by: xuanyuan300 --- pisa-proxy/parser/mysql/src/lex.rs | 2 +- pisa-proxy/parser/mysql/src/parser.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pisa-proxy/parser/mysql/src/lex.rs b/pisa-proxy/parser/mysql/src/lex.rs index 685031c6..b6253448 100644 --- a/pisa-proxy/parser/mysql/src/lex.rs +++ b/pisa-proxy/parser/mysql/src/lex.rs @@ -902,7 +902,7 @@ mod test { #[test] fn test_scan_start_at() { - let inputs = vec![("@abc", 3), ("@@session.sss", 12)]; + let inputs = vec![("@abc", 3), ("@@session.sss", 9)]; for (input, pos) in inputs { let mut scanner = Scanner::new(input); diff --git a/pisa-proxy/parser/mysql/src/parser.rs b/pisa-proxy/parser/mysql/src/parser.rs index 7ff40238..84c6f915 100644 --- a/pisa-proxy/parser/mysql/src/parser.rs +++ b/pisa-proxy/parser/mysql/src/parser.rs @@ -125,6 +125,7 @@ mod test { //"SET character_set_client = \"gbk\";", //"SET @@GLOBAL.character_set_client = gbk;", //"SET @@SESSION.character_set_client = gbk;", + "SELECT * from mysql.select;", "create database if not exists db CHARACTER SET = utf8;", ];