mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
pg sqlparser support drop table if not exists
This commit is contained in:
@@ -62,6 +62,7 @@ public class PGLexer extends Lexer {
|
||||
map.put("TRUE", Token.TRUE);
|
||||
map.put("FALSE", Token.FALSE);
|
||||
map.put("ARRAY", Token.ARRAY);
|
||||
map.put("IF", Token.IF);
|
||||
|
||||
DEFAULT_PG_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql.postgresql.ddl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.PGTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
|
||||
|
||||
public class PGDropTableIfExistsTest extends PGTest {
|
||||
public void test_0 () throws Exception {
|
||||
String sql = "DROP TABLE IF EXISTS t_report_1_19";
|
||||
|
||||
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_report_1_19")));
|
||||
|
||||
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("t_report_1_19")).getDropCount() == 1);
|
||||
|
||||
Assert.assertTrue(visitor.getColumns().size() == 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user