use of com.developmentontheedge.sql.format.DbmsTransformer in project be5 by DevelopmentOnTheEdge.
the class Project method translateSQL.
/**
* Try to translate the SQL query to the current DBMS using com.developmentontheedge.sql
* @param sql
* @return
*/
public String translateSQL(String sql) {
if (beSQL > 0) {
if (--beSQL == 0)
reconfigureFreemarker();
}
if (sqlParser == null) {
throw new IllegalStateException("translateSQL was called without enterSQL");
}
sqlParser.parse(sql);
List<String> messages = sqlParser.getMessages();
if (!messages.isEmpty()) {
throw new IllegalArgumentException(("SQL cannot be parsed:\nQuery:" + sql + "\nErrors: " + String.join("\n", messages)).replace("\r", "").replace("\n", System.lineSeparator()));
}
AstStart ast = sqlParser.getStartNode();
if (databaseSystem != Rdbms.BESQL) {
new MacroExpander().expandMacros(ast);
Dbms dbms = databaseSystem == null ? Dbms.POSTGRESQL : Dbms.valueOf(databaseSystem.name());
DbmsTransformer dbmsTransformer = new Context(dbms).getDbmsTransformer();
dbmsTransformer.setParserContext(sqlParser.getContext());
dbmsTransformer.transformAst(ast);
}
return ast.format();
}
Aggregations