bug fixed for postgresql sql parser. support begin. for issue #2182

This commit is contained in:
wenshao
2018-02-11 10:24:56 +08:00
parent 859e1c5d7f
commit f046543d72
2 changed files with 36 additions and 14 deletions
@@ -280,19 +280,18 @@ public class PGSQLStatementParser extends SQLStatementParser {
public boolean parseStatementListDialect(List<SQLStatement> statementList) {
switch (lexer.token()) {
case START: {
lexer.nextToken();
acceptIdentifier("TRANSACTION");
PGStartTransactionStatement stmt = new PGStartTransactionStatement();
statementList.add(stmt);
lexer.nextToken();
return true;
}
case WITH:
statementList.add(parseWith());
return true;
default:
break;
case BEGIN:
case START: {
PGStartTransactionStatement stmt = parseBegin();
statementList.add(stmt);
return true;
}
case WITH:
statementList.add(parseWith());
return true;
default:
break;
}
if (lexer.identifierEquals(FnvHash.Constants.CONNECT)) {
@@ -304,6 +303,18 @@ public class PGSQLStatementParser extends SQLStatementParser {
return false;
}
protected PGStartTransactionStatement parseBegin() {
PGStartTransactionStatement stmt = new PGStartTransactionStatement();
if (lexer.token() == Token.START) {
lexer.nextToken();
acceptIdentifier("TRANSACTION");
} else {
accept(Token.BEGIN);
}
return stmt;
}
public SQLStatement parseConnectTo() {
acceptIdentifier("CONNECT");
accept(Token.TO);
@@ -16,13 +16,24 @@
package com.alibaba.druid.bvt.sql.postgresql;
import com.alibaba.druid.sql.PGTest;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGStartTransactionStatement;
import com.alibaba.druid.util.JdbcConstants;
import java.util.List;
public class PGBeginTest extends PGTest {
public void testBegin() throws Exception {
String sql = "start transaction;";
String expected = "START TRANSACTION";
String expected = "START TRANSACTION;";
testParseSql(sql, expected, expected, PGStartTransactionStatement.class);
}
public void testBegin_1() throws Exception {
String sql = "begin";
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, JdbcConstants.POSTGRESQL);
assertEquals(1, stmtList.size());
}
}