use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerSetTest method test_0.
public void test_0() {
String sql = "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
Assert.assertEquals(1, stmtList.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(0, visitor.getTables().size());
Assert.assertEquals(0, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
String text = SQLUtils.toSQLString(stmtList, JdbcUtils.SQL_SERVER);
Assert.assertEquals("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED", text);
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerSetTest method test_1.
public void test_1() {
String sql = "SET FMTONLY ON";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
Assert.assertEquals(1, stmtList.size());
SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
stmt.accept(visitor);
Assert.assertEquals(0, visitor.getTables().size());
Assert.assertEquals(0, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
String text = SQLUtils.toSQLString(stmtList, JdbcUtils.SQL_SERVER);
Assert.assertEquals("SET FMTONLY ON", text);
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerUpdateTest4 method test_update.
public void test_update() throws Exception {
String sql = "UPDATE TOP (10) HumanResources.Employee " + "SET VacationHours = VacationHours * 1.25 ;";
String expect = "UPDATE TOP (10) HumanResources.Employee" + "\nSET VacationHours = VacationHours * 1.25;";
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 SQLServerUpdateTest6 method test_update.
public void test_update() throws Exception {
String sql = "update clients set name =N'小明',age =1";
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);
assertEquals("UPDATE clients\n" + "SET name = N'小明', age = 1", stmt.toString());
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SqlServerResourceTest method exec_test.
public void exec_test(String resource) throws Exception {
// System.out.println(resource);
InputStream is = null;
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
Reader reader = new InputStreamReader(is, "UTF-8");
String input = Utils.read(reader);
JdbcUtils.close(reader);
String[] items = input.split("---------------------------");
String sql = items[0].trim();
String expect = null;
if (items.length > 1) {
expect = items[1].trim();
expect = expect.replaceAll("\\r\\n", "\n");
}
SQLStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
SchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
stmt.accept(visitor);
System.out.println(stmt.toString());
if (expect != null && !expect.isEmpty()) {
assertEquals(expect, stmt.toString());
}
// System.out.println(sql);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
//
// System.out.println();
// System.out.println("---------------------------");
// System.out.println(SQLUtils.toOdpsString(stmt));
}
Aggregations