mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql server support
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.alibaba.druid.bvt.sql.sqlserver;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import com.alibaba.druid.sql.test.TestUtils;
|
||||
|
||||
public class SQLServerTopTest extends TestCase {
|
||||
|
||||
public void test_isEmpty() throws Exception {
|
||||
String sql = "SELECT TOP 10 * FROM T";
|
||||
|
||||
String expect = "SELECT TOP 10 *\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);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SqlServerOutputVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
|
||||
|
||||
@@ -20,11 +21,26 @@ public class TestUtils {
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static String outputSqlServer(List<SQLStatement> stmtList) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
SqlServerOutputVisitor visitor = new SqlServerOutputVisitor(out);
|
||||
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
stmt.accept(visitor);
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static String outputOracle(SQLStatement... stmtList) {
|
||||
return outputOracle(Arrays.asList(stmtList));
|
||||
}
|
||||
|
||||
public static String outputSqlServer(SQLStatement... stmtList) {
|
||||
return outputSqlServer(Arrays.asList(stmtList));
|
||||
}
|
||||
|
||||
public static String output(SQLStatement... stmtList) {
|
||||
return output(Arrays.asList(stmtList));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user