Skip to content

Commit

Permalink
improve sql parser
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Aug 27, 2013
1 parent d5879ee commit 8b28bd4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<!--
<parent>
<groupId>com.alibaba</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
-->

<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>0.2.26-SNAPSHOT</version>
Expand Down Expand Up @@ -41,7 +48,6 @@
<url>dav:http://code.alibabatech.com/mvn/snapshots/</url>
</snapshotRepository>
</distributionManagement>

<developers>
<developer>
<id>wenshao</id>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/alibaba/druid/support/json/JSONParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.List;
import java.util.Map;

import com.alibaba.druid.sql.parser.CharTypes;

public class JSONParser {

private String text;
Expand Down Expand Up @@ -160,7 +162,7 @@ final void nextToken() {
}

for (;;) {
if (ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t') {
if (CharTypes.isWhitespace(ch)) {
nextChar();
continue;
}
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/com/alibaba/druid/test/wall/ResourceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.alibaba.druid.test.wall;

import java.io.File;
import java.io.FileInputStream;

import junit.framework.TestCase;

import com.alibaba.druid.util.Utils;
import com.alibaba.druid.wall.Violation;
import com.alibaba.druid.wall.WallCheckResult;
import com.alibaba.druid.wall.WallProvider;
import com.alibaba.druid.wall.spi.MySqlWallProvider;

public class ResourceTest extends TestCase {

private String[] items;

protected void setUp() throws Exception {
File file = new File("D:\\error_sql");
FileInputStream is = new FileInputStream(file);
String all = Utils.read(is);
is.close();

items = all.split("\\|\\n\\|");
}

public void test_xx() throws Exception {
WallProvider provider = new MySqlWallProvider();

for (int i = 0; i < items.length; ++i) {
String sql = items[i];

WallCheckResult result = provider.check(sql);
if (result.getViolations().size() > 0) {
Violation violation = result.getViolations().get(0);
System.err.println("error (" + i + ") : " + violation.getMessage());
System.out.println(sql);
System.out.println();
// break;
}
}

System.out.println("violaionCount : " + provider.getViolationCount());
}

}

0 comments on commit 8b28bd4

Please sign in to comment.