use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerGrantTest_2 method test_grants.
public void test_grants() throws Exception {
String sql = "GRANT IMPERSONATE ON USER::HamithaL TO AccountsPayable17;";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
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());
String output = SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER);
Assert.assertEquals("GRANT IMPERSONATE ON USER::HamithaL TO AccountsPayable17;", output);
Assert.assertEquals(0, visitor.getTables().size());
Assert.assertEquals(0, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerSelectTest1 method test_isEmpty.
public void test_isEmpty() throws Exception {
String sql = "USE AdventureWorks2008R2;";
String expect = "USE AdventureWorks2008R2;";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
String text = TestUtils.outputSqlServer(stmt);
Assert.assertEquals(expect, text);
// System.out.println(text);
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerSelectTest13 method test_simple.
public void test_simple() throws Exception {
String sql = //
"SELECT" + //
" a.* " + //
"FROM" + //
" (" + //
" SELECT" + //
" row_number () over (ORDER BY a.time_add DESC) ROW," + //
" a.detail_no AS detailNo," + //
" a.ba_id AS baId," + //
" a.ba_name AS baName," + //
" a.tran_no AS tranNo," + //
" a.tran_name AS tranName, " + //
" a.tran_type AS tranType, " + //
" a.balance_type AS balanceType, " + //
" a.detail_income AS detailIncome, " + //
" a.detail_payout AS detailPayout, " + //
" a.before_balance AS beforeBalance, " + //
" a.after_balance AS afterBalance, " + //
" a.time_add AS timeAdd, " + //
" a.user_add AS userAdd, " + //
" a.remark AS remark, " + //
" ( " + //
" SELECT " + //
" top 1 t.param_name " + //
" FROM " + //
" config.sys_params t " + //
" WHERE " + //
" t.param_type = ? " + //
" AND t.param_value = a.tran_type " + //
" ) AS tranTypeName " + //
" FROM " + //
" bussiness.account_detail a " + //
" WHERE " + //
" 1 = 1 " + //
" AND a.time_add >= ? " + //
" AND a.time_add <= ? " + //
" ) a " + //
"WHERE " + //
" a. ROW NOT BETWEEN (?+ 1) " + //
"AND (?+?)";
String expect = "SELECT a.*\n" + "FROM (\n" + "\tSELECT row_number() OVER (ORDER BY a.time_add DESC) AS ROW, a.detail_no AS detailNo, a.ba_id AS baId, a.ba_name AS baName\n" + "\t\t, a.tran_no AS tranNo, a.tran_name AS tranName, a.tran_type AS tranType, a.balance_type AS balanceType, a.detail_income AS detailIncome\n" + "\t\t, a.detail_payout AS detailPayout, a.before_balance AS beforeBalance, a.after_balance AS afterBalance, a.time_add AS timeAdd, a.user_add AS userAdd\n" + "\t\t, a.remark AS remark\n" + "\t\t, (\n" + "\t\t\tSELECT TOP 1 t.param_name\n" + "\t\t\tFROM config.sys_params t\n" + "\t\t\tWHERE t.param_type = ?\n" + "\t\t\t\tAND t.param_value = a.tran_type\n" + "\t\t) AS tranTypeName\n" + "\tFROM bussiness.account_detail a\n" + "\tWHERE 1 = 1\n" + "\t\tAND a.time_add >= ?\n" + "\t\tAND a.time_add <= ?\n" + ") a\n" + "WHERE a.ROW NOT BETWEEN (? + 1) AND (? + ?)";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
String text = TestUtils.outputSqlServer(stmt);
assertEquals(expect, text);
// System.out.println(text);
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerSelectTest15 method test_simple.
public void test_simple() throws Exception {
//
String sql = "SELECT TOP 50 PERCENT * FROM Persons";
String expect = //
"SELECT TOP 50 PERCENT *\n" + "FROM Persons";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
String text = TestUtils.outputSqlServer(stmt);
Assert.assertEquals(expect, text);
// System.out.println(text);
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerSelectTest20 method test_simple.
public void test_simple() throws Exception {
//
String sql = "SELECT First_Name + ' ' + Last Name FROM Employees ORDER BY First_Name OFFSET 10 ROWS;";
String expect = //
"SELECT First_Name + ' ' + Last AS Name" + //
"\nFROM Employees" + //
"\nORDER BY First_Name" + "\nOFFSET 10 ROWS;";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
String text = TestUtils.outputSqlServer(stmt);
assertEquals(expect, text);
// System.out.println(text);
}
Aggregations