Search in sources :

Example 1 with SQLTextExpression

use of io.shardingjdbc.core.parsing.parser.expression.SQLTextExpression in project sharding-jdbc by shardingjdbc.

the class InsertSetClauseParser method parse.

/**
 * Parse insert set.
 *
 * @param insertStatement insert statement
 */
public void parse(final InsertStatement insertStatement) {
    if (!lexerEngine.skipIfEqual(getCustomizedInsertKeywords())) {
        return;
    }
    do {
        Column column = new Column(SQLUtil.getExactlyValue(lexerEngine.getCurrentToken().getLiterals()), insertStatement.getTables().getSingleTableName());
        lexerEngine.nextToken();
        lexerEngine.accept(Symbol.EQ);
        SQLExpression sqlExpression;
        if (lexerEngine.equalAny(Literals.INT)) {
            sqlExpression = new SQLNumberExpression(Integer.parseInt(lexerEngine.getCurrentToken().getLiterals()));
        } else if (lexerEngine.equalAny(Literals.FLOAT)) {
            sqlExpression = new SQLNumberExpression(Double.parseDouble(lexerEngine.getCurrentToken().getLiterals()));
        } else if (lexerEngine.equalAny(Literals.CHARS)) {
            sqlExpression = new SQLTextExpression(lexerEngine.getCurrentToken().getLiterals());
        } else if (lexerEngine.equalAny(DefaultKeyword.NULL)) {
            sqlExpression = new SQLIgnoreExpression(DefaultKeyword.NULL.name());
        } else if (lexerEngine.equalAny(Symbol.QUESTION)) {
            sqlExpression = new SQLPlaceholderExpression(insertStatement.getParametersIndex());
            insertStatement.increaseParametersIndex();
        } else {
            throw new UnsupportedOperationException("");
        }
        lexerEngine.nextToken();
        if (lexerEngine.equalAny(Symbol.COMMA, DefaultKeyword.ON, Assist.END)) {
            insertStatement.getConditions().add(new Condition(column, sqlExpression), shardingRule);
        } else {
            lexerEngine.skipUntil(Symbol.COMMA, DefaultKeyword.ON);
        }
    } while (lexerEngine.skipIfEqual(Symbol.COMMA));
}
Also used : SQLNumberExpression(io.shardingjdbc.core.parsing.parser.expression.SQLNumberExpression) Condition(io.shardingjdbc.core.parsing.parser.context.condition.Condition) SQLExpression(io.shardingjdbc.core.parsing.parser.expression.SQLExpression) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) SQLTextExpression(io.shardingjdbc.core.parsing.parser.expression.SQLTextExpression) SQLPlaceholderExpression(io.shardingjdbc.core.parsing.parser.expression.SQLPlaceholderExpression) SQLIgnoreExpression(io.shardingjdbc.core.parsing.parser.expression.SQLIgnoreExpression)

Aggregations

Column (io.shardingjdbc.core.parsing.parser.context.condition.Column)1 Condition (io.shardingjdbc.core.parsing.parser.context.condition.Condition)1 SQLExpression (io.shardingjdbc.core.parsing.parser.expression.SQLExpression)1 SQLIgnoreExpression (io.shardingjdbc.core.parsing.parser.expression.SQLIgnoreExpression)1 SQLNumberExpression (io.shardingjdbc.core.parsing.parser.expression.SQLNumberExpression)1 SQLPlaceholderExpression (io.shardingjdbc.core.parsing.parser.expression.SQLPlaceholderExpression)1 SQLTextExpression (io.shardingjdbc.core.parsing.parser.expression.SQLTextExpression)1