Search in sources :

Example 1 with ParsedSql

use of org.jdbi.v3.core.statement.ParsedSql in project jdbi by jdbi.

the class ColonPrefixSqlParser method internalParse.

private ParsedSql internalParse(String sql) throws IllegalArgumentException {
    ParsedSql.Builder parsedSql = ParsedSql.builder();
    ColonStatementLexer lexer = new ColonStatementLexer(new ANTLRStringStream(sql));
    Token t = lexer.nextToken();
    while (t.getType() != EOF) {
        switch(t.getType()) {
            case COMMENT:
            case LITERAL:
            case QUOTED_TEXT:
            case DOUBLE_QUOTED_TEXT:
                parsedSql.append(t.getText());
                break;
            case NAMED_PARAM:
                parsedSql.appendNamedParameter(t.getText().substring(1));
                break;
            case POSITIONAL_PARAM:
                parsedSql.appendPositionalParameter();
                break;
            case ESCAPED_TEXT:
                parsedSql.append(t.getText().substring(1));
                break;
            default:
                break;
        }
        t = lexer.nextToken();
    }
    return parsedSql.build();
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Token(org.antlr.runtime.Token) ColonStatementLexer(org.jdbi.v3.core.internal.lexer.ColonStatementLexer)

Example 2 with ParsedSql

use of org.jdbi.v3.core.statement.ParsedSql in project jdbi by jdbi.

the class HashPrefixSqlParser method internalParse.

private ParsedSql internalParse(final String sql) {
    ParsedSql.Builder parsedSql = ParsedSql.builder();
    HashStatementLexer lexer = new HashStatementLexer(new ANTLRStringStream(sql));
    Token t = lexer.nextToken();
    while (t.getType() != EOF) {
        switch(t.getType()) {
            case COMMENT:
            case LITERAL:
            case QUOTED_TEXT:
            case DOUBLE_QUOTED_TEXT:
                parsedSql.append(t.getText());
                break;
            case NAMED_PARAM:
                parsedSql.appendNamedParameter(t.getText().substring(1));
                break;
            case POSITIONAL_PARAM:
                parsedSql.appendPositionalParameter();
                break;
            case ESCAPED_TEXT:
                parsedSql.append(t.getText().substring(1));
                break;
            default:
                break;
        }
        t = lexer.nextToken();
    }
    return parsedSql.build();
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) HashStatementLexer(org.jdbi.v3.core.internal.lexer.HashStatementLexer) Token(org.antlr.runtime.Token)

Aggregations

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)2 Token (org.antlr.runtime.Token)2 ColonStatementLexer (org.jdbi.v3.core.internal.lexer.ColonStatementLexer)1 HashStatementLexer (org.jdbi.v3.core.internal.lexer.HashStatementLexer)1