sql parser support mybatis

This commit is contained in:
wenshao
2012-07-17 17:33:31 +08:00
parent fd98aee19a
commit 0492b77082
6 changed files with 122 additions and 6 deletions
@@ -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("@@");
}
}