use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerGrantTest_2 method test_grants.
public void test_grants() throws Exception {
String sql = "GRANT IMPERSONATE ON USER::HamithaL TO AccountsPayable17;";
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("GRANT IMPERSONATE ON USER::HamithaL TO AccountsPayable17;", output);
Assert.assertEquals(0, 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 SQLServerCreateTableTest_6 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE dbo.AO_E8B6CC_ISSUE_MAPPING_V2 (" + //
" AUTHOR VARCHAR(255)," + //
" BRANCH VARCHAR(255)," + //
" \"DATE\" DATETIME," + //
" FILES_DATA NTEXT," + //
" ID INTEGER IDENTITY(1,1) NOT NULL," + //
" ISSUE_ID VARCHAR(255)," + //
" MESSAGE NTEXT," + //
" NODE VARCHAR(255)," + //
" PARENTS_DATA VARCHAR(255)," + //
" RAW_AUTHOR VARCHAR(255)," + //
" RAW_NODE VARCHAR(255)," + //
" REPOSITORY_ID INTEGER CONSTRAINT df_AO_E8B6CC_ISSUE_MAPPING_V2_REPOSITORY_ID DEFAULT 0," + //
" VERSION INTEGER," + //
"CONSTRAINT pk_AO_E8B6CC_ISSUE_MAPPING_V2_ID 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 dbo.AO_E8B6CC_ISSUE_MAPPING_V2 (" + //
"\n\tAUTHOR VARCHAR(255)," + //
"\n\tBRANCH VARCHAR(255)," + //
"\n\t\"DATE\" DATETIME," + //
"\n\tFILES_DATA NTEXT," + //
"\n\tID INTEGER DEFAULT NULL IDENTITY (1, 1)," + //
"\n\tISSUE_ID VARCHAR(255)," + //
"\n\tMESSAGE NTEXT," + //
"\n\tNODE VARCHAR(255)," + //
"\n\tPARENTS_DATA VARCHAR(255)," + //
"\n\tRAW_AUTHOR VARCHAR(255)," + //
"\n\tRAW_NODE VARCHAR(255)," + //
"\n\tREPOSITORY_ID INTEGER DEFAULT 0," + //
"\n\tVERSION INTEGER," + //
"\n\tCONSTRAINT pk_AO_E8B6CC_ISSUE_MAPPING_V2_ID PRIMARY 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(14, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("dbo.AO_E8B6CC_ISSUE_MAPPING_V2")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.AO_E8B6CC_ISSUE_MAPPING_V2", "AUTHOR")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.AO_E8B6CC_ISSUE_MAPPING_V2", "BRANCH")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.AO_E8B6CC_ISSUE_MAPPING_V2", "VERSION")));
}
use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerCreateTableTest_8 method test_0.
public void test_0() throws Exception {
String sql = "create table ACT_RU_VARIABLE (" + " ID_ nvarchar(64) not null," + " DOUBLE_ double precision," + " LONG_ numeric(19,0)," + " TEXT_ nvarchar(4000)," + " 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 ACT_RU_VARIABLE (" + "\n\tID_ nvarchar(64) NOT NULL," + "\n\tDOUBLE_ DOUBLE PRECISION," + "\n\tLONG_ numeric(19, 0)," + "\n\tTEXT_ nvarchar(4000)," + "\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(4, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("ACT_RU_VARIABLE")));
Assert.assertTrue(visitor.getColumns().contains(new Column("ACT_RU_VARIABLE", "ID_")));
Assert.assertTrue(visitor.getColumns().contains(new Column("ACT_RU_VARIABLE", "DOUBLE_")));
}
use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerGrantTest_0 method test_grants.
public void test_grants() throws Exception {
String sql = "grant all on database::TestDataBase to User1";
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("GRANT ALL ON DATABASE::TestDataBase TO User1", output);
Assert.assertEquals(0, 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 SQLServerCreateTableTest_4 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE dbo.customfieldoption (" + //
"ID NUMERIC NOT NULL, CUSTOMFIELD NUMERIC, CUSTOMFIELDCONFIG NUMERIC, " + //
"PARENTOPTIONID NUMERIC, SEQUENCE NUMERIC, customvalue NVARCHAR(255), " + //
"optiontype NVARCHAR(60), disabled NVARCHAR(60), " + "CONSTRAINT PK_customfieldoption 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 dbo.customfieldoption (" + //
"\n\tID NUMERIC NOT NULL," + //
"\n\tCUSTOMFIELD NUMERIC," + //
"\n\tCUSTOMFIELDCONFIG NUMERIC," + //
"\n\tPARENTOPTIONID NUMERIC," + //
"\n\tSEQUENCE NUMERIC," + //
"\n\tcustomvalue NVARCHAR(255)," + //
"\n\toptiontype NVARCHAR(60)," + //
"\n\tdisabled NVARCHAR(60)," + //
"\n\tCONSTRAINT PK_customfieldoption PRIMARY 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(9, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("dbo.customfieldoption")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.customfieldoption", "ID")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.customfieldoption", "CUSTOMFIELD")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.customfieldoption", "CUSTOMFIELDCONFIG")));
}
Aggregations