use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class MTSParserTest method test_mts_0.
public void test_mts_0() throws Exception {
String sql = " savepoint xx";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("SAVEPOINT xx", output);
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class MTSParserTest method test_rollback_0.
public void test_rollback_0() throws Exception {
String sql = "rollBack to x1";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ROLLBACK TO x1", output);
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class MTSParserTest method test_lockTable_1.
public void test_lockTable_1() throws Exception {
String sql = "LOCK TABLES t2 READ LOCAL;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("LOCK TABLES t2 READ LOCAL", output);
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class DB2DropSequenceTest_0 method test_0.
public void test_0() throws Exception {
String sql = "drop sequence sales1_seq";
DB2StatementParser parser = new DB2StatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
DB2SchemaStatVisitor visitor = new DB2SchemaStatVisitor();
stmt.accept(visitor);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
// System.out.println("coditions : " + visitor.getConditions());
// System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(0, visitor.getTables().size());
Assert.assertEquals(0, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("A")));
// Assert.assertTrue(visitor.getColumns().contains(new Column("A", "F_0201")));
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
//
Assert.assertEquals(//
"DROP SEQUENCE sales1_seq", SQLUtils.toSQLString(stmt, JdbcConstants.DB2));
//
Assert.assertEquals(//
"drop sequence sales1_seq", SQLUtils.toSQLString(stmt, JdbcConstants.DB2, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class DB2MergeTest method test_0.
public void test_0() throws Exception {
String sql = "MERGE INTO product AS T " + " USING sales AS S" + " ON S.id = T.id" + " WHEN MATCHED THEN UPDATE SET inventory = T.inventory - S.sold;";
DB2StatementParser parser = new DB2StatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
DB2SchemaStatVisitor visitor = new DB2SchemaStatVisitor();
stmt.accept(visitor);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
// System.out.println("coditions : " + visitor.getConditions());
// System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(2, visitor.getTables().size());
Assert.assertEquals(4, visitor.getColumns().size());
Assert.assertEquals(2, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("sales")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("product")));
// Assert.assertTrue(visitor.getColumns().contains(new Column("DSN8B10.EMP", "WORKDEPT")));
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
Assert.assertEquals("MERGE INTO product T" + "\nUSING sales S ON (S.id = T.id) " + //
"\nWHEN MATCHED THEN UPDATE SET inventory = T.inventory - S.sold", SQLUtils.toSQLString(stmt, JdbcConstants.DB2));
Assert.assertEquals("merge into product T" + "\nusing sales S on (S.id = T.id) " + //
"\nwhen matched then update set inventory = T.inventory - S.sold", SQLUtils.toSQLString(stmt, JdbcConstants.DB2, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
Aggregations