use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerAlterTableTest_10 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = //
"ALTER TABLE dbo.doc_exc ADD column_b VARCHAR(20) NULL " + " CONSTRAINT exb_unique UNIQUE ;";
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 dbo.doc_exc" + "\n\tADD column_b VARCHAR(20) NULL CONSTRAINT exb_unique UNIQUE;", output);
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(1, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerAlterTableTest_12 method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "ALTER TABLE kpiTarget ADD deleted tinyint DEFAULT 0";
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 kpiTarget\n" + "\tADD deleted tinyint DEFAULT 0", output);
}
{
String output = SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("alter table kpiTarget\n" + "\tadd deleted tinyint default 0", output);
}
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(1, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerAlterTableTest_drop_constraint method test_alter_constraint.
public void test_alter_constraint() throws Exception {
String sql = "alter table SSHE.dbo.TUSER drop constraint UK_084c17821a8f47e8b31fbb126b6";
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 SSHE.dbo.TUSER" + "\n\tDROP CONSTRAINT UK_084c17821a8f47e8b31fbb126b6", output);
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(0, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerCreateIndexTest method test_0.
public void test_0() throws Exception {
String sql = "CREATE UNIQUE INDEX [unique_schema_migrations] ON [schema_migrations] ([version])";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLCreateIndexStatement stmt = (SQLCreateIndexStatement) statementList.get(0);
Assert.assertEquals(1, statementList.size());
//
Assert.assertEquals(//
"CREATE UNIQUE INDEX [unique_schema_migrations] ON [schema_migrations] ([version])", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
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(1, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("schema_migrations")));
Assert.assertTrue(visitor.getColumns().contains(new Column("schema_migrations", "version")));
}
use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerCreateIndexTest_3 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE NONCLUSTERED INDEX IX_SalesPerson_SalesQuota_SalesYTD" + " ON Sales.SalesPerson (SalesQuota, SalesYTD);";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLCreateIndexStatement stmt = (SQLCreateIndexStatement) statementList.get(0);
Assert.assertEquals(1, statementList.size());
Assert.assertEquals(//
"CREATE NONCLUSTERED INDEX IX_SalesPerson_SalesQuota_SalesYTD" + //
" ON Sales.SalesPerson (SalesQuota, SalesYTD);", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
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("Sales.SalesPerson")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Sales.SalesPerson", "SalesQuota")));
Assert.assertTrue(visitor.getColumns().contains(new Column("Sales.SalesPerson", "SalesYTD")));
}
Aggregations