Skip to content

Commit

Permalink
fix(parser): fix parsing identifer.identifer failed (database-mesh#104
Browse files Browse the repository at this point in the history
)

* fix(parser): fix parsing `identifer.identifer` failed

Signed-off-by: xuanyuan300 <[email protected]>

* fix(parser): fix unit test faield

Signed-off-by: xuanyuan300 <[email protected]>
  • Loading branch information
xuanyuan300 authored and mlycore committed Jun 27, 2022
1 parent 07aca71 commit c2f2cff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pisa-proxy/parser/mysql/src/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -896,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);
Expand Down
1 change: 1 addition & 0 deletions pisa-proxy/parser/mysql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;",
];

Expand Down

0 comments on commit c2f2cff

Please sign in to comment.