mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fix for sql wall
This commit is contained in:
@@ -28,6 +28,7 @@ public interface SQLObject {
|
||||
void setParent(SQLObject parent);
|
||||
|
||||
Map<String, Object> getAttributes();
|
||||
boolean containsAttribute(String name);
|
||||
Object getAttribute(String name);
|
||||
void putAttribute(String name, Object value);
|
||||
Map<String, Object> getAttributesDirect();
|
||||
|
||||
@@ -88,6 +88,14 @@ public abstract class SQLObjectImpl implements SQLObject {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public boolean containsAttribute(String name) {
|
||||
if (attributes == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return attributes.containsKey(name);
|
||||
}
|
||||
|
||||
public Object getAttribute(String name) {
|
||||
if (attributes == null) {
|
||||
return null;
|
||||
|
||||
@@ -246,8 +246,8 @@ public class SQLEvalVisitorUtils {
|
||||
if (function != null) {
|
||||
Object result = function.eval(visitor, x);
|
||||
|
||||
if (result != SQLEvalVisitor.EVAL_ERROR) {
|
||||
x.getAttributes().put(EVAL_VALUE, result);
|
||||
if (result != SQLEvalVisitor.EVAL_ERROR && result != null) {
|
||||
x.putAttribute(EVAL_VALUE, result);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -744,7 +744,7 @@ public class SQLEvalVisitorUtils {
|
||||
public static boolean visit(SQLEvalVisitor visitor, SQLInListExpr x) {
|
||||
SQLExpr valueExpr = x.getExpr();
|
||||
valueExpr.accept(visitor);
|
||||
if (!valueExpr.getAttributes().containsKey(EVAL_VALUE)) {
|
||||
if (!valueExpr.containsAttribute(EVAL_VALUE)) {
|
||||
return false;
|
||||
}
|
||||
Object value = valueExpr.getAttribute(EVAL_VALUE);
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Concat implements Function {
|
||||
for (SQLExpr item : x.getParameters()) {
|
||||
item.accept(visitor);
|
||||
|
||||
Object itemValue = item.getAttributes().get(EVAL_VALUE);
|
||||
Object itemValue = item.getAttribute(EVAL_VALUE);
|
||||
if (itemValue == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Elt implements Function {
|
||||
param0IntValue = ((Number) param0Value).intValue();
|
||||
|
||||
if (param0IntValue >= x.getParameters().size()) {
|
||||
return null;
|
||||
return SQLEvalVisitor.EVAL_VALUE_NULL;
|
||||
}
|
||||
|
||||
SQLExpr item = x.getParameters().get(param0IntValue);
|
||||
|
||||
@@ -1573,7 +1573,7 @@ public class WallVisitorUtils {
|
||||
}
|
||||
|
||||
public static Object getValue(WallVisitor visitor, SQLExpr x) {
|
||||
if (x != null && x.getAttributes().containsKey(EVAL_VALUE)) {
|
||||
if (x != null && x.containsAttribute(EVAL_VALUE)) {
|
||||
return getValueFromAttributes(visitor, x);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.alibaba.druid.bvt.filter.wall;
|
||||
|
||||
import com.alibaba.druid.wall.WallContext;
|
||||
import com.alibaba.druid.wall.WallProvider;
|
||||
import com.alibaba.druid.wall.spi.MySqlWallProvider;
|
||||
import com.alibaba.druid.wall.spi.OracleWallProvider;
|
||||
import com.alibaba.druid.wall.spi.PGWallProvider;
|
||||
import com.alibaba.druid.wall.spi.SQLServerWallProvider;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class WallStatTest_select_2
|
||||
extends TestCase {
|
||||
|
||||
private String sql = "SELECT *\n" +
|
||||
"FROM `t`\n" +
|
||||
"WHERE `t`.`col1` = '1'\n" +
|
||||
" AND `t`.`col2` = 0\n" +
|
||||
" AND CONCAT(t.col3, '_', t.col4) IN ('abc_def')";
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
WallContext.clearContext();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
WallContext.clearContext();
|
||||
}
|
||||
|
||||
public void testMySql() throws Exception {
|
||||
WallProvider provider = new MySqlWallProvider();
|
||||
assertTrue(provider.checkValid(sql));
|
||||
}
|
||||
|
||||
public void testOracle() throws Exception {
|
||||
WallProvider provider = new OracleWallProvider();
|
||||
assertTrue(provider.checkValid(sql));
|
||||
}
|
||||
|
||||
public void testPG() throws Exception {
|
||||
WallProvider provider = new PGWallProvider();
|
||||
assertTrue(provider.checkValid(sql));
|
||||
}
|
||||
|
||||
public void testSQLServer() throws Exception {
|
||||
WallProvider provider = new SQLServerWallProvider();
|
||||
assertTrue(provider.checkValid(sql));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user