use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerCreateTableTest method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE VIEW [Current Product List] AS\n" + //
"SELECT ProductID,ProductName\n" + //
"FROM Products\n" + "WHERE Discontinued=No";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLCreateViewStatement stmt = (SQLCreateViewStatement) 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(4, visitor.getColumns().size());
Assert.assertEquals(2, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("Products")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Products", "ProductID")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Products", "ProductName")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Products", "Discontinued")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Products", "No")));
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerCreateTableTest_7 method test_0.
public void test_0() throws Exception {
String sql = "create table leave_jpa (" + " id bigint identity not null, " + " user_id varchar(255), " + " primary key (id)" + ")";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLCreateTableStatement stmt = (SQLCreateTableStatement) statementList.get(0);
Assert.assertEquals(1, statementList.size());
String output = SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER);
Assert.assertEquals("CREATE TABLE leave_jpa (" + "\n\tid bigint DEFAULT NULL IDENTITY," + "\n\tuser_id varchar(255)," + "\n\tPRIMARY KEY (id)" + "\n)", output);
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(2, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("leave_jpa")));
Assert.assertTrue(visitor.getColumns().contains(new Column("leave_jpa", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("leave_jpa", "user_id")));
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerCreateTableTest_9 method test_0.
public void test_0() throws Exception {
String sql = "CREATE TABLE [dbo].[users2](\n" + "\t[id] [bigint] IDENTITY(1,1) NOT NULL,\n" + "\t[email] [varchar](255) NOT NULL,\n" + "\t[name] [varchar](255) NOT NULL,\n" + "PRIMARY KEY CLUSTERED \n" + "(\n" + "\t[id] ASC\n" + ")\n" + ")";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLCreateTableStatement stmt = (SQLCreateTableStatement) statementList.get(0);
Assert.assertEquals(1, statementList.size());
String output = SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER);
Assert.assertEquals("CREATE TABLE [dbo].[users2] (\n" + "\t[id] [bigint] DEFAULT NULL IDENTITY (1, 1),\n" + "\t[email] [varchar](255) NOT NULL,\n" + "\t[name] [varchar](255) NOT NULL,\n" + "\tPRIMARY KEY CLUSTERED ([id] ASC)\n" + ")", output);
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(3, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("dbo.users2")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.users2", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.users2", "email")));
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerInsertTest3 method test_isEmpty.
public void test_isEmpty() throws Exception {
String sql = //
"INSERT INTO Production.UnitMeasure " + "VALUES (N'F2', N'Square Feet', GETDATE());;";
String expect = //
"INSERT INTO Production.UnitMeasure" + "\nVALUES (N'F2', N'Square Feet', GETDATE());";
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 SQLServerAlterTableTest_5 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "ALTER TABLE project_measures DROP COLUMN diff_value_1, diff_value_2, diff_value_3";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
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());
String output = SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER);
Assert.assertEquals(//
"ALTER TABLE project_measures" + "\n\tDROP COLUMN diff_value_1, diff_value_2, diff_value_3", output);
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(3, visitor.getColumns().size());
}
Aggregations