use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerSelectTest4 method test_isEmpty.
public void test_isEmpty() throws Exception {
String sql = "SELECT name, password_hash FROM master.sys.sql_logins";
String expect = //
"SELECT name, password_hash\n" + "FROM master.sys.sql_logins";
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 SQLServerSelectTest6 method test_isEmpty.
public void test_isEmpty() throws Exception {
String sql = //
"WITH DirReps(ManagerID, DirectReports) AS " + //
"(" + //
" SELECT ManagerID, COUNT(*) " + //
" FROM HumanResources.Employee AS e" + //
" WHERE ManagerID IS NOT NULL" + //
" GROUP BY ManagerID" + //
")" + //
"SELECT ManagerID, DirectReports " + //
"FROM DirReps " + "ORDER BY ManagerID;";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
String text = TestUtils.outputSqlServer(stmt);
assertEquals("WITH DirReps (ManagerID, DirectReports) AS (\n" + "\t\tSELECT ManagerID, COUNT(*)\n" + "\t\tFROM HumanResources.Employee e\n" + "\t\tWHERE ManagerID IS NOT NULL\n" + "\t\tGROUP BY ManagerID\n" + "\t)\n" + "SELECT ManagerID, DirectReports\n" + "FROM DirReps\n" + "ORDER BY ManagerID;", text);
// System.out.println(text);
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerSelectTest8 method test_isEmpty.
public void test_isEmpty() throws Exception {
String sql = "SELECT Location.Distance (@p)" + " FROM Cities;";
String expect = //
"SELECT Location.Distance(@p)" + "\nFROM Cities;";
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 SQLServerSelectTest_cross_apply method test_0.
public void test_0() throws Exception {
String sql = "SELECT DeptID, DeptName, DeptMgrID, EmpID, EmpLastName, EmpSalary FROM Departments d CROSS APPLY dbo.GetReports(d.DeptMgrID)";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
SQLSelectStatement selectStmt = (SQLSelectStatement) stmt;
SQLSelect select = selectStmt.getSelect();
Assert.assertNotNull(select.getQuery());
SQLServerSelectQueryBlock queryBlock = (SQLServerSelectQueryBlock) select.getQuery();
Assert.assertNull(queryBlock.getGroupBy());
String fomatSQL = SQLUtils.toSQLString(statementList, JdbcUtils.SQL_SERVER);
// System.out.println(fomatSQL);
Assert.assertEquals(1, statementList.size());
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());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(7, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertEquals(0, visitor.getOrderByColumns().size());
String expected = //
"SELECT DeptID, DeptName, DeptMgrID, EmpID, EmpLastName" + //
"\n\t, EmpSalary" + //
"\nFROM Departments d" + "\n\tCROSS APPLY dbo.GetReports(d.DeptMgrID)";
Assert.assertEquals(expected, fomatSQL);
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerSelectTest11 method test_simple.
public void test_simple() throws Exception {
String sql = "SELECT 1";
String expect = "SELECT 1";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
String text = TestUtils.outputSqlServer(stmt);
Assert.assertEquals(expect, text);
// System.out.println(text);
}
Aggregations