Search in sources :

Example 36 with MySqlOutputVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor in project druid by alibaba.

the class SELECT_Syntax_Test method output.

private String output(List<SQLStatement> stmtList) {
    StringBuilder out = new StringBuilder();
    for (SQLStatement stmt : stmtList) {
        stmt.accept(new MySqlOutputVisitor(out));
        out.append(";");
    }
    return out.toString();
}
Also used : MySqlOutputVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 37 with MySqlOutputVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor in project druid by alibaba.

the class MySqlPerfMain method execMySql.

static String execMySql(String sql) {
    StringBuilder out = new StringBuilder();
    MySqlOutputVisitor visitor = new MySqlOutputVisitor(out);
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    // }
    return out.toString();
}
Also used : MySqlOutputVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 38 with MySqlOutputVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor in project druid by alibaba.

the class Issue_697 method test_for_issue.

public void test_for_issue() throws Exception {
    String sql = "insert into tag_rule_detail(id, gmt_create, gmt_modified, group_id, priority, rule_condition, rule_action) values(1010102, now(), now(), 10101, 0, 'flow=''trustLogin''', 'be:login,dev:pc, env:web, type:trust_login, from:$loginfrom, result:true') ;\n" + "insert into tag_rule_detail(id, gmt_create, gmt_modified, group_id, priority, rule_condition, rule_action) values(1010103, now(), now(), 10101, 0, 'flow=''Ctr''', 'be:login,dev:pc, env:web, type:ctr, from:$loginfrom, result:true') ;";
    String expected = "INSERT INTO tag_rule_detail (id, gmt_create, gmt_modified, group_id, priority" + "\n\t, rule_condition, rule_action)" + "\nVALUES (1010102, now(), now(), 10101, 0" + "\n\t, 'flow=''trustLogin''', 'be:login,dev:pc, env:web, type:trust_login, from:$loginfrom, result:true');" + "\nINSERT INTO tag_rule_detail (id, gmt_create, gmt_modified, group_id, priority" + "\n\t, rule_condition, rule_action)" + "\nVALUES (1010103, now(), now(), 10101, 0" + "\n\t, 'flow=''Ctr''', 'be:login,dev:pc, env:web, type:ctr, from:$loginfrom, result:true');\n";
    StringBuilder out = new StringBuilder();
    MySqlOutputVisitor visitor = new MySqlOutputVisitor(out);
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    for (SQLStatement statement : statementList) {
        statement.accept(visitor);
        visitor.print(";");
        visitor.println();
    }
    System.out.println(out.toString());
    Assert.assertEquals(expected, out.toString());
}
Also used : MySqlOutputVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 39 with MySqlOutputVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor in project druid by alibaba.

the class Bug_for_ruiyi method test_for_issue.

public void test_for_issue() throws Exception {
    String sql = "insert into icshall_guide(id,gmt_create,gmt_modified,subject,content,cat_id)" + "values (8,now(),now(),\"Why my payment is deducted incorrectly?/ Why my payment is deducted twice?\"," + "\"{\\\"id\\\":1,\\\"title\\\":\\\"Have you contacted your card issuer to double check instead of only checking online?\\\"," + "\\\"type\\\":\\\"START\\\"," + "\\\"currentLevel\\\":1," + "\\\"name\\\":\\\"name1\\\"," + "\\\"values\\\":[{\\\"id\\\":2," + "\\\"title\\\":\\\"Yes\\\"," + "\\\"type\\\":\\\"MIDWAY\\\"," + "\\\"currentLevel\\\":2," + "\\\"value\\\":1," + "\\\"childs\\\":[{\\\"id\\\":3," + "\\\"title\\\":\\\"If it is deducted twice, please contact the online service with the official bank statement.\\\"," + "\\\"type\\\":\\\"END\\\"," + "\\\"currentLevel\\\":3}]}," + "{\\\"id\\\":4," + "\\\"title\\\":\\\"No\\\"," + "\\\"type\\\":\\\"MIDWAY\\\"," + "\\\"currentLevel\\\":2," + "\\\"value\\\":1," + "\\\"childs\\\":[{\\\"id\\\":5," + "\\\"title\\\":\\\"Please contact your card issuer to double confirm.\\\"," + "\\\"type\\\":\\\"END\\\"," + "\\\"currentLevel\\\":3}]}]}\",607)";
    String expected = "INSERT INTO icshall_guide (id, gmt_create, gmt_modified, subject, content" + "\n\t, cat_id)" + "\nVALUES (8, now(), now(), 'Why my payment is deducted incorrectly?/ Why my payment is deducted twice?', '{\"id\":1,\"title\":\"Have you contacted your card issuer to double check instead of only checking online?\",\"type\":\"START\",\"currentLevel\":1,\"name\":\"name1\",\"values\":[{\"id\":2,\"title\":\"Yes\",\"type\":\"MIDWAY\",\"currentLevel\":2,\"value\":1,\"childs\":[{\"id\":3,\"title\":\"If it is deducted twice, please contact the online service with the official bank statement.\",\"type\":\"END\",\"currentLevel\":3}]},{\"id\":4,\"title\":\"No\",\"type\":\"MIDWAY\",\"currentLevel\":2,\"value\":1,\"childs\":[{\"id\":5,\"title\":\"Please contact your card issuer to double confirm.\",\"type\":\"END\",\"currentLevel\":3}]}]}'" + "\n\t, 607);\n";
    StringBuilder out = new StringBuilder();
    MySqlOutputVisitor visitor = new MySqlOutputVisitor(out);
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    for (SQLStatement statement : statementList) {
        statement.accept(visitor);
        visitor.print(";");
        visitor.println();
    }
    //System.out.println(out.toString());
    Assert.assertEquals(expected, out.toString());
}
Also used : MySqlOutputVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 40 with MySqlOutputVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor in project druid by alibaba.

the class MySqlParserResourceTest method output.

private String output(List<SQLStatement> stmtList) {
    StringBuilder out = new StringBuilder();
    MySqlOutputVisitor visitor = new MySqlOutputVisitor(out);
    for (SQLStatement stmt : stmtList) {
        stmt.accept(visitor);
    }
    return out.toString();
}
Also used : MySqlOutputVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

MySqlOutputVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor)61 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)60 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)20 SQLInListExpr (com.alibaba.druid.sql.ast.expr.SQLInListExpr)1 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)1 MySqlInsertStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement)1 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)1 AggregationColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.AggregationColumn)1 AggregationType (com.dangdang.ddframe.rdb.sharding.parser.result.merger.AggregationColumn.AggregationType)1