mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve wall filter
This commit is contained in:
@@ -194,7 +194,7 @@ public class SQLEvalVisitorUtils {
|
||||
|
||||
if (function != null) {
|
||||
Object result = function.eval(visitor, x);
|
||||
|
||||
|
||||
if (result != SQLEvalVisitor.EVAL_ERROR) {
|
||||
x.getAttributes().put(EVAL_VALUE, result);
|
||||
}
|
||||
@@ -954,6 +954,10 @@ public class SQLEvalVisitorUtils {
|
||||
if (val instanceof Short) {
|
||||
return (Short) val;
|
||||
}
|
||||
|
||||
if (val instanceof String) {
|
||||
return Short.parseShort((String) val);
|
||||
}
|
||||
|
||||
return ((Number) val).shortValue();
|
||||
}
|
||||
@@ -967,6 +971,17 @@ public class SQLEvalVisitorUtils {
|
||||
return (Integer) val;
|
||||
}
|
||||
|
||||
if (val instanceof String) {
|
||||
return Integer.parseInt((String) val);
|
||||
}
|
||||
|
||||
if (val instanceof List) {
|
||||
List list = (List) val;
|
||||
if (list.size() == 1) {
|
||||
return castToInteger(list.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
return ((Number) val).intValue();
|
||||
}
|
||||
|
||||
@@ -978,6 +993,18 @@ public class SQLEvalVisitorUtils {
|
||||
if (val instanceof Long) {
|
||||
return (Long) val;
|
||||
}
|
||||
|
||||
if (val instanceof String) {
|
||||
return Long.parseLong((String) val);
|
||||
}
|
||||
|
||||
|
||||
if (val instanceof List) {
|
||||
List list = (List) val;
|
||||
if (list.size() == 1) {
|
||||
return castToLong(list.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
return ((Number) val).longValue();
|
||||
}
|
||||
@@ -1395,6 +1422,10 @@ public class SQLEvalVisitorUtils {
|
||||
if (b == null) {
|
||||
return a;
|
||||
}
|
||||
|
||||
if (a instanceof Date || b instanceof Date) {
|
||||
return SQLEvalVisitor.EVAL_ERROR;
|
||||
}
|
||||
|
||||
if (a instanceof BigDecimal || b instanceof BigDecimal) {
|
||||
return castToDecimal(a).subtract(castToDecimal(b));
|
||||
@@ -1427,8 +1458,12 @@ public class SQLEvalVisitorUtils {
|
||||
if (a instanceof Byte || b instanceof Byte) {
|
||||
return castToByte(a) - castToByte(b);
|
||||
}
|
||||
|
||||
if(a instanceof String && b instanceof String) {
|
||||
return castToLong(a) - castToLong(b);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException();
|
||||
return SQLEvalVisitor.EVAL_ERROR;
|
||||
}
|
||||
|
||||
public static Object multi(Object a, Object b) {
|
||||
|
||||
@@ -189,11 +189,11 @@ public final class DruidStatManagerFacade {
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static Map mergWallStat(Map mapA, Map mapB) {
|
||||
if (mapA.size() == 0) {
|
||||
if (mapA == null || mapA.size() == 0) {
|
||||
return mapB;
|
||||
}
|
||||
|
||||
if (mapB.size() == 0) {
|
||||
if (mapB == null || mapB.size() == 0) {
|
||||
return mapA;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class WallFunctionStat {
|
||||
}
|
||||
|
||||
public void incrementInvokeCount() {
|
||||
this.invokeCount++;
|
||||
invokeCountUpdater.incrementAndGet(this);
|
||||
}
|
||||
|
||||
public void addSqlFunctionStat(WallSqlFunctionStat sqlFunctionStat) {
|
||||
|
||||
@@ -223,7 +223,7 @@ public class WallVisitorUtils {
|
||||
}
|
||||
|
||||
public static void checkDelete(WallVisitor visitor, SQLDeleteStatement x) {
|
||||
checkReadOnly(visitor, x.getExprTableSource());
|
||||
checkReadOnly(visitor, x.getTableSource());
|
||||
|
||||
WallConfig config = visitor.getConfig();
|
||||
if (!config.isDeleteAllow()) {
|
||||
|
||||
Reference in New Issue
Block a user