use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerCreateTableTest_1 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE [projects] (" + //
"[id] int NOT NULL IDENTITY(1, 1) PRIMARY KEY, " + //
"[name] NVARCHAR(256), [description] NVARCHAR(2000), " + //
"[enabled] bit DEFAULT 1 NOT NULL, " + //
"[scope] NVARCHAR(3), " + //
"[qualifier] NVARCHAR(3), " + //
"[kee] NVARCHAR(400), " + //
"[root_id] int, " + //
"[profile_id] int, " + //
"[language] NVARCHAR(5), " + //
"[copy_resource_id] int, " + "[long_name] NVARCHAR(256)) ";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLCreateTableStatement stmt = (SQLCreateTableStatement) statementList.get(0);
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(12, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("projects")));
Assert.assertTrue(visitor.containsColumn("projects", "id"));
Assert.assertTrue(visitor.containsColumn("projects", "name"));
Assert.assertTrue(visitor.containsColumn("projects", "enabled"));
Assert.assertTrue(visitor.containsColumn("projects", "scope"));
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerUpdateTest3 method test_update.
public void test_update() throws Exception {
String sql = //
"UPDATE Sales.SalesPerson " + //
"SET SalesYTD = SalesYTD + " + //
" (SELECT SUM(so.SubTotal) " + //
" FROM Sales.SalesOrderHeader AS so" + //
" WHERE so.OrderDate = (SELECT MAX(OrderDate)" + //
" FROM Sales.SalesOrderHeader AS so2" + //
" WHERE so2.SalesPersonID = " + //
" so.SalesPersonID)" + //
" AND Sales.SalesPerson.SalesPersonID = so.SalesPersonID" + " GROUP BY so.SalesPersonID);";
String expect = "UPDATE Sales.SalesPerson" + "\nSET SalesYTD = SalesYTD + (" + "\n\tSELECT SUM(so.SubTotal)" + "\n\tFROM Sales.SalesOrderHeader so" + "\n\tWHERE so.OrderDate = (" + "\n\t\t\tSELECT MAX(OrderDate)" + "\n\t\t\tFROM Sales.SalesOrderHeader so2" + "\n\t\t\tWHERE so2.SalesPersonID = so.SalesPersonID" + "\n\t\t)" + "\n\t\tAND Sales.SalesPerson.SalesPersonID = so.SalesPersonID" + "\n\tGROUP BY so.SalesPersonID" + "\n);";
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 SQLServerUpdateTest5 method test_update.
public void test_update() throws Exception {
String sql = "UPDATE TOP (10) HumanResources.Employee SET VacationHours = VacationHours * 1.25, ModifiedDate = GETDATE() OUTPUT inserted.BusinessEntityID, deleted.VacationHours, inserted.VacationHours, inserted.ModifiedDate INTO @MyTableVar;";
String expect = "UPDATE TOP (10) HumanResources.Employee" + "\nSET VacationHours = VacationHours * 1.25, ModifiedDate = GETDATE()" + "\nOUTPUT inserted.BusinessEntityID, deleted.VacationHours, inserted.VacationHours, inserted.ModifiedDate" + "\n\tINTO @MyTableVar;";
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 SQLServerWaitForTest method test_1.
public void test_1() {
String sql = "WAITFOR DELAY '02:00';";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
Assert.assertEquals(1, stmtList.size());
String text = SQLUtils.toSQLString(stmtList, JdbcUtils.SQL_SERVER);
Assert.assertEquals("WAITFOR DELAY '02:00';", text);
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerWaitForTest method test_0.
public void test_0() {
String sql = "WAITFOR TIME '22:20';";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
Assert.assertEquals(1, stmtList.size());
String text = SQLUtils.toSQLString(stmtList, JdbcUtils.SQL_SERVER);
Assert.assertEquals("WAITFOR TIME '22:20';", text);
}
Aggregations