diff --git a/pom.xml b/pom.xml index bdf263a450..b3adc37460 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.alibaba druid - 0.2.17 + 0.2.18-SNAPSHOT jar druid diff --git a/src/main/java/com/alibaba/druid/pool/DruidDataSource.java b/src/main/java/com/alibaba/druid/pool/DruidDataSource.java index d0c64df731..7949c51e0c 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidDataSource.java +++ b/src/main/java/com/alibaba/druid/pool/DruidDataSource.java @@ -405,7 +405,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat filter.init(this); } - if (this.dbType == JdbcConstants.MYSQL) { + if (JdbcConstants.MYSQL.equals(this.dbType) || // + JdbcConstants.MARIADB.equals(this.dbType)) { boolean cacheServerConfigurationSet = false; if (this.connectProperties.containsKey("cacheServerConfiguration")) { cacheServerConfigurationSet = true; @@ -544,7 +545,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat createConnectionThread.start(); } - /** * load filters from SPI ServiceLoader * diff --git a/src/main/java/com/alibaba/druid/pool/vendor/OracleExceptionSorter.java b/src/main/java/com/alibaba/druid/pool/vendor/OracleExceptionSorter.java index 77db0ccf10..43b9afede9 100644 --- a/src/main/java/com/alibaba/druid/pool/vendor/OracleExceptionSorter.java +++ b/src/main/java/com/alibaba/druid/pool/vendor/OracleExceptionSorter.java @@ -17,41 +17,112 @@ package com.alibaba.druid.pool.vendor; import java.io.Serializable; import java.sql.SQLException; +import java.util.HashSet; +import java.util.Set; import com.alibaba.druid.pool.ExceptionSorter; +import com.alibaba.druid.support.logging.Log; +import com.alibaba.druid.support.logging.LogFactory; /** * Implementation of ExceptionSorter for Oracle. */ public class OracleExceptionSorter implements ExceptionSorter, Serializable { + private final static Log LOG = LogFactory.getLog(OracleExceptionSorter.class); + private static final long serialVersionUID = -9146226891418913174L; + private Set fatalErrorCodes = new HashSet(); + public OracleExceptionSorter(){ + String property = System.getProperty("druid.oracle.fatalErrorCodes"); + if (property != null) { + String[] items = property.split("\\,"); + for (String item : items) { + if (item != null && item.length() > 0) { + try { + int code = Integer.parseInt(item); + fatalErrorCodes.add(code); + } catch (NumberFormatException e) { + LOG.error("parse druid.oracle.fatalErrorCodes error", e); + } + } + } + } + } + + public Set getFatalErrorCodes() { + return fatalErrorCodes; + } + + public void setFatalErrorCodes(Set fatalErrorCodes) { + this.fatalErrorCodes = fatalErrorCodes; } public boolean isExceptionFatal(final SQLException e) { final int error_code = Math.abs(e.getErrorCode()); // I can't remember if the errors are negative or positive. - if ((error_code == 28) // session has been killed - || (error_code == 600) // Internal oracle error - || (error_code == 1012) // not logged on - || (error_code == 1014) // Oracle shutdown in progress - || (error_code == 1033) // Oracle initialization or shutdown in progress - || (error_code == 1034) // Oracle not available - || (error_code == 1035) // ORACLE only available to users with RESTRICTED SESSION privilege - || (error_code == 1089) // immediate shutdown in progress - no operations are permitted - || (error_code == 1090) // shutdown in progress - connection is not permitted - || (error_code == 1092) // ORACLE instance terminated. Disconnection forced - || (error_code == 1094) // ALTER DATABASE CLOSE in progress. Connections not permitted - || (error_code == 2396) // exceeded maximum idle time, please connect again - || (error_code == 3106) // fatal two-task communication protocol error - || (error_code == 3111) // break received on communication channel - || (error_code == 3113) // end-of-file on communication channel - || (error_code == 3114) // not connected to ORACLE - || (error_code >= 12100 && error_code <= 12299) // TNS issues - ) { - return true; + switch (error_code) { + case 28: // your session has been killed + case 600: // Internal oracle error + case 1012: // not logged on + case 1014: // Oracle shutdown in progress + case 1033: // Oracle initialization or shutdown in progress + case 1034: // Oracle not available + case 1035: // ORACLE only available to users with RESTRICTED SESSION privilege + case 1089: // immediate shutdown in progress - no operations are permitted + case 1090: // shutdown in progress - connection is not permitted + case 1092: // ORACLE instance terminated. Disconnection forced + case 1094: // ALTER DATABASE CLOSE in progress. Connections not permitted + case 2396: // exceeded maximum idle time, please connect again + case 3106: // fatal two-task communication protocol error + case 3111: // break received on communication channel + case 3113: // end-of-file on communication channel + case 3114: // not connected to ORACLE + + case 3134: // Connections to this server version are no longer supported. + case 3135: // connection lost contact + case 3136: // inbound connection timed out + case 3138: // Connection terminated due to security policy violation + case 3142: // Connection was lost for the specified session and serial number. This is either due to session + // being killed or network problems. + case 3143: // Connection was lost for the specified process ID and thread ID. This is either due to session + // being killed or network problems. + case 3144: // Connection was lost for the specified process ID. This is either due to session being killed + // or network problems. + case 3145: // I/O streaming direction error + case 3149: // Invalid Oracle error code, Cause: An invalid Oracle error code was received by the server. + + case 6801: // TLI Driver: listen for SPX server reconnect failed + case 6802: // TLI Driver: could not open the /etc/netware/yellowpages file + case 6805: // TLI Driver: could not send datagram SAP packet for SPX + case 9918: // Unable to get user privileges from SQL*Net + case 9920: // Unable to get sensitivity label from connection + case 9921: // Unable to get information label from connection + + // TTC(Two-Task Common) ERROR CODE + case 17001: // Internal Error + case 17002: // Io exception + case 17008: // Closed Connection + case 17024: // No data read + case 17089: // internal error + case 17409: // invalid buffer length + case 17410: // No more data to read from socket + case 17416: // FATAl + + case 25407: // connection terminated + case 25408: // can not safely replay call + case 25409: // failover happened during the network operation,cannot continue + case 25425: // connection lost during rollback + case 29276: // transfer timeout + case 30676: // socket read or write failed + return true; + default: + if (error_code >= 12100 && error_code <= 12299) { // TNS issues + return true; + } + break; } final String error_text = (e.getMessage()).toUpperCase(); @@ -59,12 +130,18 @@ public class OracleExceptionSorter implements ExceptionSorter, Serializable { // Exclude oracle user defined error codes (20000 through 20999) from consideration when looking for // certain strings. - if ((error_code < 20000 || error_code >= 21000) - && ((error_text.indexOf("SOCKET") > -1) // for control socket error - || (error_text.indexOf("CONNECTION HAS ALREADY BEEN CLOSED") > -1) || (error_text.indexOf("BROKEN PIPE") > -1))) { - return true; + if ((error_code < 20000 || error_code >= 21000)) { + if ((error_text.indexOf("SOCKET") > -1) // for control socket error + || (error_text.indexOf("套接字") > -1) // for control socket error + || (error_text.indexOf("CONNECTION HAS ALREADY BEEN CLOSED") > -1) // + || (error_text.indexOf("BROKEN PIPE") > -1) // + || (error_text.indexOf("管道已结束") > -1) // + ) { + return true; + } + } - return false; + return fatalErrorCodes.contains(error_code); } } diff --git a/src/main/java/com/alibaba/druid/sql/PagerUtils.java b/src/main/java/com/alibaba/druid/sql/PagerUtils.java index a1dfa98f6d..71dbba0e37 100644 --- a/src/main/java/com/alibaba/druid/sql/PagerUtils.java +++ b/src/main/java/com/alibaba/druid/sql/PagerUtils.java @@ -94,7 +94,9 @@ public class PagerUtils { private static String limitQueryBlock(SQLSelect select, String dbType, int offset, int count) { SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) select.getQuery(); - if (JdbcConstants.MYSQL.equals(dbType)) { + if (JdbcConstants.MYSQL.equals(dbType) || // + JdbcConstants.MARIADB.equals(dbType) || // + JdbcConstants.H2.equals(dbType)) { return limitMySqlQueryBlock((MySqlSelectQueryBlock) queryBlock, dbType, offset, count); } @@ -205,6 +207,14 @@ public class PagerUtils { return new MySqlSelectQueryBlock(); } + if (JdbcConstants.MARIADB.equals(dbType)) { + return new MySqlSelectQueryBlock(); + } + + if (JdbcConstants.H2.equals(dbType)) { + return new MySqlSelectQueryBlock(); + } + if (JdbcConstants.ORACLE.equals(dbType)) { return new OracleSelectQueryBlock(); } diff --git a/src/main/java/com/alibaba/druid/sql/SQLUtils.java b/src/main/java/com/alibaba/druid/sql/SQLUtils.java index 664118193e..fd6c854a76 100644 --- a/src/main/java/com/alibaba/druid/sql/SQLUtils.java +++ b/src/main/java/com/alibaba/druid/sql/SQLUtils.java @@ -45,11 +45,9 @@ public class SQLUtils { private final static Log LOG = LogFactory.getLog(SQLUtils.class); public static String toSQLString(SQLObject sqlObject, String dbType) { - if (JdbcUtils.MYSQL.equals(dbType)) { - return toMySqlString(sqlObject); - } - - if (JdbcUtils.H2.equals(dbType)) { + if (JdbcUtils.MYSQL.equals(dbType) || // + JdbcUtils.MARIADB.equals(dbType) || // + JdbcUtils.H2.equals(dbType)) { return toMySqlString(sqlObject); } @@ -139,7 +137,7 @@ public class SQLUtils { public static SQLExpr toSQLExpr(String sql) { return toSQLExpr(sql, null); } - + public static String format(String sql, String dbType) { return format(sql, dbType, null); } @@ -158,7 +156,7 @@ public class SQLUtils { public static String toSQLString(List statementList, String dbType) { return toSQLString(statementList, dbType, null); } - + public static String toSQLString(List statementList, String dbType, List parameters) { StringBuilder out = new StringBuilder(); SQLASTOutputVisitor visitor = createFormatOutputVisitor(out, statementList, dbType); @@ -183,7 +181,9 @@ public class SQLUtils { } } - if (JdbcUtils.MYSQL.equals(dbType)) { + if (JdbcUtils.MYSQL.equals(dbType) || // + JdbcUtils.MARIADB.equals(dbType) || // + JdbcUtils.H2.equals(dbType)) { return new MySqlOutputVisitor(out); } @@ -194,15 +194,11 @@ public class SQLUtils { if (JdbcUtils.SQL_SERVER.equals(dbType)) { return new SQLServerOutputVisitor(out); } - + if (JdbcUtils.JTDS.equals(dbType)) { return new SQLServerOutputVisitor(out); } - if (JdbcUtils.H2.equals(dbType)) { - return new MySqlOutputVisitor(out); - } - return new SQLASTOutputVisitor(out); } @@ -215,7 +211,9 @@ public class SQLUtils { } } - if (JdbcUtils.MYSQL.equals(dbType)) { + if (JdbcUtils.MYSQL.equals(dbType) || // + JdbcUtils.MARIADB.equals(dbType) || // + JdbcUtils.H2.equals(dbType)) { return new MySqlSchemaStatVisitor(); } @@ -226,15 +224,11 @@ public class SQLUtils { if (JdbcUtils.SQL_SERVER.equals(dbType)) { return new SQLServerSchemaStatVisitor(); } - + if (JdbcUtils.JTDS.equals(dbType)) { return new SQLServerSchemaStatVisitor(); } - if (JdbcUtils.H2.equals(dbType)) { - return new MySqlSchemaStatVisitor(); - } - return new SchemaStatVisitor(); } diff --git a/src/main/java/com/alibaba/druid/sql/parser/SQLParserUtils.java b/src/main/java/com/alibaba/druid/sql/parser/SQLParserUtils.java index b8c04b40a3..6a3c642b84 100644 --- a/src/main/java/com/alibaba/druid/sql/parser/SQLParserUtils.java +++ b/src/main/java/com/alibaba/druid/sql/parser/SQLParserUtils.java @@ -36,6 +36,10 @@ public class SQLParserUtils { return new MySqlStatementParser(sql); } + if (JdbcUtils.MARIADB.equals(dbType)) { + return new MySqlStatementParser(sql); + } + if (JdbcUtils.POSTGRESQL.equals(dbType)) { return new PGSQLStatementParser(sql); } @@ -43,7 +47,7 @@ public class SQLParserUtils { if (JdbcUtils.SQL_SERVER.equals(dbType)) { return new SQLServerStatementParser(sql); } - + if (JdbcUtils.JTDS.equals(dbType)) { return new SQLServerStatementParser(sql); } @@ -60,11 +64,9 @@ public class SQLParserUtils { return new OracleExprParser(sql); } - if (JdbcUtils.H2.equals(dbType)) { - return new MySqlExprParser(sql); - } - - if (JdbcUtils.MYSQL.equals(dbType)) { + if (JdbcUtils.MYSQL.equals(dbType) || // + JdbcUtils.MARIADB.equals(dbType) || // + JdbcUtils.H2.equals(dbType)) { return new MySqlExprParser(sql); } @@ -75,7 +77,7 @@ public class SQLParserUtils { if (JdbcUtils.SQL_SERVER.equals(dbType)) { return new SQLServerExprParser(sql); } - + if (JdbcUtils.JTDS.equals(dbType)) { return new SQLServerExprParser(sql); } diff --git a/src/main/java/com/alibaba/druid/sql/visitor/ParameterizedOutputVisitorUtils.java b/src/main/java/com/alibaba/druid/sql/visitor/ParameterizedOutputVisitorUtils.java index 88cf78eadb..cae49c8f4f 100644 --- a/src/main/java/com/alibaba/druid/sql/visitor/ParameterizedOutputVisitorUtils.java +++ b/src/main/java/com/alibaba/druid/sql/visitor/ParameterizedOutputVisitorUtils.java @@ -56,6 +56,10 @@ public class ParameterizedOutputVisitorUtils { if (JdbcUtils.MYSQL.equals(dbType)) { return new MySqlParameterizedOutputVisitor(out); } + + if (JdbcUtils.MARIADB.equals(dbType)) { + return new MySqlParameterizedOutputVisitor(out); + } if (JdbcUtils.H2.equals(dbType)) { return new MySqlParameterizedOutputVisitor(out); 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 31a86b2c52..3984f818f8 100644 --- a/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java +++ b/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java @@ -139,6 +139,10 @@ public class SQLEvalVisitorUtils { if (JdbcUtils.MYSQL.equals(dbType)) { return new MySqlEvalVisitorImpl(); } + + if (JdbcUtils.MARIADB.equals(dbType)) { + return new MySqlEvalVisitorImpl(); + } if (JdbcUtils.H2.equals(dbType)) { return new MySqlEvalVisitorImpl(); diff --git a/src/main/java/com/alibaba/druid/support/logging/LogFactory.java b/src/main/java/com/alibaba/druid/support/logging/LogFactory.java index 7b65dbc8ff..18b536144b 100644 --- a/src/main/java/com/alibaba/druid/support/logging/LogFactory.java +++ b/src/main/java/com/alibaba/druid/support/logging/LogFactory.java @@ -58,7 +58,7 @@ public class LogFactory { logConstructor = null; } } catch (Throwable t) { - t.printStackTrace(); + // skip } } diff --git a/src/main/java/com/alibaba/druid/util/JdbcConstants.java b/src/main/java/com/alibaba/druid/util/JdbcConstants.java index 20f0c4c066..8ae1f4625f 100644 --- a/src/main/java/com/alibaba/druid/util/JdbcConstants.java +++ b/src/main/java/com/alibaba/druid/util/JdbcConstants.java @@ -34,16 +34,17 @@ public interface JdbcConstants { public static final String SQL_SERVER = "sqlserver"; public static final String ORACLE = "oracle"; - public static final String ALI_ORACLE = "AliOracle"; - public static final String ORACLE_DRIVER = "oracle.jdbc.driver.OracleDriver"; + public static final String ALI_ORACLE = "AliOracle"; public static final String ALI_ORACLE_DRIVER = "com.alibaba.jdbc.AlibabaDriver"; public static final String MYSQL = "mysql"; - public static final String MYSQL_DRIVER = "com.mysql.jdbc.Driver"; + public static final String MARIADB = "mariadb"; + public static final String MARIADB_DRIVER = "org.mariadb.jdbc.Driver"; + public static final String DERBY = "derby"; public static final String HBASE = "hbase"; diff --git a/src/main/java/com/alibaba/druid/util/JdbcUtils.java b/src/main/java/com/alibaba/druid/util/JdbcUtils.java index e8c9ecbea7..ac0159e66d 100644 --- a/src/main/java/com/alibaba/druid/util/JdbcUtils.java +++ b/src/main/java/com/alibaba/druid/util/JdbcUtils.java @@ -348,6 +348,8 @@ public final class JdbcUtils implements JdbcConstants { return "org.apache.derby.jdbc.EmbeddedDriver"; } else if (rawUrl.startsWith("jdbc:mysql:")) { return MYSQL_DRIVER; + } else if (rawUrl.startsWith("jdbc:mariadb:")) { + return MARIADB_DRIVER; } else if (rawUrl.startsWith("jdbc:oracle:")) { return ORACLE_DRIVER; } else if (rawUrl.startsWith("jdbc:alibaba:oracle:")) { @@ -414,6 +416,8 @@ public final class JdbcUtils implements JdbcConstants { return DERBY; } else if (rawUrl.startsWith("jdbc:mysql:")) { return MYSQL; + } else if (rawUrl.startsWith("jdbc:mariadb:")) { + return MARIADB; } else if (rawUrl.startsWith("jdbc:oracle:")) { return ORACLE; } else if (rawUrl.startsWith("jdbc:alibaba:oracle:")) { diff --git a/src/main/java/com/alibaba/druid/wall/WallConfig.java b/src/main/java/com/alibaba/druid/wall/WallConfig.java index 8aa8883df9..b0d0bc3a3f 100644 --- a/src/main/java/com/alibaba/druid/wall/WallConfig.java +++ b/src/main/java/com/alibaba/druid/wall/WallConfig.java @@ -31,7 +31,7 @@ public class WallConfig implements WallConfigMBean { private boolean selectIntoAllow = true; private boolean selectIntoOutfileAllow = false; private boolean selectWhereAlwayTrueCheck = true; - private boolean selectHavingAlwayTrueCheck = true; + private boolean selectHavingAlwayTrueCheck = false; private boolean selectUnionCheck = true; private boolean createTableAllow = true; private boolean dropTableAllow = true; diff --git a/src/main/java/com/alibaba/druid/wall/WallFilter.java b/src/main/java/com/alibaba/druid/wall/WallFilter.java index 9fd1c2ecb1..91070bfd5d 100644 --- a/src/main/java/com/alibaba/druid/wall/WallFilter.java +++ b/src/main/java/com/alibaba/druid/wall/WallFilter.java @@ -72,7 +72,9 @@ public class WallFilter extends FilterAdapter implements WallFilterMBean { dbType = JdbcUtils.getDbType(dataSource.getUrl(), null); } - if (JdbcUtils.MYSQL.equals(dbType) || JdbcUtils.H2.equals(dbType)) { + if (JdbcUtils.MYSQL.equals(dbType) || // + JdbcUtils.MARIADB.equals(dbType) || // + JdbcUtils.H2.equals(dbType)) { if (config == null) { config = new WallConfig(MySqlWallProvider.DEFAULT_CONFIG_DIR); } @@ -541,7 +543,7 @@ public class WallFilter extends FilterAdapter implements WallFilterMBean { if (sqlStat == null) { return; } - + Map sqlTableStats = sqlStat.getTableStats(); if (sqlTableStats == null) { return; 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 68d1be852f..1aa506e897 100644 --- a/src/main/java/com/alibaba/druid/wall/spi/MySqlWallVisitor.java +++ b/src/main/java/com/alibaba/druid/wall/spi/MySqlWallVisitor.java @@ -63,6 +63,7 @@ import com.alibaba.druid.wall.WallContext; import com.alibaba.druid.wall.WallProvider; import com.alibaba.druid.wall.WallSqlTableStat; import com.alibaba.druid.wall.WallVisitor; +import com.alibaba.druid.wall.spi.WallVisitorUtils.WallConditionContext; import com.alibaba.druid.wall.violation.ErrorCode; import com.alibaba.druid.wall.violation.IllegalSQLObjectViolation; @@ -255,8 +256,8 @@ public class MySqlWallVisitor extends MySqlASTVisitorAdapter implements WallVisi } if (varName.startsWith("@@") && !checkVar(x.getParent(), x.getName())) { - boolean isTop = WallVisitorUtils.isTopNoneFromSelect(this, x); - if (!isTop) { + boolean noneCondition = WallVisitorUtils.getWallConditionContext() == null; + if (!noneCondition) { 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 3b2169d9c1..6ae42251d6 100644 --- a/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java +++ b/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java @@ -678,7 +678,9 @@ public class WallVisitorUtils { WallContext context = WallContext.current(); if (context != null) { if (current.hasPartAlwayTrue() || Boolean.TRUE == value) { - context.incrementWarnnings(); + if (!isFirst(x)) { + context.incrementWarnnings(); + } } } diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest89.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest89.java new file mode 100644 index 0000000000..e0ce6035b6 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest89.java @@ -0,0 +1,46 @@ +/* + * 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 MySqlWallTest89 extends TestCase { + + public void test_true() throws Exception { + WallProvider provider = new MySqlWallProvider(); + + provider.getConfig().setSelectHavingAlwayTrueCheck(true); + + Assert.assertTrue(provider.checkValid(// + "select login('', '', 'guest', '47ea3937793101011caaa5dd88d3bcae926526624796b8a26a9615e8d3bea6b4', 'iPad3,4', 'unknown'), '', (select max(num) from accounts) + @@auto_increment_increment")); + + Assert.assertEquals(1, provider.getTableStats().size()); + Assert.assertTrue(provider.getTableStats().containsKey("accounts")); + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest90.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest90.java new file mode 100644 index 0000000000..81c802fccb --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest90.java @@ -0,0 +1,48 @@ +/* + * 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 MySqlWallTest90 extends TestCase { + + public void test_true() throws Exception { + WallProvider provider = new MySqlWallProvider(); + + provider.getConfig().setSelectHavingAlwayTrueCheck(true); + + Assert.assertTrue(provider.checkValid(// + "select * from (select t10006_men_xing_jia_ge_fen_lei.bian_hao as \"bian_hao\", " + // + " t10006_men_xing_jia_ge_fen_lei.ming_cheng as \"ming_cheng\" " + // + "from t10006_men_xing_jia_ge_fen_lei where 1=1 ) as tables where 1=1 order by tables.bian_hao")); + + Assert.assertEquals(1, provider.getTableStats().size()); + Assert.assertTrue(provider.getTableStats().containsKey("t10006_men_xing_jia_ge_fen_lei")); + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/pool/exception/OracleExceptionSorter_userDefined.java b/src/test/java/com/alibaba/druid/bvt/pool/exception/OracleExceptionSorter_userDefined.java new file mode 100644 index 0000000000..3ec9212e32 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/pool/exception/OracleExceptionSorter_userDefined.java @@ -0,0 +1,34 @@ +package com.alibaba.druid.bvt.pool.exception; + +import java.sql.SQLException; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.druid.pool.vendor.OracleExceptionSorter; + +public class OracleExceptionSorter_userDefined extends TestCase { + + protected void setUp() throws Exception { + System.setProperty("druid.oracle.fatalErrorCodes", "1,2,3,a,"); + } + + protected void tearDown() throws Exception { + System.clearProperty("druid.oracle.fatalErrorCodes"); + } + + public void test_userDefinedErrorCodes() throws Exception { + OracleExceptionSorter sorter = new OracleExceptionSorter(); + Assert.assertEquals(3, sorter.getFatalErrorCodes().size()); + Assert.assertTrue(sorter.getFatalErrorCodes().contains(1)); + Assert.assertTrue(sorter.getFatalErrorCodes().contains(2)); + Assert.assertTrue(sorter.getFatalErrorCodes().contains(3)); + + Assert.assertTrue(sorter.isExceptionFatal(new SQLException("xx", "xx", 1))); + Assert.assertTrue(sorter.isExceptionFatal(new SQLException("xx", "xx", 2))); + Assert.assertTrue(sorter.isExceptionFatal(new SQLException("xx", "xx", 3))); + Assert.assertFalse(sorter.isExceptionFatal(new SQLException("xx", "xx", 4))); + Assert.assertTrue(sorter.isExceptionFatal(new SQLException("xx", "xx", 28))); + } +}