Search in sources :

Example 76 with SQLSelectStatement

use of com.alibaba.druid.sql.ast.statement.SQLSelectStatement in project druid by alibaba.

the class SQLServerTopTest method test_isEmpty.

public void test_isEmpty() throws Exception {
    String sql = "SELECT TOP 10 * FROM T";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
    Assert.assertEquals("SELECT TOP 10 *\nFROM T", SQLUtils.toSQLServerString(stmt));
    Assert.assertEquals("select top 10 *\nfrom T", SQLUtils.toSQLServerString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
Also used : SQLServerStatementParser(com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement)

Example 77 with SQLSelectStatement

use of com.alibaba.druid.sql.ast.statement.SQLSelectStatement in project druid by alibaba.

the class SQLServerTopTest2 method test_isEmpty.

public void test_isEmpty() throws Exception {
    String sql = "SELECT TOP ? * FROM T";
    String expect = "SELECT TOP ? *\nFROM T";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
    String text = TestUtils.outputSqlServer(stmt);
    Assert.assertEquals(expect, text);
//        System.out.println(text);
}
Also used : SQLServerStatementParser(com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement)

Example 78 with SQLSelectStatement

use of com.alibaba.druid.sql.ast.statement.SQLSelectStatement in project druid by alibaba.

the class SqlserverGroupByTest method testGroupBy.

public void testGroupBy() throws Exception {
    String sql = "SELECT a.workflowid, COUNT(1) FROM workflow_base a GROUP BY a.workflowid";
    SQLStatementParser parser = new SQLServerStatementParser(sql);
    //
    SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatement();
    try {
        stmt.toString();
    } catch (ClassCastException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : SQLServerStatementParser(com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement)

Aggregations

SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)78 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)39 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)25 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)23 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)21 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)17 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)15 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)14 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)10 SQLServerStatementParser (com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser)6 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)4 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)4 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)4 SQLServerSelectQueryBlock (com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock)3 SQLDeleteStatement (com.alibaba.druid.sql.ast.statement.SQLDeleteStatement)2 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)2 SQLSubqueryTableSource (com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource)2 SQLTableSource (com.alibaba.druid.sql.ast.statement.SQLTableSource)2 SQLUpdateStatement (com.alibaba.druid.sql.ast.statement.SQLUpdateStatement)2 Limit (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.Limit)2