use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class ExportParameterInTest method test_exportParameter.
public void test_exportParameter() throws Exception {
String sql = "select * from t_user where oid = '102' and uid in (1, 2, 3)";
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
assertEquals(1, stmtList.size());
SQLStatement stmt = stmtList.get(0);
StringBuilder out = new StringBuilder();
List<Object> parameters = new ArrayList<Object>();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, dbType);
visitor.setParameterized(true);
visitor.setParameterizedMergeInList(true);
visitor.setParameters(parameters);
stmt.accept(visitor);
System.out.println(out);
System.out.println(JSON.toJSONString(parameters));
restore(out.toString(), parameters);
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class ExportParameterShardingTest method test_exportParameter.
public void test_exportParameter() throws Exception {
String sql = "select * from t_user_0000 where oid = 1001";
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
assertEquals(1, stmtList.size());
SQLStatement stmt = stmtList.get(0);
StringBuilder out = new StringBuilder();
List<Object> parameters = new ArrayList<Object>();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, dbType);
visitor.setParameterized(true);
visitor.setParameterizedMergeInList(true);
visitor.setParameters(parameters);
stmt.accept(visitor);
System.out.println(out);
System.out.println(JSON.toJSONString(parameters));
String restoredSql = restore(out.toString(), parameters);
assertEquals("SELECT *\n" + "FROM t_user_0000\n" + "WHERE oid = 1001", restoredSql);
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class MTSParserTest method test_mts_2.
public void test_mts_2() throws Exception {
String sql = " savepoInt `select`";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("SAVEPOINT `select`", output);
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class MTSParserTest method test_lockTable.
public void test_lockTable() throws Exception {
String sql = "LOCK TABLES t1 READ;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("LOCK TABLES t1 READ", output);
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class MTSParserTest method test_mts_3.
public void test_mts_3() throws Exception {
String sql = "Release sAVEPOINT xx ";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("RELEASE SAVEPOINT xx", output);
}
Aggregations