use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerSelectTest2 method test_isEmpty.
public void test_isEmpty() throws Exception {
String sql = "SELECT TOP 1 name FROM (SELECT TOP 9 name FROM master..syslogins ORDER BY name ASC) sq ORDER BY name DESC ";
String expect = //
"SELECT TOP 1 name\n" + //
"FROM (SELECT TOP 9 name\n" + //
"\tFROM master..syslogins\n" + //
"\tORDER BY name ASC\n" + //
"\t) sq\n" + "ORDER BY name DESC";
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);
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 SQLServerSelectTest21 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 FETCH NEXT 5 ROWS ONLY;";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
{
String text = SQLUtils.toSQLServerString(stmt);
Assert.assertEquals(//
"SELECT First_Name + ' ' + Last AS Name" + //
"\nFROM Employees" + //
"\nORDER BY First_Name" + "\nOFFSET 10 ROWS FETCH NEXT 5 ROWS ONLY", text);
}
{
String text = SQLUtils.toSQLServerString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals(//
"select First_Name + ' ' + Last as Name" + //
"\nfrom Employees" + //
"\norder by First_Name" + "\noffset 10 rows fetch next 5 rows only", text);
}
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerCreateTableTest_8 method test_0.
public void test_0() throws Exception {
String sql = "create table ACT_RU_VARIABLE (" + " ID_ nvarchar(64) not null," + " DOUBLE_ double precision," + " LONG_ numeric(19,0)," + " TEXT_ nvarchar(4000)," + " primary key (ID_)" + ")";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLCreateTableStatement stmt = (SQLCreateTableStatement) statementList.get(0);
Assert.assertEquals(1, statementList.size());
String output = SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER);
Assert.assertEquals("CREATE TABLE ACT_RU_VARIABLE (" + "\n\tID_ nvarchar(64) NOT NULL," + "\n\tDOUBLE_ DOUBLE PRECISION," + "\n\tLONG_ numeric(19, 0)," + "\n\tTEXT_ nvarchar(4000)," + "\n\tPRIMARY KEY (ID_)" + "\n)", output);
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(4, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("ACT_RU_VARIABLE")));
Assert.assertTrue(visitor.getColumns().contains(new Column("ACT_RU_VARIABLE", "ID_")));
Assert.assertTrue(visitor.getColumns().contains(new Column("ACT_RU_VARIABLE", "DOUBLE_")));
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project Mycat_plus by coderczp.
the class DruidSelectSqlServerParser method sqlserverParse.
private void sqlserverParse(SchemaConfig schema, RouteResultset rrs) {
// 使用sqlserver的解析,否则会有部分语法识别错误
SQLServerStatementParser oracleParser = new SQLServerStatementParser(getCtx().getSql());
SQLSelectStatement oracleStmt = (SQLSelectStatement) oracleParser.parseStatement();
SQLSelectQuery oracleSqlSelectQuery = oracleStmt.getSelect().getQuery();
if (oracleSqlSelectQuery instanceof SQLServerSelectQueryBlock) {
parseSqlServerPageSql(oracleStmt, rrs, (SQLServerSelectQueryBlock) oracleSqlSelectQuery, schema);
if (isNeedParseOrderAgg) {
parseOrderAggGroupSqlServer(schema, oracleStmt, rrs, (SQLServerSelectQueryBlock) oracleSqlSelectQuery);
}
}
}
Aggregations