use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerDropTableTest method test_alter_first.
public void test_alter_first() throws Exception {
String sql = "DROP TABLE IF EXISTS test";
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);
assertEquals("DROP TABLE IF EXISTS test", output);
assertEquals(1, visitor.getTables().size());
assertEquals(0, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerInsertTest4 method test_isEmpty.
public void test_isEmpty() throws Exception {
String sql = "INSERT INTO dbo.AO_B9A0F0_APPLIED_TEMPLATE DEFAULT VALUES";
String expect = "INSERT INTO dbo.AO_B9A0F0_APPLIED_TEMPLATE DEFAULT VALUES";
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 SQLServerInsertTest5 method test_parseCompleteValues_false.
public void test_parseCompleteValues_false() throws Exception {
String sql = "insert into t(a,b) values ('a1','b1'),('a2','b2'),('a3','b3'),('a4','b4');";
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(3, insertStmt.getValuesList().size());
Assert.assertEquals(2, insertStmt.getValues().getValues().size());
Assert.assertEquals(2, insertStmt.getColumns().size());
Assert.assertEquals(1, statementList.size());
SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
stmt.accept(visitor);
String formatSql = //
"INSERT INTO t (a, b)" + //
"\nVALUES ('a1', 'b1')," + //
"\n('a2', 'b2')," + "\n('a3', 'b3')";
Assert.assertEquals(formatSql, SQLUtils.toSQLServerString(insertStmt));
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerParameterizedOutputVisitorTest method test_simple.
public void test_simple() throws Exception {
String sql = //
"select GEN_VAL " + //
"from ID_GENERATOR with (updlock, rowlock) " + //
"where GEN_NAME = 'T_USERS' AND FID = 3 AND FSTATE IN (1, 2, 3)";
String expect = //
"SELECT GEN_VAL" + //
"\nFROM ID_GENERATOR WITH (updlock, rowlock)" + "\nWHERE GEN_NAME = ?" + "\n\tAND FID = ?" + "\n\tAND FSTATE IN (?)";
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
String text = outputSqlServer(stmtList);
Assert.assertEquals(expect, text);
}
use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.
the class SQLServerInsertTest6 method test.
public void test() throws Exception {
String sql = "INSERT [dbo].[SurveyAnswer]([CustomerId], [QuestionId], [OptionId], [CreateTime], [LastUpdateTime]) VALUES (@0, @1, @2, @3, @4)";
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(1, insertStmt.getValuesList().size());
Assert.assertEquals(5, insertStmt.getValues().getValues().size());
Assert.assertEquals(5, insertStmt.getColumns().size());
Assert.assertEquals(1, statementList.size());
SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
stmt.accept(visitor);
String formatSql = //
"INSERT INTO [dbo].[SurveyAnswer] ([CustomerId], [QuestionId], [OptionId], [CreateTime], [LastUpdateTime])" + "\nVALUES (@0, @1, @2, @3, @4)";
Assert.assertEquals(formatSql, SQLUtils.toSQLServerString(insertStmt));
}
Aggregations