use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.
the class MySqlParameterizedOutputVisitorTest_18 method test_for_parameterize.
public void test_for_parameterize() throws Exception {
final DbType dbType = JdbcConstants.MYSQL;
String sql = "insert into `t_n_0021` ( " + "`f0`, `f1`, `f2`, `f3`, `f4`" + ", `f5`, `f6`, `f7`, `f8`, `f9`" + ", `f10`, `f11`, `f12`, `f13`, `f14`" + ", `f15`) " + "values ( NOW(), NOW(), 123, 'abc', 'abd'" + ", 'tair:ldbcount:808', 0.0, 2.0, 0, 251, 0, '172.29.60.62', 2, 1483686655818, 12, 0);";
String psql = ParameterizedOutputVisitorUtils.parameterize(sql, dbType);
assertEquals("INSERT INTO t_n (`f0`, `f1`, `f2`, `f3`, `f4`\n" + "\t, `f5`, `f6`, `f7`, `f8`, `f9`\n" + "\t, `f10`, `f11`, `f12`, `f13`, `f14`\n" + "\t, `f15`)\n" + "VALUES (NOW(), NOW(), ?, ?, ?\n" + "\t, ?, ?, ?, ?, ?\n" + "\t, ?, ?, ?, ?, ?\n" + "\t, ?);", psql);
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
List<SQLStatement> stmtList = parser.parseStatementList();
StringBuilder out = new StringBuilder();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
List<Object> parameters = new ArrayList<Object>();
visitor.setParameterized(true);
visitor.setParameterizedMergeInList(true);
visitor.setParameters(parameters);
visitor.setExportTables(true);
/*visitor.setPrettyFormat(false);*/
SQLStatement stmt = stmtList.get(0);
stmt.accept(visitor);
// System.out.println(parameters);
assertEquals(14, parameters.size());
StringBuilder buf = new StringBuilder();
SQLASTOutputVisitor visitor1 = SQLUtils.createOutputVisitor(buf, dbType);
visitor1.setParameters(visitor.getParameters());
stmt.accept(visitor1);
assertEquals("INSERT INTO `t_n_0021` (`f0`, `f1`, `f2`, `f3`, `f4`\n" + "\t, `f5`, `f6`, `f7`, `f8`, `f9`\n" + "\t, `f10`, `f11`, `f12`, `f13`, `f14`\n" + "\t, `f15`)\n" + "VALUES (NOW(), NOW(), 123, 'abc', 'abd'\n" + "\t, 'tair:ldbcount:808', 0.0, 2.0, 0, 251\n" + "\t, 0, '172.29.60.62', 2, 1483686655818, 12\n" + "\t, 0);", buf.toString());
}
use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.
the class MySqlParameterizedOutputVisitorTest_21 method test_for_parameterize.
public void test_for_parameterize() throws Exception {
final DbType dbType = JdbcConstants.MYSQL;
String sql = "select `a_entry`.`id` from `a_entry`";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
List<SQLStatement> stmtList = parser.parseStatementList();
StringBuilder out = new StringBuilder();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
List<Object> parameters = new ArrayList<Object>();
visitor.setParameterized(true);
visitor.setParameterizedMergeInList(true);
visitor.setParameters(parameters);
visitor.setExportTables(true);
/*visitor.setPrettyFormat(false);*/
SQLStatement stmt = stmtList.get(0);
stmt.accept(visitor);
// System.out.println(parameters);
assertEquals(0, parameters.size());
StringBuilder buf = new StringBuilder();
SQLASTOutputVisitor visitor1 = SQLUtils.createOutputVisitor(buf, dbType);
visitor1.addTableMapping("a_entry", "a_entry_2664");
visitor1.setParameters(visitor.getParameters());
stmt.accept(visitor1);
assertEquals("SELECT a_entry_2664.`id`\n" + "FROM a_entry_2664", buf.toString());
}
use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.
the class MySqlParameterizedOutputVisitorTest_54_or method test_for_parameterize.
public void test_for_parameterize() throws Exception {
final DbType dbType = JdbcConstants.MYSQL;
String sql = "SELECT r.id, r.plugin_rule_key as \"ruleKey\", r.plugin_name as \"repositoryKey\", r.description, r.description_format as \"descriptionFormat\", r.status, r.name, r.plugin_config_key as \"configKey\", r.priority as \"severity\", r.is_template as \"isTemplate\", r.language as \"language\", r.template_id as \"templateId\", r.note_data as \"noteData\", r.note_user_login as \"noteUserLogin\", r.note_created_at as \"noteCreatedAt\", r.note_updated_at as \"noteUpdatedAt\", r.remediation_function as \"remediationFunction\", r.def_remediation_function as \"defRemediationFunction\", r.remediation_gap_mult as \"remediationGapMultiplier\", r.def_remediation_gap_mult as \"defRemediationGapMultiplier\", r.remediation_base_effort as \"remediationBaseEffort\", r.def_remediation_base_effort as \"defRemediationBaseEffort\", r.gap_description as \"gapDescription\", r.tags as \"tagsField\", r.system_tags as \"systemTagsField\", r.rule_type as \"type\", r.created_at as \"createdAt\", r.updated_at as \"updatedAt\" FROM rules r WHERE (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?) or (r.plugin_name=? and r.plugin_rule_key=?)";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement statement = stmtList.get(0);
StringBuilder out = new StringBuilder();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
List<Object> parameters = new ArrayList<Object>();
visitor.setParameterized(true);
visitor.setParameterizedMergeInList(true);
visitor.setParameters(parameters);
/*visitor.setPrettyFormat(false);*/
statement.accept(visitor);
/* JSONArray array = new JSONArray();
for(String table : visitor.getTables()){
array.add(table.replaceAll("`",""));
}*/
String psql = out.toString();
System.out.println(psql);
assertEquals("SELECT r.id, r.plugin_rule_key AS \"ruleKey\", r.plugin_name AS \"repositoryKey\", r.description, r.description_format AS \"descriptionFormat\"\n" + "\t, r.status, r.name, r.plugin_config_key AS \"configKey\", r.priority AS \"severity\", r.is_template AS \"isTemplate\"\n" + "\t, r.language AS \"language\", r.template_id AS \"templateId\", r.note_data AS \"noteData\", r.note_user_login AS \"noteUserLogin\", r.note_created_at AS \"noteCreatedAt\"\n" + "\t, r.note_updated_at AS \"noteUpdatedAt\", r.remediation_function AS \"remediationFunction\", r.def_remediation_function AS \"defRemediationFunction\", r.remediation_gap_mult AS \"remediationGapMultiplier\", r.def_remediation_gap_mult AS \"defRemediationGapMultiplier\"\n" + "\t, r.remediation_base_effort AS \"remediationBaseEffort\", r.def_remediation_base_effort AS \"defRemediationBaseEffort\", r.gap_description AS \"gapDescription\", r.tags AS \"tagsField\", r.system_tags AS \"systemTagsField\"\n" + "\t, r.rule_type AS \"type\", r.created_at AS \"createdAt\", r.updated_at AS \"updatedAt\"\n" + "FROM rules r\n" + "WHERE (r.plugin_name = ?\n" + "\t\tAND r.plugin_rule_key = ?)\n" + "\tOR (r.plugin_name = ?\n" + "\t\tAND r.plugin_rule_key = ?)", psql);
}
use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.
the class MySqlParameterizedOutputVisitorTest_36 method test_for_parameterize.
public void test_for_parameterize() throws Exception {
final DbType dbType = JdbcConstants.MYSQL;
String sql = "INSERT INTO v_j (jb) VALUES (0x7801848fbd6ec23014465f057986c4ffc69150972e0c1dd9bc5cdbd7c56d8028762221c4bbd72addbb1e9def48df832c399281ecb9a4865345c996ac39e2ed743abe376e434cda0a8b7b26920908c6701e64a45a29c3c137bdde272403fbdbb5cdc391922b1ea323c3866d37ee55fc88aa01f76fd29167ab0618470fe1fb348f2d79ae751afafe8cf7dcc11273dd4108584a1731c132d60ec6ecc1c32e5f43b7e6a9e0bce2dcafac87a5de7e0fcd589af856f3054b85cb7460d20a6194e4ca2d9472fd75f3391e446c3c498d7b11a5e7009c098d946a4941614a2fb7e4cfeb01020fe0ad899602a34c09ce2c9388497903d26bf2fc090000ffff01196b1f)";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement statement = stmtList.get(0);
StringBuilder out = new StringBuilder();
// List<Object> parameters = new ArrayList<Object>();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
visitor.setParameterized(true);
visitor.setParameterizedMergeInList(true);
// visitor.setParameters(parameters);
visitor.setExportTables(true);
visitor.setPrettyFormat(false);
statement.accept(visitor);
assertEquals("INSERT INTO v_j (jb) VALUES (?)", out.toString());
}
use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.
the class MySqlParameterizedOutputVisitorTest_22 method test_for_parameterize.
public void test_for_parameterize() throws Exception {
final DbType dbType = JdbcConstants.MYSQL;
String sql = "/* 0bba613214845441110397435e/0.4.6.25// */select `f`.`id`,`f`.`biz_id`,`f`.`user_id`,`f`.`file_name`,`f`.`parent_id`,`f`.`length`,`f`.`type`,`f`.`stream_key`,`f`.`biz_status`,`f`.`mark`,`f`.`content_modified`,`f`.`status`,`f`.`gmt_create`,`f`.`gmt_modified`,`f`.`md5`,`f`.`extra_str1`,`f`.`extra_str2`,`f`.`extra_str3`,`f`.`extra_num1`,`f`.`extra_num2`,`f`.`extra_num3`,`f`.`safe`,`f`.`open_status`,`f`.`inner_mark`,`f`.`sys_extra`,`f`.`feature`,`f`.`domain_option`,`f`.`version`,`f`.`reference_type`,`f`.`dentry_type`,`f`.`space_id`,`f`.`extension`,`f`.`creator_id`,`f`.`modifier_id`,`f`.`store_type`,`f`.`link_mark`,`f`.`content_type` from ( select `vfs_dentry_2664`.`id` from `vfs_dentry_2664` FORCE INDEX (idx_gmt) where ((`vfs_dentry_2664`.`extra_str1` = '97d45a25df387b4460e5b4151daeb452') AND (`vfs_dentry_2664`.`biz_id` = 62) AND (`vfs_dentry_2664`.`status` = 0) AND (`vfs_dentry_2664`.`user_id` = '11168360') AND (`vfs_dentry_2664`.`dentry_type` = 1)) limit 0,50 ) `t` join `vfs_dentry_2664` `f` on `t`.`id` = `f`.`id` where ((`t`.`id` = `f`.`id`) AND (`f`.`user_id` = 11168360))";
String psql = ParameterizedOutputVisitorUtils.parameterize(sql, dbType);
assertEquals("SELECT `f`.`id`, `f`.`biz_id`, `f`.`user_id`, `f`.`file_name`, `f`.`parent_id`\n" + "\t, `f`.`length`, `f`.`type`, `f`.`stream_key`, `f`.`biz_status`, `f`.`mark`\n" + "\t, `f`.`content_modified`, `f`.`status`, `f`.`gmt_create`, `f`.`gmt_modified`, `f`.`md5`\n" + "\t, `f`.`extra_str1`, `f`.`extra_str2`, `f`.`extra_str3`, `f`.`extra_num1`, `f`.`extra_num2`\n" + "\t, `f`.`extra_num3`, `f`.`safe`, `f`.`open_status`, `f`.`inner_mark`, `f`.`sys_extra`\n" + "\t, `f`.`feature`, `f`.`domain_option`, `f`.`version`, `f`.`reference_type`, `f`.`dentry_type`\n" + "\t, `f`.`space_id`, `f`.`extension`, `f`.`creator_id`, `f`.`modifier_id`, `f`.`store_type`\n" + "\t, `f`.`link_mark`, `f`.`content_type`\n" + "FROM (\n" + "\tSELECT vfs_dentry.`id`\n" + "\tFROM vfs_dentry FORCE INDEX (idx_gmt)\n" + "\tWHERE vfs_dentry.`extra_str1` = ?\n" + "\t\tAND vfs_dentry.`biz_id` = ?\n" + "\t\tAND vfs_dentry.`status` = ?\n" + "\t\tAND vfs_dentry.`user_id` = ?\n" + "\t\tAND vfs_dentry.`dentry_type` = ?\n" + "\tLIMIT ?, ?\n" + ") `t`\n" + "\tJOIN vfs_dentry `f` ON `t`.`id` = `f`.`id`\n" + "WHERE `t`.`id` = `f`.`id`\n" + "\tAND `f`.`user_id` = ?", psql);
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(psql, dbType);
List<SQLStatement> stmtList = parser.parseStatementList();
StringBuilder out = new StringBuilder();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
List<Object> parameters = new ArrayList<Object>();
visitor.setParameterized(true);
visitor.setParameterizedMergeInList(true);
visitor.setParameters(parameters);
visitor.setExportTables(true);
/*visitor.setPrettyFormat(false);*/
SQLStatement stmt = stmtList.get(0);
stmt.accept(visitor);
// System.out.println(parameters);
assertEquals(0, parameters.size());
StringBuilder buf = new StringBuilder();
SQLASTOutputVisitor visitor1 = SQLUtils.createOutputVisitor(buf, dbType);
visitor1.addTableMapping("vfs_dentry", "vfs_dentry_001");
visitor1.setParameters(visitor.getParameters());
stmt.accept(visitor1);
assertEquals("SELECT `f`.`id`, `f`.`biz_id`, `f`.`user_id`, `f`.`file_name`, `f`.`parent_id`\n" + "\t, `f`.`length`, `f`.`type`, `f`.`stream_key`, `f`.`biz_status`, `f`.`mark`\n" + "\t, `f`.`content_modified`, `f`.`status`, `f`.`gmt_create`, `f`.`gmt_modified`, `f`.`md5`\n" + "\t, `f`.`extra_str1`, `f`.`extra_str2`, `f`.`extra_str3`, `f`.`extra_num1`, `f`.`extra_num2`\n" + "\t, `f`.`extra_num3`, `f`.`safe`, `f`.`open_status`, `f`.`inner_mark`, `f`.`sys_extra`\n" + "\t, `f`.`feature`, `f`.`domain_option`, `f`.`version`, `f`.`reference_type`, `f`.`dentry_type`\n" + "\t, `f`.`space_id`, `f`.`extension`, `f`.`creator_id`, `f`.`modifier_id`, `f`.`store_type`\n" + "\t, `f`.`link_mark`, `f`.`content_type`\n" + "FROM (\n" + "\tSELECT vfs_dentry_001.`id`\n" + "\tFROM vfs_dentry_001 FORCE INDEX (idx_gmt)\n" + "\tWHERE vfs_dentry_001.`extra_str1` = ?\n" + "\t\tAND vfs_dentry_001.`biz_id` = ?\n" + "\t\tAND vfs_dentry_001.`status` = ?\n" + "\t\tAND vfs_dentry_001.`user_id` = ?\n" + "\t\tAND vfs_dentry_001.`dentry_type` = ?\n" + "\tLIMIT ?, ?\n" + ") `t`\n" + "\tJOIN vfs_dentry_001 `f` ON `t`.`id` = `f`.`id`\n" + "WHERE `t`.`id` = `f`.`id`\n" + "\tAND `f`.`user_id` = ?", buf.toString());
}
Aggregations