use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGUpdateTest0 method test_0.
public void test_0() throws Exception {
String sql = "update student a set grade = tmp.grade from (values (1, 'A')) as tmp(id, grade) where a.id = tmp.id";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
assertEquals("UPDATE student a\n" + "SET grade = tmp.grade\n" + "FROM (VALUES (1, 'A')) AS tmp (id, grade)\n" + "WHERE a.id = tmp.id", stmt.toString());
assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
// System.out.println("coditions : " + visitor.getConditions());
assertTrue(visitor.getTables().containsKey(new TableStat.Name("student")));
assertEquals(2, visitor.getColumns().size());
assertTrue(visitor.containsColumn("student", "id"));
assertTrue(visitor.containsColumn("student", "grade"));
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGAlterTableAddUnique0 method test_0.
public void test_0() throws Exception {
String sql = "ALTER TABLE products ADD CONSTRAINT some_name UNIQUE (product_no);";
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("products")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getDropCount() == 0);
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getAlterCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 1);
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("products", "product_no")));
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGAlterTableDropColumnTest0 method test_0.
public void test_0() throws Exception {
String sql = "ALTER TABLE products DROP COLUMN description;";
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("products")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getDropCount() == 0);
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getAlterCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 1);
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGAlterTableDropConstraint method test_0.
public void test_0() throws Exception {
String sql = "ALTER TABLE products DROP CONSTRAINT some_name;";
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("products")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getDropCount() == 0);
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getAlterCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 0);
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGSelectTest1 method test_0.
public void test_0() throws Exception {
String sql = "SELECT * FROM t1 CROSS JOIN t2;";
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(2, visitor.getColumns().size());
Assert.assertEquals(2, visitor.getTables().size());
}
Aggregations