Search in sources :

Example 76 with SQLServerStatementParser

use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.

the class SQLServerSelectTest17 method test_simple.

public void test_simple() throws Exception {
    String sql = "SELECT CIM_ASSET_TYPE.ID" + "\nFROM CIM_ASSET_TYPE" + "\nWHERE CIM_ASSET_TYPE.DEL_STATUS = '0'" + "\nAND NOT (" + "\nCIM_ASSET_TYPE.MODEL_TABLE IS NULL" + "\nOR CIM_ASSET_TYPE.MODEL_TABLE = ''" + //
    ")";
    String expect = "SELECT CIM_ASSET_TYPE.ID" + "\nFROM CIM_ASSET_TYPE" + "\nWHERE CIM_ASSET_TYPE.DEL_STATUS = '0'" + "\n\tAND NOT (CIM_ASSET_TYPE.MODEL_TABLE IS NULL" + "\n\tOR CIM_ASSET_TYPE.MODEL_TABLE = '')";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    SQLStatement stmt = 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) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 77 with SQLServerStatementParser

use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.

the class SQLServerSelectTest18 method test_simple.

public void test_simple() throws Exception {
    String sql = //
    "SELECT T0.[Address], T0.[Address] " + //
    "FROM [dbo].[CRD1] T0 " + //
    "WHERE T0.[CardCode] = (@P1) AND T0.[AdresType] = (@P2) " + //
    "ORDER BY T0.[Address] " + //
    "FOR BROWSE";
    String expect = "SELECT T0.[Address], T0.[Address]" + "\nFROM [dbo].[CRD1] T0" + "\nWHERE T0.[CardCode] = @P1" + "\n\tAND T0.[AdresType] = @P2" + "\nORDER BY T0.[Address]" + "\nFOR BROWSE";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    SQLStatement stmt = 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) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 78 with SQLServerStatementParser

use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.

the class SQLServerSelectTest19 method test_simple.

public void test_simple() throws Exception {
    String sql = "SELECT p.BusinessEntityID, FirstName, LastName, PhoneNumber AS Phone" + "\nFROM Person.Person AS p" + "\nJOIN Person.PersonPhone AS pph ON p.BusinessEntityID  = pph.BusinessEntityID" + "\nWHERE LastName LIKE 'G%'" + "\nORDER BY LastName, FirstName " + //
    "\nFOR XML AUTO, TYPE, XMLSCHEMA, ELEMENTS XSINIL;";
    String expect = "SELECT p.BusinessEntityID, FirstName, LastName, PhoneNumber AS Phone" + "\nFROM Person.Person p" + "\n\tJOIN Person.PersonPhone pph ON p.BusinessEntityID = pph.BusinessEntityID" + "\nWHERE LastName LIKE 'G%'" + "\nORDER BY LastName, FirstName" + "\nFOR XML , TYPE, XMLSCHEMA, ELEMENTS XSINIL";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    SQLStatement stmt = 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) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 79 with SQLServerStatementParser

use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.

the class SQLServerSelectTest22 method test_simple.

public void test_simple() throws Exception {
    //
    String sql = "DELETE T FROM abc T";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    {
        String text = SQLUtils.toSQLServerString(stmt);
        Assert.assertEquals("DELETE T FROM abc T", text);
    }
    {
        String text = SQLUtils.toSQLServerString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
        Assert.assertEquals("delete T from abc T", text);
    }
}
Also used : SQLServerStatementParser(com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 80 with SQLServerStatementParser

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;";
    String expect = "WITH" + "\n\tDirReps (ManagerID, DirectReports)" + "\n\tAS" + "\n\t(" + "\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)" + "\nSELECT ManagerID, DirectReports" + "\nFROM DirReps" + "\nORDER BY ManagerID";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    SQLStatement stmt = 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) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLServerStatementParser (com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser)152 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)145 SQLServerSchemaStatVisitor (com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor)64 Column (com.alibaba.druid.stat.TableStat.Column)21 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)17 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)9 SQLServerSelectQueryBlock (com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock)8 SQLServerInsertStatement (com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement)8 SQLCreateIndexStatement (com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement)4 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)4 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)2 SQLCreateViewStatement (com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement)2 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)2 DB2StatementParser (com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser)2 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)2 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)2 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)2 PGSelectQueryBlock (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock)2 PGSQLStatementParser (com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)2 SQLMergeStatement (com.alibaba.druid.sql.ast.statement.SQLMergeStatement)1