use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGInsertTest11 method test_0.
public void test_0() throws Exception {
String sql = "INSERT INTO test VALUES (B'10'::bit(3), B'101');";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
// print(statementList);
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("test")));
assertEquals(0, visitor.getColumns().size());
//
// assertTrue(visitor.getColumns().contains(new TableStat.Column("distributors", "did")));
// assertTrue(visitor.getColumns().contains(new TableStat.Column("distributors", "dname")));
assertEquals("INSERT INTO test\n" + "VALUES (B'10'::bit(3), B'101');", stmt.toString());
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGInsertTest4 method test_0.
public void test_0() throws Exception {
String sql = "INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets') RETURNING did;";
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("distributors")));
Assert.assertEquals(2, visitor.getColumns().size());
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("distributors", "did")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("distributors", "dname")));
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGInsertTest6_multi method test_0.
public void test_0() throws Exception {
String sql = "INSERT INTO products (product_no, name, price) VALUES" + "\n (1, 'Cheese', 9.99)," + "\n (2, 'Bread', 1.99)," + "\n (3, 'Milk', 2.99);";
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("products")));
Assert.assertEquals(3, visitor.getColumns().size());
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("products", "product_no")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("products", "name")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("products", "price")));
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGMergeIntoTest0 method test_0.
public void test_0() throws Exception {
String sql = "MERGE INTO CustomerAccount CA \n" + "USING (Select CustomerId, TransactionValue From RecentTransactions) AS T \n" + "ON CA.CustomerId = T.CustomerId \n" + "WHEN NOT MATCHED THEN \n" + " INSERT (CustomerId, Balance) \n" + " VALUES (T.CustomerId, T.TransactionValue) \n" + "WHEN MATCHED THEN \n" + " UPDATE SET Balance = Balance + TransactionValue; ";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
assertEquals("MERGE INTO CustomerAccount CA\n" + "USING (\n" + "\t(SELECT CustomerId, TransactionValue\n" + "\tFROM RecentTransactions)\n" + ") T ON (CA.CustomerId = T.CustomerId) \n" + "WHEN MATCHED THEN UPDATE SET Balance = Balance + TransactionValue\n" + "WHEN NOT MATCHED THEN INSERT (CustomerId, Balance) VALUES (T.CustomerId, T.TransactionValue);", 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 PGShowTest method test_0.
public void test_0() throws Exception {
String sql = "SHOW max_identifier_length";
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());
{
WallProvider provider = new PGWallProvider();
Assert.assertTrue(provider.checkValid(sql));
}
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("reviews")));
// Assert.assertTrue(visitor.getTables().get(new TableStat.Name("reviews")).getAlterCount() == 1);
// Assert.assertTrue(visitor.getColumns().size() == 1);
}
Aggregations