Search in sources :

Example 1 with Unparsed

use of org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Unparsed in project scout.rt by eclipse.

the class SqlFormatter method formatStatement.

private void formatStatement(Statement stm, FormatContext ctx) {
    if (stm != null) {
        for (IToken t : stm.getChildren()) {
            if (t instanceof Statement) {
                formatStatement((Statement) t, ctx);
            } else if (t instanceof SingleStatement) {
                formatSingleStatement((SingleStatement) t, ctx);
            } else if (t instanceof BracketExpr) {
                formatBracketExpr((BracketExpr) t, ctx);
            } else if (t instanceof UnionToken) {
                formatDefault(t, ctx);
                ctx.println();
            } else if (t instanceof Unparsed) {
                ctx.println("*** UNPARSED ***");
                formatDefault(t, ctx);
                ctx.println();
            } else {
                formatDefault(t, ctx);
            }
        }
    }
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken) Statement(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Statement) SingleStatement(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.SingleStatement) Unparsed(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Unparsed) SingleStatement(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.SingleStatement) UnionToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.UnionToken) BracketExpr(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.BracketExpr)

Example 2 with Unparsed

use of org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Unparsed in project scout.rt by eclipse.

the class SqlParser method parse.

public Statement parse(String s) {
    ParseContext ctx = new ParseContext();
    List<IToken> list = tokenize(s, ctx);
    Statement stm = parseStatement(list, ctx);
    // sometimes sql is wrapped into brackets
    if (stm == null) {
        ctx = new ParseContext();
        list = tokenize(s, ctx);
        BracketExpr be = parseBracketExpr(list, ctx);
        if (be != null) {
            for (IToken t : be.getChildren()) {
                if (t instanceof Statement) {
                    stm = (Statement) t;
                    break;
                }
            }
        }
    }
    if (list.size() > 0) {
        Unparsed up = new Unparsed();
        up.setText(flatten(list));
        if (stm == null) {
            stm = new Statement();
        }
        stm.addChild(up);
    }
    return stm;
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken) Statement(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Statement) SingleStatement(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.SingleStatement) Unparsed(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Unparsed) BracketExpr(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.BracketExpr)

Aggregations

BracketExpr (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.BracketExpr)2 IToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken)2 SingleStatement (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.SingleStatement)2 Statement (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Statement)2 Unparsed (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Unparsed)2 UnionToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.UnionToken)1