improve sql wall

This commit is contained in:
wenshao
2013-08-28 16:47:58 +08:00
parent faee5b92b7
commit 670c376feb
9 changed files with 233 additions and 53 deletions
@@ -64,19 +64,19 @@ public class MySqlLexer extends Lexer {
super(input);
super.keywods = DEFAULT_MYSQL_KEYWORDS;
}
public void scanSharp() {
if (ch != '#') {
throw new ParserException("illegal stat");
}
if (charAt(pos + 1) == '{') {
scanVariable();
return;
}
Token lastToken = this.token;
scanChar();
mark = pos;
bufPos = 0;
@@ -102,10 +102,10 @@ public class MySqlLexer extends Lexer {
scanChar();
bufPos++;
}
stringVal = subString(mark, bufPos);
token = Token.LINE_COMMENT;
if (commentHandler != null && commentHandler.handle(lastToken, stringVal)) {
return;
}
@@ -315,7 +315,7 @@ public class MySqlLexer extends Lexer {
switch (ch) {
case '\0':
putChar('\0');
putChar(ch = '\0');
break;
case '\'':
putChar('\'');
@@ -345,20 +345,19 @@ public class MySqlLexer extends Lexer {
putChar(ch);
break;
}
scanChar();
}
if (ch == '\'') {
scanChar();
if (ch != '\'') {
token = LITERAL_CHARS;
break;
} else {
initBuff(bufPos);
arraycopy(mark + 1, buf, 0, bufPos);
hasSpecial = true;
putChar('\'');
continue;
} else {
if (ch == '\'') {
scanChar();
if (ch != '\'') {
token = LITERAL_CHARS;
break;
} else {
initBuff(bufPos);
arraycopy(mark + 1, buf, 0, bufPos);
hasSpecial = true;
putChar('\'');
continue;
}
}
}
@@ -438,7 +437,7 @@ public class MySqlLexer extends Lexer {
if (commentHandler != null && commentHandler.handle(lastToken, stringVal)) {
return;
}
if (!isAllowComment()) {
throw new NotAllowCommentException();
}
@@ -474,7 +473,7 @@ public class MySqlLexer extends Lexer {
stringVal = subString(mark, bufPos + 1);
token = Token.LINE_COMMENT;
if (commentHandler != null && commentHandler.handle(lastToken, stringVal)) {
return;
}
@@ -482,7 +481,7 @@ public class MySqlLexer extends Lexer {
if (!isAllowComment()) {
throw new NotAllowCommentException();
}
return;
}
}
@@ -1210,7 +1210,7 @@ public class SQLExprParser extends SQLParser {
if (lexer.token() == Token.ESCAPE) {
lexer.nextToken();
rightExp = expr();
rightExp = primary();
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Escape, rightExp);
}
} else if (lexer.token() == (Token.NOT)) {
@@ -570,8 +570,12 @@ public class SQLEvalVisitorUtils {
public static boolean visit(SQLEvalVisitor visitor, SQLHexExpr x) {
String hex = x.getHex();
byte[] bytes = HexBin.decode(hex);
String val = new String(bytes);
x.putAttribute(EVAL_VALUE, val);
if (bytes == null) {
x.putAttribute(EVAL_VALUE, EVAL_ERROR);
} else {
String val = new String(bytes);
x.putAttribute(EVAL_VALUE, val);
}
return true;
}
@@ -807,9 +811,13 @@ public class SQLEvalVisitorUtils {
x.putAttribute(EVAL_VALUE, val);
break;
case NOT:
case Not:
x.putAttribute(EVAL_VALUE, !castToBoolean(val));
case Not: {
Boolean booleanVal = castToBoolean(val);
if (booleanVal != null) {
x.putAttribute(EVAL_VALUE, !booleanVal);
}
break;
}
case Plus:
x.putAttribute(EVAL_VALUE, val);
break;
@@ -1368,9 +1376,9 @@ public class SQLEvalVisitorUtils {
BigDecimal decimalA = castToDecimal(a);
BigDecimal decimalB = castToDecimal(b);
if (decimalB.scale() < decimalA.scale()) {
decimalB.setScale(decimalA.scale());
decimalB = decimalB.setScale(decimalA.scale());
}
return decimalA.divide(decimalB);
return decimalA.divide(decimalB, BigDecimal.ROUND_HALF_UP);
}
if (a instanceof Double || b instanceof Double) {