diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest142.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest142.java new file mode 100644 index 0000000000..33eae0a13f --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest142.java @@ -0,0 +1,33 @@ +/* + * 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; + +public class MySqlWallTest142 extends TestCase { + + public void test_false() throws Exception { + WallProvider provider = new MySqlWallProvider(); + + String sql = "SELECT * FROM `my_crons` WHERE 1 OR nextrun = '0' "; + Assert.assertTrue(provider.checkValid(sql)); + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest143.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest143.java new file mode 100644 index 0000000000..4e53956a64 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest143.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; + +public class MySqlWallTest143 extends TestCase { + + public void test_false() throws Exception { + WallProvider provider = new MySqlWallProvider(); + + String sql = "SELECT" // + + " `Extent1`.`ID`, " // + + " `Extent1`.`State`, " // + + " `Extent1`.`CreateTime`, " // + + " `Extent1`.`UpdateTime`, " // + + " `Extent1`.`OpeningBank`, " // + + " `Extent1`.`BankAccount`, " // + + " `Extent1`.`BankAccountName`, " // + + " `Extent1`.`Zone`, " // + + " `Extent1`.`AccountantMobile`, " // + + " `Extent1`.`IsPublic`" // + + " FROM `paybank` AS `Extent1`" // + + " WHERE (`Extent1`.`State` > -1)" // + + " AND ((`Extent1`.`Zone`) = (CASE WHEN (1 IS NULL) THEN (1) ELSE (1) END))"; + Assert.assertTrue(provider.checkValid(sql)); + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_11.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_11.java new file mode 100644 index 0000000000..bfd636ec67 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_11.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.SQLServerWallProvider; + +/** + * SQLServerWallTest + * + * @see + */ +public class SQLServerWallTest_11 extends TestCase { + + public void test_true() throws Exception { + WallProvider provider = new SQLServerWallProvider(); + provider.getConfig().setCommentAllow(true); + + String sql = "SELECT KL_ArticleContent,KL_ArticleTitle " // + + "FROM dbo.KL_Article " // + + "WHERE KL_ArticleId =-4731 "// + + "UNION ALL "// + + "SELECT (SELECT TOP 1 CHAR(58)+CHAR(108)+CHAR(107)+CHAR(103)+CHAR(58)+ISNULL(CAST(name AS NVARCHAR(4000)),CHAR(32))+CHAR(58)+CHAR(109)+CHAR(122)+CHAR(104)+CHAR(58) FROM sys.sql_logins WHERE ISNULL(name,CHAR(32)) NOT IN (SELECT TOP 0 ISNULL(name,CHAR(32)) FROM sys.sql_logins ORDER BY 1) ORDER BY 1),NULL-- "; + + Assert.assertFalse(provider.checkValid(sql)); + + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_12.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_12.java new file mode 100644 index 0000000000..5ccc061bdd --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_12.java @@ -0,0 +1,42 @@ +/* + * 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.SQLServerWallProvider; + +/** + * SQLServerWallTest + * + * @see + */ +public class SQLServerWallTest_12 extends TestCase { + + public void test_true() throws Exception { + WallProvider provider = new SQLServerWallProvider(); + provider.getConfig().setCommentAllow(true); + + String sql = "EXEC master..xp_msver"; + + Assert.assertTrue(provider.checkValid(sql)); + + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/oracle/OracleSelectTest51.java b/src/test/java/com/alibaba/druid/bvt/sql/oracle/OracleSelectTest51.java new file mode 100644 index 0000000000..5ba24cca04 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/oracle/OracleSelectTest51.java @@ -0,0 +1,64 @@ +/* + * 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.sql.oracle; + +import java.util.List; + +import org.junit.Assert; + +import com.alibaba.druid.sql.OracleTest; +import com.alibaba.druid.sql.ast.SQLStatement; +import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser; +import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor; +import com.alibaba.druid.sql.test.TestUtils; + +public class OracleSelectTest51 extends OracleTest { + + public void test_0() throws Exception { + String sql = // + "select TRIM(TRAILING 'M' FROM RTRIM(' testM')) from dual;"; // + + OracleStatementParser parser = new OracleStatementParser(sql); + List statementList = parser.parseStatementList(); + SQLStatement stmt = statementList.get(0); + print(statementList); + + Assert.assertEquals(1, statementList.size()); + + OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor(); + stmt.accept(visitor); + + System.out.println("Tables : " + visitor.getTables()); + System.out.println("fields : " + visitor.getColumns()); + System.out.println("coditions : " + visitor.getConditions()); + System.out.println("relationships : " + visitor.getRelationships()); + System.out.println("orderBy : " + visitor.getOrderByColumns()); + + Assert.assertEquals(0, visitor.getTables().size()); + + Assert.assertEquals(0, visitor.getColumns().size()); + + String text = TestUtils.outputOracle(stmt); + + Assert.assertEquals("SELECT TRIM(TRAILING 'M' FROM RTRIM(' testM'))" // + + "\nFROM dual;"// + + "\n", text); + + // Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh"))); + + // Assert.assertTrue(visitor.getOrderByColumns().contains(new TableStat.Column("employees", "last_name"))); + } +}