From 9621e373117440d4890b93bc69b1848252361474 Mon Sep 17 00:00:00 2001 From: wenshao Date: Fri, 12 Apr 2013 11:06:27 +0800 Subject: [PATCH 1/4] add error info --- .../druid/pool/DruidPooledConnection.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java index d4d8bed89e..8f5ac28342 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java +++ b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java @@ -1025,15 +1025,27 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql. public void checkState() throws SQLException { if (holder == null) { - throw new SQLException("connection holder is null"); + if (disableError != null) { + throw new SQLException("connection holder is null", disableError); + } else { + throw new SQLException("connection holder is null"); + } } if (closed) { - throw new SQLException("connection closed"); + if (disableError != null) { + throw new SQLException("connection closed", disableError); + } else { + throw new SQLException("connection closed"); + } } if (disable) { - throw new SQLException("connection disabled", disableError); + if (disableError != null) { + throw new SQLException("connection disabled", disableError); + } else { + throw new SQLException("connection disabled"); + } } } From 0612632591803f94b0895b3ab401d798b7bafd6e Mon Sep 17 00:00:00 2001 From: wenshao Date: Fri, 12 Apr 2013 11:06:50 +0800 Subject: [PATCH 2/4] improve wall filter --- .../sql/dialect/mysql/parser/MySqlLexer.java | 1 + .../sql/visitor/SQLEvalVisitorUtils.java | 2 +- .../com/alibaba/druid/wall/WallContext.java | 12 +++ .../com/alibaba/druid/wall/WallProvider.java | 2 + .../druid/wall/spi/MySqlWallVisitor.java | 4 +- .../druid/wall/spi/WallVisitorUtils.java | 74 +++++++++++-------- .../druid/wall/violation/ErrorCode.java | 3 +- .../bvt/filter/wall/MySqlWallTest80.java | 54 ++++++++++++++ .../bvt/filter/wall/MySqlWallTest81.java | 44 +++++++++++ .../bvt/filter/wall/MySqlWallTest82.java | 44 +++++++++++ .../bvt/filter/wall/MySqlWallTest_like_1.java | 2 +- .../bvt/filter/wall/TenantSelectTest2.java | 2 +- .../bvt/filter/wall/TenantSelectTest3.java | 2 +- 13 files changed, 209 insertions(+), 37 deletions(-) create mode 100644 src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest80.java create mode 100644 src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest81.java create mode 100644 src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest82.java diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java index 36b6976a21..60cecea063 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java @@ -259,6 +259,7 @@ public class MySqlLexer extends Lexer { final char ch = text.charAt(i); if (ch == '\\') { hasSpecial = true; + continue; } if (ch == '\'') { endIndex = i; diff --git a/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java b/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java index 880e72e2ea..d602f7df43 100644 --- a/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java +++ b/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java @@ -649,7 +649,7 @@ public class SQLEvalVisitorUtils { } public static boolean visit(SQLEvalVisitor visitor, SQLQueryExpr x) { - if (WallVisitorUtils.isSimpleCountTableSource(((SQLQueryExpr) x).getSubQuery())) { + if (WallVisitorUtils.isSimpleCountTableSource(null, ((SQLQueryExpr) x).getSubQuery())) { x.putAttribute(EVAL_VALUE, 1); return false; } diff --git a/src/main/java/com/alibaba/druid/wall/WallContext.java b/src/main/java/com/alibaba/druid/wall/WallContext.java index 63374e5624..037b19db4d 100644 --- a/src/main/java/com/alibaba/druid/wall/WallContext.java +++ b/src/main/java/com/alibaba/druid/wall/WallContext.java @@ -31,6 +31,7 @@ public class WallContext { private int unionWarnnings = 0; private int updateNoneConditionWarnnings = 0; private int deleteNoneConditionWarnnings = 0; + private int likeNumberWarnnings = 0; public WallContext(String dbType){ this.dbType = dbType; @@ -141,6 +142,17 @@ public class WallContext { this.warnnings++; } + public int getLikeNumberWarnnings() { + return likeNumberWarnnings; + } + + public void incrementLikeNumberWarnnings() { + if (likeNumberWarnnings == 0) { + this.warnnings++; + } + likeNumberWarnnings++; + } + public int getUnionWarnnings() { return unionWarnnings; } diff --git a/src/main/java/com/alibaba/druid/wall/WallProvider.java b/src/main/java/com/alibaba/druid/wall/WallProvider.java index fede94a6da..71e1a254e0 100644 --- a/src/main/java/com/alibaba/druid/wall/WallProvider.java +++ b/src/main/java/com/alibaba/druid/wall/WallProvider.java @@ -476,6 +476,8 @@ public abstract class WallProvider { violations.add(new IllegalSQLObjectViolation(ErrorCode.NONE_CONDITION, "update none condition", sql)); } else 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)); } else { violations.add(new IllegalSQLObjectViolation(ErrorCode.COMPOUND, "multi-warnnings", sql)); } diff --git a/src/main/java/com/alibaba/druid/wall/spi/MySqlWallVisitor.java b/src/main/java/com/alibaba/druid/wall/spi/MySqlWallVisitor.java index 8bd4ce48a1..68d1be852f 100644 --- a/src/main/java/com/alibaba/druid/wall/spi/MySqlWallVisitor.java +++ b/src/main/java/com/alibaba/druid/wall/spi/MySqlWallVisitor.java @@ -206,7 +206,7 @@ public class MySqlWallVisitor extends MySqlASTVisitorAdapter implements WallVisi } if (!checkVar(x.getParent(), x.getName())) { - boolean isTop = WallVisitorUtils.isTopNoneFromSelect(x); + boolean isTop = WallVisitorUtils.isTopNoneFromSelect(this, x); if (!isTop) { violations.add(new IllegalSQLObjectViolation(ErrorCode.VARIANT_DENY, "variable not allow : " + x.getName(), toSQL(x))); @@ -255,7 +255,7 @@ public class MySqlWallVisitor extends MySqlASTVisitorAdapter implements WallVisi } if (varName.startsWith("@@") && !checkVar(x.getParent(), x.getName())) { - boolean isTop = WallVisitorUtils.isTopNoneFromSelect(x); + boolean isTop = WallVisitorUtils.isTopNoneFromSelect(this, x); if (!isTop) { violations.add(new IllegalSQLObjectViolation(ErrorCode.VARIANT_DENY, "variable not allow : " + x.getName(), toSQL(x))); diff --git a/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java b/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java index c74deaf083..65ad3b6e3e 100644 --- a/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java +++ b/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java @@ -236,9 +236,9 @@ public class WallVisitorUtils { addViolation(visitor, ErrorCode.INSERT_NOT_ALLOW, "delete not allow", x); return; } - + boolean hasUsing = false; - + if (x instanceof MySqlDeleteStatement) { hasUsing = ((MySqlDeleteStatement) x).getUsing() != null; } @@ -479,7 +479,7 @@ public class WallVisitorUtils { checkConditionForMultiTenant(visitor, x.getWhere(), x); } - public static Object getValue(SQLBinaryOpExpr x) { + public static Object getValue(WallVisitor visitor, SQLBinaryOpExpr x) { if (x.getLeft() instanceof SQLName && x.getRight() instanceof SQLName) { if (x.getLeft().toString().equalsIgnoreCase(x.getRight().toString())) { if (x.getOperator() == SQLBinaryOperator.Equality) { @@ -523,7 +523,7 @@ public class WallVisitorUtils { boolean allFalse = true; for (int i = groupList.size() - 1; i >= 0; --i) { - Object result = getValue(groupList.get(i)); + Object result = getValue(visitor, groupList.get(i)); if (Boolean.TRUE == result) { final WallConditionContext wallContext = WallVisitorUtils.getWallConditionContext(); if (wallContext != null) { @@ -546,8 +546,17 @@ public class WallVisitorUtils { SQLExpr left = x.getLeft(); SQLExpr right = x.getRight(); - Object leftResult = getValue(left); - Object rightResult = getValue(right); + Object leftResult = getValue(visitor, left); + Object rightResult = getValue(visitor, right); + + if (x.getOperator() == SQLBinaryOperator.Like || x.getOperator() == SQLBinaryOperator.NotLike) { + WallContext context = WallContext.current(); + if (context != null) { + if (rightResult instanceof Number || leftResult instanceof Number) { + context.incrementLikeNumberWarnnings(); + } + } + } if (x.getOperator() == SQLBinaryOperator.BooleanAnd) { if (Boolean.FALSE == leftResult || Boolean.FALSE == rightResult) { @@ -659,7 +668,7 @@ public class WallVisitorUtils { final WallConditionContext old = wallConditionContextLocal.get(); try { wallConditionContextLocal.set(new WallConditionContext()); - final Object value = getValue(x); + final Object value = getValue(visitor, x); final WallConditionContext current = wallConditionContextLocal.get(); WallContext context = WallContext.current(); @@ -692,8 +701,12 @@ public class WallVisitorUtils { } public static Object getValue(SQLExpr x) { + return getValue(null, x); + } + + public static Object getValue(WallVisitor visitor, SQLExpr x) { if (x instanceof SQLBinaryOpExpr) { - return getValue((SQLBinaryOpExpr) x); + return getValue(visitor, (SQLBinaryOpExpr) x); } if (x instanceof MySqlBooleanExpr) { @@ -713,31 +726,31 @@ public class WallVisitorUtils { } if (x instanceof SQLNotExpr) { - Object result = getValue(((SQLNotExpr) x).getExpr()); + Object result = getValue(visitor, ((SQLNotExpr) x).getExpr()); if (result instanceof Boolean) { return !((Boolean) result).booleanValue(); } } if (x instanceof SQLQueryExpr) { - if (isSimpleCountTableSource(((SQLQueryExpr) x).getSubQuery())) { + if (isSimpleCountTableSource(visitor, ((SQLQueryExpr) x).getSubQuery())) { return Integer.valueOf(1); } } if (x instanceof SQLMethodInvokeExpr) { - return getValue((SQLMethodInvokeExpr) x); + return getValue(visitor, (SQLMethodInvokeExpr) x); } return null; } - public static Object getValue(SQLMethodInvokeExpr x) { + public static Object getValue(WallVisitor visitor, SQLMethodInvokeExpr x) { String methodName = x.getMethodName(); if ("len".equalsIgnoreCase(methodName) || "length".equalsIgnoreCase(methodName)) { Object firstValue = null; if (x.getParameters().size() > 0) { - firstValue = (getValue(x.getParameters().get(0))); + firstValue = (getValue(visitor, x.getParameters().get(0))); } if (firstValue instanceof String) { @@ -747,20 +760,20 @@ public class WallVisitorUtils { if ("if".equalsIgnoreCase(methodName) && x.getParameters().size() == 3) { SQLExpr first = x.getParameters().get(0); - Object firstResult = getValue(first); + Object firstResult = getValue(visitor, first); if (Boolean.TRUE == firstResult) { - return getValue(x.getParameters().get(1)); + return getValue(visitor, x.getParameters().get(1)); } if (Boolean.FALSE == firstResult) { - getValue(x.getParameters().get(2)); + getValue(visitor, x.getParameters().get(2)); } } if ("chr".equalsIgnoreCase(methodName) && x.getParameters().size() == 1) { SQLExpr first = x.getParameters().get(0); - Object firstResult = getValue(first); + Object firstResult = getValue(visitor, first); if (firstResult instanceof Number) { int intValue = ((Number) firstResult).intValue(); char ch = (char) intValue; @@ -772,7 +785,7 @@ public class WallVisitorUtils { if ("concat".equalsIgnoreCase(methodName)) { StringBuffer buf = new StringBuffer(); for (SQLExpr expr : x.getParameters()) { - Object value = getValue(expr); + Object value = getValue(visitor, expr); if (value == null) { return null; } @@ -785,17 +798,17 @@ public class WallVisitorUtils { return null; } - public static boolean isSimpleCountTableSource(SQLTableSource tableSource) { + public static boolean isSimpleCountTableSource(WallVisitor visitor, SQLTableSource tableSource) { if (!(tableSource instanceof SQLSubqueryTableSource)) { return false; } SQLSubqueryTableSource subQuery = (SQLSubqueryTableSource) tableSource; - return isSimpleCountTableSource(subQuery.getSelect()); + return isSimpleCountTableSource(visitor, subQuery.getSelect()); } - public static boolean isSimpleCountTableSource(SQLSelect select) { + public static boolean isSimpleCountTableSource(WallVisitor visitor, SQLSelect select) { SQLSelectQuery query = select.getQuery(); if (query instanceof SQLSelectQueryBlock) { @@ -806,7 +819,7 @@ public class WallVisitorUtils { if (queryBlock.getWhere() == null) { allawTrueWhere = true; } else { - Object whereValue = getValue(queryBlock.getWhere()); + Object whereValue = getValue(visitor, queryBlock.getWhere()); if (whereValue == Boolean.TRUE) { allawTrueWhere = true; } else if (whereValue == Boolean.FALSE) { @@ -846,7 +859,7 @@ public class WallVisitorUtils { } if (!visitor.getProvider().checkDenyFunction(methodName)) { - boolean isTopNoneFrom = isTopNoneFromSelect(x); + boolean isTopNoneFrom = isTopNoneFromSelect(visitor, x); if (isTopNoneFrom) { return; } @@ -898,7 +911,7 @@ public class WallVisitorUtils { return null; } - public static boolean isTopNoneFromSelect(SQLObject x) { + public static boolean isTopNoneFromSelect(WallVisitor visitor, SQLObject x) { if (!(x.getParent() instanceof SQLSelectItem)) { return false; } @@ -909,7 +922,7 @@ public class WallVisitorUtils { } SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) item.getParent(); - if (!queryBlockFromIsNull(queryBlock)) { + if (!queryBlockFromIsNull(visitor, queryBlock)) { return false; } @@ -1086,7 +1099,8 @@ public class WallVisitorUtils { return; } - if (WallVisitorUtils.queryBlockFromIsNull(x.getLeft()) || WallVisitorUtils.queryBlockFromIsNull(x.getRight())) { + if (WallVisitorUtils.queryBlockFromIsNull(visitor, x.getLeft()) + || WallVisitorUtils.queryBlockFromIsNull(visitor, x.getRight())) { boolean isTopUpdateStatement = false; SQLObject selectParent = x.getParent(); while (selectParent instanceof SQLUnionQuery // @@ -1103,7 +1117,7 @@ public class WallVisitorUtils { if (isTopUpdateStatement) { return; } - + WallContext context = WallContext.current(); if (context != null) { context.incrementUnionWarnnings(); @@ -1115,7 +1129,7 @@ public class WallVisitorUtils { } } - public static boolean queryBlockFromIsNull(SQLSelectQuery query) { + public static boolean queryBlockFromIsNull(WallVisitor visitor, SQLSelectQuery query) { if (query instanceof SQLSelectQueryBlock) { SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) query; SQLTableSource from = queryBlock.getFrom(); @@ -1141,7 +1155,7 @@ public class WallVisitorUtils { && queryBlock.getSelectList().get(0).getExpr() instanceof SQLAllColumnExpr) { if (from instanceof SQLSubqueryTableSource) { SQLSelectQuery subQuery = ((SQLSubqueryTableSource) from).getSelect().getQuery(); - if (queryBlockFromIsNull(subQuery)) { + if (queryBlockFromIsNull(visitor, subQuery)) { return true; } } @@ -1149,7 +1163,7 @@ public class WallVisitorUtils { boolean allIsConst = true; for (SQLSelectItem item : queryBlock.getSelectList()) { - if (getValue(item.getExpr()) == null) { + if (getValue(visitor, item.getExpr()) == null) { allIsConst = false; break; } diff --git a/src/main/java/com/alibaba/druid/wall/violation/ErrorCode.java b/src/main/java/com/alibaba/druid/wall/violation/ErrorCode.java index e16bc05600..2f16bafbe3 100644 --- a/src/main/java/com/alibaba/druid/wall/violation/ErrorCode.java +++ b/src/main/java/com/alibaba/druid/wall/violation/ErrorCode.java @@ -58,7 +58,8 @@ public interface ErrorCode { public final static int CONST_ARITHMETIC = 2101; public final static int XOR = 2102; public final static int BITWISE = 2103; - public final static int NONE_CONDITION = 1200; + public final static int NONE_CONDITION = 2104; + public final static int LIKE_NUMBER = 2105; public final static int NOT_PARAMETERIZED = 2200; public final static int MULTI_TENANT = 2201; diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest80.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest80.java new file mode 100644 index 0000000000..ad2e23d3f6 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest80.java @@ -0,0 +1,54 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.bvt.filter.wall; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.druid.wall.WallProvider; +import com.alibaba.druid.wall.spi.MySqlWallProvider; + +/** + * SQLServerWallTest + * + * @author RaymondXiu + * @version 1.0, 2012-3-18 + * @see + */ +public class MySqlWallTest80 extends TestCase { + + public void test_true() throws Exception { + WallProvider provider = new MySqlWallProvider(); + + Assert.assertTrue(provider.checkValid(// + "SELECT * FROM T WHERE FID = ? OR FID LIKE 1")); + + Assert.assertEquals(1, provider.getTableStats().size()); + } + + public void test_false() throws Exception { + WallProvider provider = new MySqlWallProvider(); + + provider.getConfig().setCommentAllow(true); + + Assert.assertFalse(provider.checkValid(// + "SELECT * FROM T WHERE FID = ? OR FID LIKE 1 --")); + + Assert.assertEquals(1, provider.getTableStats().size()); + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest81.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest81.java new file mode 100644 index 0000000000..1ef4564505 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest81.java @@ -0,0 +1,44 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.bvt.filter.wall; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.druid.wall.WallProvider; +import com.alibaba.druid.wall.spi.MySqlWallProvider; + +/** + * SQLServerWallTest + * + * @author RaymondXiu + * @version 1.0, 2012-3-18 + * @see + */ +public class MySqlWallTest81 extends TestCase { + + public void test_false() throws Exception { + WallProvider provider = new MySqlWallProvider(); + provider.getConfig().setStrictSyntaxCheck(false); + + Assert.assertFalse(provider.checkValid(// + "SELECT * FROM T WHERE FID = '\\'a' OR LEAST(2,1,9,8) = 1")); + + Assert.assertEquals(1, provider.getTableStats().size()); + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest82.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest82.java new file mode 100644 index 0000000000..770e0b748f --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest82.java @@ -0,0 +1,44 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.bvt.filter.wall; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.druid.wall.WallProvider; +import com.alibaba.druid.wall.spi.MySqlWallProvider; + +/** + * SQLServerWallTest + * + * @author RaymondXiu + * @version 1.0, 2012-3-18 + * @see + */ +public class MySqlWallTest82 extends TestCase { + + public void test_false() throws Exception { + WallProvider provider = new MySqlWallProvider(); + provider.getConfig().setStrictSyntaxCheck(false); + + Assert.assertFalse(provider.checkValid(// + "SELECT * FROM T WHERE FID = '\0a' OR LEAST(2,1,9,8) = 1")); + + Assert.assertEquals(1, provider.getTableStats().size()); + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest_like_1.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest_like_1.java index a21a2b418f..8321b10f27 100644 --- a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest_like_1.java +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest_like_1.java @@ -34,7 +34,7 @@ public class MySqlWallTest_like_1 extends TestCase { public void test_false() throws Exception { WallProvider provider = new MySqlWallProvider(); - Assert.assertFalse(provider.checkValid(// + Assert.assertTrue(provider.checkValid(// "SELECT * FROM T WHERE FID = ? OR FID LIKE 1")); Assert.assertEquals(1, provider.getTableStats().size()); diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/TenantSelectTest2.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/TenantSelectTest2.java index 5d04795fa5..475d251040 100644 --- a/src/test/java/com/alibaba/druid/bvt/filter/wall/TenantSelectTest2.java +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/TenantSelectTest2.java @@ -48,6 +48,6 @@ public class TenantSelectTest2 extends TestCase { "\nFROM orders" + // "\nWHERE tenant = 123" + // "\n\tAND (FID = ?" + - "\n\t\t\tOR FID = ?)", resultSql); + "\n\t\tOR FID = ?)", resultSql); } } diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/TenantSelectTest3.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/TenantSelectTest3.java index b303ec384a..412def124d 100644 --- a/src/test/java/com/alibaba/druid/bvt/filter/wall/TenantSelectTest3.java +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/TenantSelectTest3.java @@ -52,6 +52,6 @@ public class TenantSelectTest3 extends TestCase { "\n\t\tAND o.userid = u.id" + // "\nWHERE o.tenant = 123" + // "\n\tAND (FID = ?" + // - "\n\t\t\tOR FID = ?)", resultSql); + "\n\t\tOR FID = ?)", resultSql); } } From 60875af0e4553769b0581b65c50dab2b3845865d Mon Sep 17 00:00:00 2001 From: wenshao Date: Fri, 12 Apr 2013 15:39:37 +0800 Subject: [PATCH 3/4] add pool concurrent warnnings --- src/main/java/com/alibaba/druid/pool/DruidDataSource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/alibaba/druid/pool/DruidDataSource.java b/src/main/java/com/alibaba/druid/pool/DruidDataSource.java index 43562dd919..48705aaf53 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidDataSource.java +++ b/src/main/java/com/alibaba/druid/pool/DruidDataSource.java @@ -891,7 +891,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat } if (pooledConnection.getOwnerThread() != Thread.currentThread()) { - throw new SQLException("closed error, get/close not same thread"); + LOG.warn("get/close not same thread"); } final Connection physicalConnection = holder.getConnection(); From e2993be3f72ca4a6d89dac0d58652b5590b18451 Mon Sep 17 00:00:00 2001 From: wenshao Date: Fri, 12 Apr 2013 15:39:54 +0800 Subject: [PATCH 4/4] improve wall filter --- .../druid/sql/dialect/mysql/parser/MySqlLexer.java | 7 ++++++- .../java/com/alibaba/druid/bvt/sql/cobar/HintsTest.java | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java index 60cecea063..9e97eeb670 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java @@ -67,6 +67,11 @@ public class MySqlLexer extends Lexer { throw new ParserException("illegal stat"); } + if (charAt(pos + 1) == '{') { + scanVariable(); + return; + } + Token lastToken = this.token; scanChar(); @@ -420,7 +425,7 @@ public class MySqlLexer extends Lexer { } if (isHint) { - stringVal = subString(mark + startHintSp, (bufPos - startHintSp) - 1); + stringVal = subString(mark + startHintSp, (bufPos - startHintSp) - 2); token = Token.HINT; } else { stringVal = subString(mark, bufPos); diff --git a/src/test/java/com/alibaba/druid/bvt/sql/cobar/HintsTest.java b/src/test/java/com/alibaba/druid/bvt/sql/cobar/HintsTest.java index 74918f8757..e2d290d35d 100644 --- a/src/test/java/com/alibaba/druid/bvt/sql/cobar/HintsTest.java +++ b/src/test/java/com/alibaba/druid/bvt/sql/cobar/HintsTest.java @@ -43,4 +43,13 @@ public class HintsTest extends TestCase { String output = SQLUtils.toMySqlString(stmt); Assert.assertEquals("SELECT /*! STRAIGHT_JOIN */ col1\nFROM table1, table2", output); } + + public void test_hints_none() throws Exception { + String sql = "SELECT /* STRAIGHT_JOIN */ col1 FROM table1,table2"; + MySqlStatementParser parser = new MySqlStatementParser(sql); + SQLStatement stmt = parser.parseStatementList().get(0); + parser.match(Token.EOF); + String output = SQLUtils.toMySqlString(stmt); + Assert.assertEquals("SELECT col1\nFROM table1, table2", output); + } }