add sql parser testcases

This commit is contained in:
高铁
2016-03-12 16:16:59 +08:00
parent 491752c4dd
commit 55280f4675
35 changed files with 211 additions and 91 deletions
@@ -47,7 +47,6 @@ public class SQLServerCreateTableTest_3 extends TestCase {
Assert.assertEquals(1, statementList.size());
String output = SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER);
Assert.assertEquals("CREATE TABLE dbo.cwd_directory (" //
+ "\n\tID NUMERIC NOT NULL,"//
+ "\n\tdirectory_name NVARCHAR(255),"//
@@ -61,7 +60,23 @@ public class SQLServerCreateTableTest_3 extends TestCase {
+ "\n\tdirectory_type NVARCHAR(60),"//
+ "\n\tdirectory_position NUMERIC,"//
+ "\n\tCONSTRAINT PK_cwd_directory PRIMARY KEY (ID)"//
+ "\n)", output);
+ "\n)", SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER));
Assert.assertEquals("create table dbo.cwd_directory (" //
+ "\n\tID NUMERIC not null,"//
+ "\n\tdirectory_name NVARCHAR(255),"//
+ "\n\tlower_directory_name NVARCHAR(255),"//
+ "\n\tcreated_date DATETIME,"//
+ "\n\tupdated_date DATETIME,"//
+ "\n\tactive int,"//
+ "\n\tdescription NVARCHAR(255),"//
+ "\n\timpl_class NVARCHAR(255),"//
+ "\n\tlower_impl_class NVARCHAR(255),"//
+ "\n\tdirectory_type NVARCHAR(60),"//
+ "\n\tdirectory_position NUMERIC,"//
+ "\n\tconstraint PK_cwd_directory primary key (ID)"//
+ "\n)", SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
stmt.accept(visitor);
@@ -16,26 +16,24 @@
package com.alibaba.druid.bvt.sql.sqlserver;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
import com.alibaba.druid.sql.test.TestUtils;
import junit.framework.TestCase;
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);
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));
System.out.println(text);
}
}