use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGSelectTest3 method test_0.
public void test_0() throws Exception {
String sql = //
"SELECT TITLE_ID,WEB_ID,MENU_TYPE_ID,MENU_ID,TITLE" + //
",SOURCE,INFO,RECOMMEND_FLAG,CREATE_TIME,CREATE_IP,CREATE_ACCENDANT_ID" + //
",LAST_UPD_TIME,LAST_UPD_IP,LAST_UPD_ACCENDANT_ID,'http://cmp2.test.com/cmps' AS STR_BASE_URL" + //
",'html' AS STR_SUFFIX FROM WEB_DATA_TITLE_LIST" + " WHERE WEB_ID=? AND MENU_ID=? AND MENU_TYPE_ID=? ORDER BY RECOMMEND_FLAG DESC ,LAST_UPD_TIME DESC OFFSET ? LIMIT ?";
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());
// System.out.println("coditions : " + visitor.getConditions());
Assert.assertEquals(14, visitor.getColumns().size());
Assert.assertEquals(1, visitor.getTables().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGAlterTableTest1 method test_0.
public void test_0() throws Exception {
String sql = "ALTER TABLE \"measure_data\" ALTER \"measure_id\" DROP NOT NULL";
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("measure_data")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("measure_data")).getAlterCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 1);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGAlterTableTest3 method test_0.
public void test_0() throws Exception {
String sql = //
"ALTER TABLE issues " + //
"ADD COLUMN issue_creation_date_ms BIGINT NULL, " + //
"ADD COLUMN issue_update_date_ms BIGINT NULL, " + //
"ADD COLUMN issue_close_date_ms BIGINT NULL, " + //
"ADD COLUMN tags VARCHAR (4000) NULL, " + //
"ADD COLUMN component_uuid VARCHAR (50) NULL, " + "ADD COLUMN project_uuid VARCHAR (50) NULL";
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("issues")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("issues")).getAlterCount() == 1);
Assert.assertEquals(visitor.getColumns().size(), 6);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGCommentTest method test_2.
public void test_2() throws Exception {
String sql = "/*multiline comment test" + ".\r\n multiline comment test*" + "/select --single line comment test\r\na.id," + "/*multiline comment test*/" + "a.name from a;";
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());
System.out.println("coditions : " + visitor.getConditions());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("a")));
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGCreateTableTest_0 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE my_first_table (" + //
" first_column text," + //
" second_column integer" + ");";
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("my_first_table")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("my_first_table")).getCreateCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 2);
}
Aggregations