mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve SQL Parser
This commit is contained in:
@@ -177,8 +177,6 @@ public class MySqlLexer extends Lexer {
|
||||
throw new SQLParseException("illegal identifier");
|
||||
}
|
||||
|
||||
int hash = first;
|
||||
|
||||
mark = pos;
|
||||
bufPos = 1;
|
||||
char ch;
|
||||
@@ -189,15 +187,13 @@ public class MySqlLexer extends Lexer {
|
||||
break;
|
||||
}
|
||||
|
||||
hash = 31 * hash + ch;
|
||||
|
||||
bufPos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
this.ch = charAt(pos);
|
||||
|
||||
stringVal = addSymbol(hash);
|
||||
stringVal = addSymbol();
|
||||
Token tok = keywods.getKeyword(stringVal);
|
||||
if (tok != null) {
|
||||
token = tok;
|
||||
|
||||
@@ -106,8 +106,6 @@ public class OracleLexer extends Lexer {
|
||||
throw new SQLParseException("illegal variable");
|
||||
}
|
||||
|
||||
int hash = ch;
|
||||
|
||||
mark = pos;
|
||||
bufPos = 1;
|
||||
char ch;
|
||||
@@ -115,12 +113,10 @@ public class OracleLexer extends Lexer {
|
||||
boolean quoteFlag = false;
|
||||
boolean mybatisFlag = false;
|
||||
if (charAt(pos + 1) == '"') {
|
||||
hash = 31 * hash + '"';
|
||||
pos++;
|
||||
bufPos++;
|
||||
quoteFlag = true;
|
||||
} else if (charAt(pos + 1) == '{') {
|
||||
hash = 31 * hash + '"';
|
||||
pos++;
|
||||
bufPos++;
|
||||
mybatisFlag = true;
|
||||
@@ -133,8 +129,6 @@ public class OracleLexer extends Lexer {
|
||||
break;
|
||||
}
|
||||
|
||||
hash = 31 * hash + ch;
|
||||
|
||||
bufPos++;
|
||||
continue;
|
||||
}
|
||||
@@ -143,21 +137,19 @@ public class OracleLexer extends Lexer {
|
||||
if (ch != '"') {
|
||||
throw new SQLParseException("syntax error");
|
||||
}
|
||||
hash = 31 * hash + '"';
|
||||
++pos;
|
||||
bufPos++;
|
||||
} else if (mybatisFlag) {
|
||||
if (ch != '}') {
|
||||
throw new SQLParseException("syntax error");
|
||||
}
|
||||
hash = 31 * hash + '"';
|
||||
++pos;
|
||||
bufPos++;
|
||||
}
|
||||
|
||||
this.ch = charAt(pos);
|
||||
|
||||
stringVal = addSymbol(hash);
|
||||
stringVal = addSymbol();
|
||||
Token tok = keywods.getKeyword(stringVal);
|
||||
if (tok != null) {
|
||||
token = tok;
|
||||
|
||||
@@ -79,7 +79,7 @@ public class Lexer {
|
||||
return text.charAt(index);
|
||||
}
|
||||
|
||||
public String addSymbol(int hash) {
|
||||
public String addSymbol() {
|
||||
return subString(mark, bufPos);
|
||||
}
|
||||
|
||||
@@ -567,14 +567,10 @@ public class Lexer {
|
||||
}
|
||||
|
||||
public void scanVariable() {
|
||||
final char first = ch;
|
||||
|
||||
if (ch != '@' && ch != ':' && ch != '#' && ch != '$') {
|
||||
throw new SQLParseException("illegal variable");
|
||||
}
|
||||
|
||||
int hash = first;
|
||||
|
||||
mark = pos;
|
||||
bufPos = 1;
|
||||
char ch;
|
||||
@@ -582,11 +578,9 @@ public class Lexer {
|
||||
boolean mybatisFlag = false;
|
||||
if (charAt(pos + 1) == '@') {
|
||||
ch = charAt(++pos);
|
||||
hash = 31 * hash + ch;
|
||||
|
||||
bufPos++;
|
||||
} else if (charAt(pos + 1) == '{') {
|
||||
hash = 31 * hash + '"';
|
||||
pos++;
|
||||
bufPos++;
|
||||
mybatisFlag = true;
|
||||
@@ -599,8 +593,6 @@ public class Lexer {
|
||||
break;
|
||||
}
|
||||
|
||||
hash = 31 * hash + ch;
|
||||
|
||||
bufPos++;
|
||||
continue;
|
||||
}
|
||||
@@ -609,14 +601,13 @@ public class Lexer {
|
||||
if (ch != '}') {
|
||||
throw new SQLParseException("syntax error");
|
||||
}
|
||||
hash = 31 * hash + '"';
|
||||
++pos;
|
||||
bufPos++;
|
||||
}
|
||||
|
||||
this.ch = charAt(pos);
|
||||
|
||||
stringVal = addSymbol(hash);
|
||||
stringVal = addSymbol();
|
||||
token = Token.VARIANT;
|
||||
}
|
||||
|
||||
@@ -693,8 +684,6 @@ public class Lexer {
|
||||
throw new SQLParseException("illegal identifier");
|
||||
}
|
||||
|
||||
int hash = first;
|
||||
|
||||
mark = pos;
|
||||
bufPos = 1;
|
||||
char ch;
|
||||
@@ -705,7 +694,6 @@ public class Lexer {
|
||||
break;
|
||||
}
|
||||
|
||||
hash = 31 * hash + ch;
|
||||
|
||||
bufPos++;
|
||||
continue;
|
||||
@@ -713,7 +701,7 @@ public class Lexer {
|
||||
|
||||
this.ch = charAt(pos);
|
||||
|
||||
stringVal = addSymbol(hash);
|
||||
stringVal = addSymbol();
|
||||
Token tok = keywods.getKeyword(stringVal);
|
||||
if (tok != null) {
|
||||
token = tok;
|
||||
|
||||
Reference in New Issue
Block a user