mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve sql wall
This commit is contained in:
@@ -169,9 +169,9 @@ public class WallContext {
|
||||
}
|
||||
|
||||
public void incrementUpdateNoneConditionWarnnings() {
|
||||
if (this.updateNoneConditionWarnnings == 0) {
|
||||
this.incrementWarnnings();
|
||||
}
|
||||
// if (this.updateNoneConditionWarnnings == 0) {
|
||||
// this.incrementWarnnings();
|
||||
// }
|
||||
this.updateNoneConditionWarnnings++;
|
||||
}
|
||||
|
||||
@@ -180,9 +180,9 @@ public class WallContext {
|
||||
}
|
||||
|
||||
public void incrementDeleteNoneConditionWarnnings() {
|
||||
if (this.deleteNoneConditionWarnnings == 0) {
|
||||
this.incrementWarnnings();
|
||||
}
|
||||
// if (this.deleteNoneConditionWarnnings == 0) {
|
||||
// this.incrementWarnnings();
|
||||
// }
|
||||
this.deleteNoneConditionWarnnings++;
|
||||
}
|
||||
|
||||
|
||||
@@ -665,11 +665,7 @@ public abstract class WallProvider {
|
||||
}
|
||||
|
||||
if (visitor.getViolations().size() == 0 && context != null && context.getWarnnings() >= 2) {
|
||||
if (context.getDeleteNoneConditionWarnnings() > 0) {
|
||||
violations.add(new IllegalSQLObjectViolation(ErrorCode.NONE_CONDITION, "delete none condition", sql));
|
||||
} else if (context.getUpdateNoneConditionWarnnings() > 0) {
|
||||
violations.add(new IllegalSQLObjectViolation(ErrorCode.NONE_CONDITION, "update none condition", sql));
|
||||
} else if (context.getCommentCount() > 0) {
|
||||
if (context.getCommentCount() > 0) {
|
||||
violations.add(new IllegalSQLObjectViolation(ErrorCode.COMMIT_NOT_ALLOW, "comment not allow", sql));
|
||||
} else if (context.getLikeNumberWarnnings() > 0) {
|
||||
violations.add(new IllegalSQLObjectViolation(ErrorCode.COMMIT_NOT_ALLOW, "like number", sql));
|
||||
|
||||
@@ -277,10 +277,6 @@ public class WallVisitorUtils {
|
||||
Object whereValue = getConditionValue(visitor, where, visitor.getConfig().isSelectWhereAlwayTrueCheck());
|
||||
|
||||
if (Boolean.TRUE == whereValue) {
|
||||
if (queryBlockFromIsNull(visitor, x, false)) {
|
||||
addViolation(visitor, ErrorCode.EMPTY_QUERY_HAS_CONDITION, "empty select has condition", x);
|
||||
}
|
||||
|
||||
if (!isSimpleConstExpr(where)) {// 简单表达式
|
||||
addViolation(visitor, ErrorCode.ALWAY_TRUE, "select alway true condition not allow", x);
|
||||
}
|
||||
@@ -2102,7 +2098,8 @@ public class WallVisitorUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
if (WallVisitorUtils.queryBlockFromIsNull(visitor, x.getRight())) {
|
||||
if (!WallVisitorUtils.queryBlockFromIsNull(visitor, x.getLeft())
|
||||
&& WallVisitorUtils.queryBlockFromIsNull(visitor, x.getRight())) {
|
||||
boolean isTopUpdateStatement = false;
|
||||
boolean isTopInsertStatement = false;
|
||||
SQLObject selectParent = x.getParent();
|
||||
|
||||
@@ -43,10 +43,10 @@ public class SyntaxErrorViolation implements Violation {
|
||||
|
||||
public String getMessage() {
|
||||
if (exception == null) {
|
||||
return null;
|
||||
return "syntax error";
|
||||
}
|
||||
|
||||
return exception.getMessage();
|
||||
return "syntax error: " + exception.getMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,8 @@ public class MySqlWallTest134 extends TestCase {
|
||||
public void test_false() throws Exception {
|
||||
WallProvider provider = new MySqlWallProvider();
|
||||
|
||||
Assert.assertFalse(provider.checkValid("SELECT 1 FROM dual WHERE 1 = '1'''''''''''''UNION SELECT '2';"));
|
||||
Assert.assertTrue(provider.checkValid("SELECT 1 FROM dual WHERE 1 = '1'''''''''''''UNION SELECT '2';"));
|
||||
Assert.assertFalse(provider.checkValid("SELECT 1 FROM t WHERE 1 = '1'''''''''''''UNION SELECT '2';"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class MySqlWallTest49 extends TestCase {
|
||||
public void test_false() throws Exception {
|
||||
WallProvider provider = new MySqlWallProvider();
|
||||
|
||||
Assert.assertFalse(provider.checkValid(//
|
||||
Assert.assertTrue(provider.checkValid(//
|
||||
"select temp.*, u.CanComment, u.CanBeShared, " + //
|
||||
" u.CanForward, COALESCE(b.UserID,0) as isBlocked, " + //
|
||||
" COALESCE(f.UserID,0) as Followed, COALESCE(ff.UserID,0) as IsFollowed, " + //
|
||||
|
||||
@@ -35,7 +35,7 @@ public class MySqlWallTest62 extends TestCase {
|
||||
WallProvider provider = new MySqlWallProvider();
|
||||
provider.getConfig().setSchemaCheck(true);
|
||||
|
||||
Assert.assertFalse(provider.checkValid(//
|
||||
Assert.assertTrue(provider.checkValid(//
|
||||
"select temp.*, u.CanComment, u.CanBeShared, u.CanForward, COALESCE(b.UserID,0) as isBlocked" + //
|
||||
" , COALESCE(f.UserID,0) as Followed, COALESCE(ff.UserID,0) as IsFollowed" + //
|
||||
" , COALESCE(ul.UserID,0) as liked, COALESCE(fff.UserID,0) as RIsFollowed " + //
|
||||
@@ -50,6 +50,19 @@ public class MySqlWallTest62 extends TestCase {
|
||||
|
||||
Assert.assertEquals(4, provider.getTableStats().size());
|
||||
}
|
||||
|
||||
public void test_false() throws Exception {
|
||||
WallProvider provider = new MySqlWallProvider();
|
||||
provider.getConfig().setSchemaCheck(true);
|
||||
String sql = "SELECT 1, 2, 3" + //
|
||||
" UNION ALL SELECT a from tt " + //
|
||||
" UNION ALL SELECT 2 FROM dual ";
|
||||
Assert.assertFalse(provider.checkValid(sql));
|
||||
|
||||
sql = "SELECT a from t UNION ALL SELECT 2 FROM dual ";
|
||||
Assert.assertFalse(provider.checkValid(sql));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user