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(", ");
}
}
}
}
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(")");
}
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(")");
}
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(", ");
}
}
}
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);
}
Aggregations