Search in sources :

Example 1 with SQLCommentRemoveConverter

use of com.varsql.core.pattern.convert.SQLCommentRemoveConverter in project varsql by varsqlinfo.

the class VarsqlFormatterUtil method formatResponseResult.

public static ResponseResult formatResponseResult(String sql, DBType dbType, FORMAT_TYPE format_type) {
    ResponseResult result = new ResponseResult();
    String resultSql = "";
    sql = new SQLCommentRemoveConverter().convert(sql, dbType);
    if (format_type.equals(FORMAT_TYPE.VARSQL)) {
        resultSql = new VarsqlFormatterImpl().execute(sql);
    // resultSql = SqlFormatter.format(sql);
    } else {
        try {
            resultSql = com.varsql.core.sql.util.SQLParserUtils.getParserString(sql, dbType);
        } catch (Exception e) {
            resultSql = new VarsqlFormatterImpl().execute(sql);
            result.setMessage(e.getMessage());
        }
    }
    // resultSql = Native2Ascii.asciiToNative(resultSql);
    result.setItemOne(resultSql + BlankConstants.NEW_LINE);
    return result;
}
Also used : ResponseResult(com.vartech.common.app.beans.ResponseResult) SQLCommentRemoveConverter(com.varsql.core.pattern.convert.SQLCommentRemoveConverter)

Example 2 with SQLCommentRemoveConverter

use of com.varsql.core.pattern.convert.SQLCommentRemoveConverter in project varsql by varsqlinfo.

the class VarsqlFormatterUtilTest method test.

@Test
void test() {
    String ugly_sql_code = getResourceContent("/query/formatTestQuery.txt");
    String str = new SQLCommentRemoveConverter().convert(ugly_sql_code, DBType.ORACLE);
    String result = VarsqlFormatterUtil.formatResponseResult(str, DBType.OTHER, FORMAT_TYPE.VARSQL).getItem();
    System.out.println(result);
}
Also used : SQLCommentRemoveConverter(com.varsql.core.pattern.convert.SQLCommentRemoveConverter) Test(org.junit.jupiter.api.Test) BaseTest(com.varsql.core.test.BaseTest)

Aggregations

SQLCommentRemoveConverter (com.varsql.core.pattern.convert.SQLCommentRemoveConverter)2 BaseTest (com.varsql.core.test.BaseTest)1 ResponseResult (com.vartech.common.app.beans.ResponseResult)1 Test (org.junit.jupiter.api.Test)1