mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #731 from wenshao/master
pg sqlparser support drop table if not exists
This commit is contained in:
@@ -552,6 +552,12 @@
|
||||
<artifactId>tbdatasource</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>jboss</groupId>
|
||||
<artifactId>jboss-j2ee</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,11 +1,10 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import javax.resource.cci.ResultSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
@@ -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