Merge pull request #1746 from terryzhu/support_more_pg_syntax

添加postgresql的begin,commit,set命令解析
This commit is contained in:
高铁
2017-05-31 13:39:31 +08:00
committed by GitHub
19 changed files with 603 additions and 63 deletions
@@ -17,10 +17,12 @@ package com.alibaba.druid.sql;
import java.util.List;
import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser;
import junit.framework.TestCase;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGOutputVisitor;
import org.junit.Assert;
public class PGTest extends TestCase {
protected String output(List<SQLStatement> stmtList) {
@@ -42,4 +44,18 @@ public class PGTest extends TestCase {
}
System.out.println(text);
}
protected void testParseSql(String sql, String expectedSql, String expectedPattern, Class<?> type) {
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statement = statementList.get(0);
Assert.assertEquals(1, statementList.size());
Assert.assertTrue(type.isAssignableFrom(statement.getClass()));
StringBuilder sb = new StringBuilder();
PGOutputVisitor visitor = new PGOutputVisitor(sb);
statement.accept(visitor);
Assert.assertEquals(expectedSql, sb.toString());
}
}