Search in sources :

Example 31 with Expression

use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.

the class InsertDeParser method deParse.

public void deParse(Insert insert) {
    buffer.append("INSERT ");
    if (insert.getModifierPriority() != null) {
        buffer.append(insert.getModifierPriority()).append(" ");
    }
    if (insert.isModifierIgnore()) {
        buffer.append("IGNORE ");
    }
    buffer.append("INTO ");
    buffer.append(insert.getTable().toString());
    if (insert.getColumns() != null) {
        buffer.append(" (");
        for (Iterator<Column> iter = insert.getColumns().iterator(); iter.hasNext(); ) {
            Column column = iter.next();
            buffer.append(column.getColumnName());
            if (iter.hasNext()) {
                buffer.append(", ");
            }
        }
        buffer.append(")");
    }
    if (insert.getItemsList() != null) {
        insert.getItemsList().accept(this);
    }
    if (insert.getSelect() != null) {
        buffer.append(" ");
        if (insert.isUseSelectBrackets()) {
            buffer.append("(");
        }
        if (insert.getSelect().getWithItemsList() != null) {
            buffer.append("WITH ");
            for (WithItem with : insert.getSelect().getWithItemsList()) {
                with.accept(selectVisitor);
            }
            buffer.append(" ");
        }
        insert.getSelect().getSelectBody().accept(selectVisitor);
        if (insert.isUseSelectBrackets()) {
            buffer.append(")");
        }
    }
    if (insert.isUseSet()) {
        buffer.append(" SET ");
        for (int i = 0; i < insert.getSetColumns().size(); i++) {
            Column column = insert.getSetColumns().get(i);
            column.accept(expressionVisitor);
            buffer.append(" = ");
            Expression expression = insert.getSetExpressionList().get(i);
            expression.accept(expressionVisitor);
            if (i < insert.getSetColumns().size() - 1) {
                buffer.append(", ");
            }
        }
    }
    if (insert.isUseDuplicate()) {
        buffer.append(" ON DUPLICATE KEY UPDATE ");
        for (int i = 0; i < insert.getDuplicateUpdateColumns().size(); i++) {
            Column column = insert.getDuplicateUpdateColumns().get(i);
            buffer.append(column.getFullyQualifiedName()).append(" = ");
            Expression expression = insert.getDuplicateUpdateExpressionList().get(i);
            expression.accept(expressionVisitor);
            if (i < insert.getDuplicateUpdateColumns().size() - 1) {
                buffer.append(", ");
            }
        }
    }
    if (insert.isReturningAllColumns()) {
        buffer.append(" RETURNING *");
    } else if (insert.getReturningExpressionList() != null) {
        buffer.append(" RETURNING ");
        for (Iterator<SelectExpressionItem> iter = insert.getReturningExpressionList().iterator(); iter.hasNext(); ) {
            buffer.append(iter.next().toString());
            if (iter.hasNext()) {
                buffer.append(", ");
            }
        }
    }
}
Also used : Column(net.sf.jsqlparser.schema.Column) Expression(net.sf.jsqlparser.expression.Expression) Iterator(java.util.Iterator) WithItem(net.sf.jsqlparser.statement.select.WithItem)

Example 32 with Expression

use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.

the class InsertDeParser method visit.

@Override
public void visit(ExpressionList expressionList) {
    buffer.append(" VALUES (");
    for (Iterator<Expression> iter = expressionList.getExpressions().iterator(); iter.hasNext(); ) {
        Expression expression = iter.next();
        expression.accept(expressionVisitor);
        if (iter.hasNext()) {
            buffer.append(", ");
        }
    }
    buffer.append(")");
}
Also used : Expression(net.sf.jsqlparser.expression.Expression)

Example 33 with Expression

use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.

the class ReplaceDeParser method visit.

@Override
public void visit(ExpressionList expressionList) {
    buffer.append("VALUES (");
    for (Iterator<Expression> iter = expressionList.getExpressions().iterator(); iter.hasNext(); ) {
        Expression expression = iter.next();
        expression.accept(expressionVisitor);
        if (iter.hasNext()) {
            buffer.append(", ");
        }
    }
    buffer.append(")");
}
Also used : Expression(net.sf.jsqlparser.expression.Expression)

Example 34 with Expression

use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.

the class UpsertDeParser method appendDuplicate.

private void appendDuplicate(Upsert upsert) {
    buffer.append(" ON DUPLICATE KEY UPDATE ");
    for (int i = 0; i < upsert.getDuplicateUpdateColumns().size(); i++) {
        Column column = upsert.getDuplicateUpdateColumns().get(i);
        buffer.append(column.getFullyQualifiedName()).append(" = ");
        Expression expression = upsert.getDuplicateUpdateExpressionList().get(i);
        expression.accept(expressionVisitor);
        if (i < upsert.getDuplicateUpdateColumns().size() - 1) {
            buffer.append(", ");
        }
    }
}
Also used : Column(net.sf.jsqlparser.schema.Column) Expression(net.sf.jsqlparser.expression.Expression)

Example 35 with Expression

use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.

the class CCJSqlParserUtilTest method testParseExpression2.

@Test
public void testParseExpression2() throws Exception {
    Expression result = CCJSqlParserUtil.parseExpression("2*(a+6.0)");
    assertEquals("2 * (a + 6.0)", result.toString());
    assertTrue(result instanceof Multiplication);
    Multiplication mult = (Multiplication) result;
    assertTrue(mult.getLeftExpression() instanceof LongValue);
    assertTrue(mult.getRightExpression() instanceof Parenthesis);
}
Also used : Multiplication(net.sf.jsqlparser.expression.operators.arithmetic.Multiplication) Parenthesis(net.sf.jsqlparser.expression.Parenthesis) Expression(net.sf.jsqlparser.expression.Expression) LongValue(net.sf.jsqlparser.expression.LongValue) Test(org.junit.Test)

Aggregations

Expression (net.sf.jsqlparser.expression.Expression)100 AndExpression (net.sf.jsqlparser.expression.operators.conditional.AndExpression)33 ArrayList (java.util.ArrayList)32 Test (org.junit.Test)30 BinaryExpression (net.sf.jsqlparser.expression.BinaryExpression)28 SignedExpression (net.sf.jsqlparser.expression.SignedExpression)26 ExpressionList (net.sf.jsqlparser.expression.operators.relational.ExpressionList)21 Column (net.sf.jsqlparser.schema.Column)19 CompiledSQLExpression (herddb.sql.expressions.CompiledSQLExpression)17 AlterExpression (net.sf.jsqlparser.statement.alter.AlterExpression)17 LikeExpression (net.sf.jsqlparser.expression.operators.relational.LikeExpression)15 StatementExecutionException (herddb.model.StatementExecutionException)14 NotExpression (net.sf.jsqlparser.expression.NotExpression)14 Table (net.sf.jsqlparser.schema.Table)14 CaseExpression (net.sf.jsqlparser.expression.CaseExpression)12 OrExpression (net.sf.jsqlparser.expression.operators.conditional.OrExpression)12 Column (herddb.model.Column)11 TimeKeyExpression (net.sf.jsqlparser.expression.TimeKeyExpression)11 InExpression (net.sf.jsqlparser.expression.operators.relational.InExpression)11 Function (net.sf.jsqlparser.expression.Function)10