use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerInsertTest9 method test_0.
public void test_0() throws Exception {
String sql = "insert into dashboard_role_res (res_id, role_id,res_type) values (?, ? ,?) , (?, ? ,?)";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
parser.setParseCompleteValues(false);
parser.setParseValuesSize(3);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
SQLServerInsertStatement insertStmt = (SQLServerInsertStatement) stmt;
Assert.assertEquals(2, insertStmt.getValuesList().size());
Assert.assertEquals(3, insertStmt.getValues().getValues().size());
Assert.assertEquals(3, insertStmt.getColumns().size());
Assert.assertEquals(1, statementList.size());
SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
stmt.accept(visitor);
String formatSql = "INSERT INTO dashboard_role_res (res_id, role_id, res_type)\n" + "VALUES (?, ?, ?),\n" + "(?, ?, ?)";
Assert.assertEquals(formatSql, SQLUtils.toSQLServerString(insertStmt));
}
use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerCreateTableTest_2 method test_0.
public void test_0() throws Exception {
String sql = "CREATE TABLE #Test (C1 nvarchar(10), C2 nvarchar(50), C3 datetime);";
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 #Test (" + //
"\n\tC1 nvarchar(10)," + //
"\n\tC2 nvarchar(50)," + //
"\n\tC3 datetime" + "\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("#Test")));
Assert.assertTrue(visitor.getColumns().contains(new Column("#Test", "C1")));
Assert.assertTrue(visitor.getColumns().contains(new Column("#Test", "C2")));
Assert.assertTrue(visitor.getColumns().contains(new Column("#Test", "C3")));
}
use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerCreateTableTest_3 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE dbo.cwd_directory (" + //
"ID NUMERIC NOT NULL, directory_name NVARCHAR(255), " + //
"lower_directory_name NVARCHAR(255), created_date DATETIME, " + //
"updated_date DATETIME, active int, description NVARCHAR(255), " + //
"impl_class NVARCHAR(255), lower_impl_class NVARCHAR(255), " + //
"directory_type NVARCHAR(60), directory_position NUMERIC, " + "CONSTRAINT PK_cwd_directory PRIMARY KEY (ID))";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLCreateTableStatement stmt = (SQLCreateTableStatement) statementList.get(0);
Assert.assertEquals(1, statementList.size());
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));
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);
// 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(12, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("dbo.cwd_directory")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.cwd_directory", "ID")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.cwd_directory", "directory_name")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.cwd_directory", "lower_directory_name")));
}
use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerCreateTableTest_5 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE dbo.AO_563AEE_ACTOR_ENTITY (" + //
" FULL_NAME VARCHAR(255)," + //
" ID INTEGER IDENTITY(1,1) NOT NULL," + //
" PROFILE_PAGE_URI VARCHAR(767)," + //
" PROFILE_PICTURE_URI VARCHAR(767)," + //
" USERNAME VARCHAR(255)," + ")";
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_563AEE_ACTOR_ENTITY (" + //
"\n\tFULL_NAME VARCHAR(255)," + //
"\n\tID INTEGER DEFAULT NULL IDENTITY (1, 1)," + //
"\n\tPROFILE_PAGE_URI VARCHAR(767)," + //
"\n\tPROFILE_PICTURE_URI VARCHAR(767)," + //
"\n\tUSERNAME VARCHAR(255)" + "\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(5, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("dbo.AO_563AEE_ACTOR_ENTITY")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.AO_563AEE_ACTOR_ENTITY", "FULL_NAME")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.AO_563AEE_ACTOR_ENTITY", "ID")));
Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.AO_563AEE_ACTOR_ENTITY", "USERNAME")));
}
use of com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor in project druid by alibaba.
the class SQLServerGrantTest_1 method test_grants.
public void test_grants() throws Exception {
String sql = "GRANT CONTROL ON USER::Wanida TO RolandX;";
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 CONTROL ON USER::Wanida TO RolandX;", output);
Assert.assertEquals(0, visitor.getTables().size());
Assert.assertEquals(0, visitor.getColumns().size());
}
Aggregations