mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql parser support mybatis
This commit is contained in:
@@ -63,7 +63,7 @@ public class MySqlLexer extends Lexer {
|
||||
public void scanVariable() {
|
||||
final char first = ch;
|
||||
|
||||
if (ch != '@' && ch != ':' && ch != '#') {
|
||||
if (ch != '@' && ch != ':' && ch != '#' && ch != '$') {
|
||||
throw new SQLParseException("illegal variable");
|
||||
}
|
||||
|
||||
@@ -104,6 +104,31 @@ public class MySqlLexer extends Lexer {
|
||||
|
||||
stringVal = symbolTable.addSymbol(buf, np, sp, hash);
|
||||
token = Token.VARIANT;
|
||||
} else if (buf[bp + 1] == '{') {
|
||||
++bp;
|
||||
++sp;
|
||||
char ch;
|
||||
for (;;) {
|
||||
ch = buf[++bp];
|
||||
|
||||
if (ch == '}') {
|
||||
sp++;
|
||||
ch = buf[++bp];
|
||||
break;
|
||||
} else if (ch == EOI) {
|
||||
throw new SQLParseException("illegal identifier");
|
||||
}
|
||||
|
||||
hash = 31 * hash + ch;
|
||||
|
||||
sp++;
|
||||
continue;
|
||||
}
|
||||
|
||||
this.ch = buf[bp];
|
||||
|
||||
stringVal = symbolTable.addSymbol(buf, np, sp, hash);
|
||||
token = Token.VARIANT;
|
||||
} else {
|
||||
for (;;) {
|
||||
ch = buf[++bp];
|
||||
|
||||
@@ -494,7 +494,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (x.isGlobal()) {
|
||||
print("@@global.");
|
||||
} else {
|
||||
if ((!x.getName().startsWith("@")) && (!x.getName().equals("?"))) {
|
||||
String varName = x.getName();
|
||||
if ((!varName.startsWith("@")) && (!varName.equals("?")) && (!varName.startsWith("#")) && (!varName.startsWith("$"))) {
|
||||
print("@@");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class OracleLexer extends Lexer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch != ':' && ch != '#') {
|
||||
if (ch != ':' && ch != '#' && ch != '$') {
|
||||
throw new SQLParseException("illegal variable");
|
||||
}
|
||||
|
||||
@@ -98,12 +98,19 @@ public class OracleLexer extends Lexer {
|
||||
char ch;
|
||||
|
||||
boolean quoteFlag = false;
|
||||
boolean mybatisFlag = false;
|
||||
if (buf[bp + 1] == '"') {
|
||||
hash = 31 * hash + '"';
|
||||
bp++;
|
||||
sp++;
|
||||
quoteFlag = true;
|
||||
} else if (buf[bp + 1] == '{') {
|
||||
hash = 31 * hash + '"';
|
||||
bp++;
|
||||
sp++;
|
||||
mybatisFlag = true;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
ch = buf[++bp];
|
||||
|
||||
@@ -116,6 +123,7 @@ public class OracleLexer extends Lexer {
|
||||
sp++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (quoteFlag) {
|
||||
if (ch != '"') {
|
||||
throw new SQLParseException("syntax error");
|
||||
@@ -123,6 +131,13 @@ public class OracleLexer extends Lexer {
|
||||
hash = 31 * hash + '"';
|
||||
++bp;
|
||||
sp++;
|
||||
} else if (mybatisFlag) {
|
||||
if (ch != '}') {
|
||||
throw new SQLParseException("syntax error");
|
||||
}
|
||||
hash = 31 * hash + '"';
|
||||
++bp;
|
||||
sp++;
|
||||
}
|
||||
|
||||
this.ch = buf[bp];
|
||||
|
||||
@@ -205,9 +205,13 @@ public class Lexer {
|
||||
if (isWhitespace(ch)) {
|
||||
scanChar();
|
||||
continue;
|
||||
}// QS_TODO skip comment
|
||||
}
|
||||
|
||||
if (ch == '$' && buf[bp + 1] == '{') {
|
||||
scanVariable();
|
||||
return;
|
||||
}
|
||||
|
||||
// QS_TODO id may start from digit
|
||||
if (isFirstIdentifierChar(ch)) {
|
||||
if (ch == 'N') {
|
||||
if (buf[bp + 1] == '\'') {
|
||||
@@ -571,7 +575,7 @@ public class Lexer {
|
||||
public void scanVariable() {
|
||||
final char first = ch;
|
||||
|
||||
if (ch != '@' && ch != ':' && ch != '#') {
|
||||
if (ch != '@' && ch != ':' && ch != '#' && ch != '$') {
|
||||
throw new SQLParseException("illegal variable");
|
||||
}
|
||||
|
||||
@@ -581,11 +585,17 @@ public class Lexer {
|
||||
sp = 1;
|
||||
char ch;
|
||||
|
||||
boolean mybatisFlag = false;
|
||||
if (buf[bp + 1] == '@') {
|
||||
ch = buf[++bp];
|
||||
hash = 31 * hash + ch;
|
||||
|
||||
sp++;
|
||||
} else if (buf[bp + 1] == '{') {
|
||||
hash = 31 * hash + '"';
|
||||
bp++;
|
||||
sp++;
|
||||
mybatisFlag = true;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
@@ -600,6 +610,15 @@ public class Lexer {
|
||||
sp++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mybatisFlag) {
|
||||
if (ch != '}') {
|
||||
throw new SQLParseException("syntax error");
|
||||
}
|
||||
hash = 31 * hash + '"';
|
||||
++bp;
|
||||
sp++;
|
||||
}
|
||||
|
||||
this.ch = buf[bp];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user