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:
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 MySqlWallTest139 extends TestCase {
|
||||
|
||||
public void test_false() throws Exception {
|
||||
WallProvider provider = new MySqlWallProvider();
|
||||
|
||||
String sql = "select count(1) as total "//
|
||||
+ " from (" //
|
||||
+ " select '' buyer_nick from dual " //
|
||||
+ " where 1=0 "//
|
||||
+ " union " //
|
||||
+ " select distinct buyer_nick "//
|
||||
+ " from sys_info.orders "//
|
||||
+ " where 1=1 and receiver_district in ('平谷区')" //
|
||||
+ ") a " //
|
||||
+ "inner join (" //
|
||||
+ " select buyer_nick from ("//
|
||||
+ " select distinct buyer_nick "//
|
||||
+ " from sys_info.orders " //
|
||||
+ " where 1=1 and created > '2013-07-28' "//
|
||||
+ " ) recent_days " //
|
||||
+ "inner join (" //
|
||||
+ " select distinct buyer_nick " //
|
||||
+ " from sys_info.orders " //
|
||||
+ " where 1=1 and seller_nick in ('创维官方旗舰店') " //
|
||||
+ " ) seller_nick using(buyer_nick) "//
|
||||
+ ") b using(buyer_nick)";
|
||||
Assert.assertTrue(provider.checkValid(sql));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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_10 extends TestCase {
|
||||
|
||||
public void test_true() throws Exception {
|
||||
WallProvider provider = new SQLServerWallProvider();
|
||||
|
||||
String sql = "select top 50 * FROM [V_Goods_WithAvailableStockQuantity] where Status='����' and (Code like '%mu%' ESCAPE '\' or Model like '%mu%' ESCAPE '\' or Spec like '%mu%' ESCAPE '\' or BarCode like '%mu%' ESCAPE '\' or ProductName like '%mu%' ESCAPE '\' or dbo.F_GetPY(ProductName) like '%mu%' ESCAPE '\') ";
|
||||
|
||||
Assert.assertTrue(provider.checkValid(sql));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,22 +15,16 @@
|
||||
*/
|
||||
package com.alibaba.druid.bvt.filter.wall;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import com.alibaba.druid.wall.WallProvider;
|
||||
import com.alibaba.druid.wall.spi.SQLServerWallProvider;
|
||||
|
||||
/**
|
||||
* SQLServerWallTest
|
||||
*
|
||||
* @author RaymondXiu
|
||||
* @version 1.0, 2012-3-18
|
||||
* @see
|
||||
*/
|
||||
public class SQLServerWallTest_9 extends TestCase {
|
||||
@@ -44,7 +38,7 @@ public class SQLServerWallTest_9 extends TestCase {
|
||||
+ " AND status='P'" //
|
||||
+ " AND islast=0" //
|
||||
+ " AND NOT EXISTS (select m.id from project_measures m WHERE m.snapshot_id=s.id)";
|
||||
|
||||
|
||||
Assert.assertTrue(provider.checkValid(sql));
|
||||
|
||||
}
|
||||
|
||||
@@ -96,17 +96,6 @@ public class DMLInsertParserTest extends TestCase {
|
||||
"\n\t('12''34')", output);
|
||||
}
|
||||
|
||||
public void testInsert_7() throws Exception {
|
||||
String sql = "insErt LOW_PRIORITY t1 (col1, t1.col2) VALUE (123,'123\\'4') oN dupLicatE key UPDATE ex.col1=?";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("INSERT LOW_PRIORITY INTO t1 (col1, t1.col2)\nVALUES (123, '123''4')" + //
|
||||
"\nON DUPLICATE KEY UPDATE ex.col1 = ?",
|
||||
output);
|
||||
}
|
||||
|
||||
public void testInsert_8() throws Exception {
|
||||
String sql = "insErt LOW_PRIORITY t1 (col1, t1.col2) select id from t3 oN dupLicatE key UPDATE ex.col1=?";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.cobar;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
public class DMLInsertParserTest_Special extends TestCase {
|
||||
public void testInsert_7() throws Exception {
|
||||
String sql = "insErt LOW_PRIORITY t1 (col1, t1.col2) VALUE (123,'123\\'4') oN dupLicatE key UPDATE ex.col1=?";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("INSERT LOW_PRIORITY INTO t1 (col1, t1.col2)\nVALUES (123, '123''4')" + //
|
||||
"\nON DUPLICATE KEY UPDATE ex.col1 = ?",
|
||||
output);
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,12 @@ public class ResourceTest extends TestCase {
|
||||
private String[] items;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
File file = new File("D:\\error_sql");
|
||||
File file = new File("D:\\scan_error.txt");
|
||||
FileInputStream is = new FileInputStream(file);
|
||||
String all = Utils.read(is);
|
||||
is.close();
|
||||
|
||||
items = all.split("\\|\\n\\|");
|
||||
items = all.split("\\|\\r\\n\\|");
|
||||
}
|
||||
|
||||
public void test_xx() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user