Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeParsers #1

Merged
merged 1 commit into from
Dec 2, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void visit(Division division) {
}

public void visit(DoubleValue doubleValue) {
buffer.append(doubleValue.getValue());
buffer.append(doubleValue.toString());

}

Expand Down Expand Up @@ -165,7 +165,10 @@ public void visit(JdbcParameter jdbcParameter) {

public void visit(LikeExpression likeExpression) {
visitBinaryExpression(likeExpression, " LIKE ");

String escape = likeExpression.getEscape();
if(escape!=null){
buffer.append(" ESCAPE '").append(escape).append('\'');
}
}

public void visit(ExistsExpression existsExpression) {
Expand Down Expand Up @@ -324,29 +327,32 @@ public void visit(TimeValue timeValue) {
public void visit(CaseExpression caseExpression) {
buffer.append("CASE ");
Expression switchExp = caseExpression.getSwitchExpression();
if (switchExp != null) {
if( switchExp != null ) {
switchExp.accept(this);
buffer.append(" ");
}

List<Expression> clauses = caseExpression.getWhenClauses();
for (Iterator<Expression> iter = clauses.iterator(); iter.hasNext();) {
Expression exp = iter.next();
for (Iterator<Expression> iter = caseExpression.getWhenClauses().iterator(); iter.hasNext();) {
Expression exp = (Expression) iter.next();
exp.accept(this);
}

Expression elseExp = caseExpression.getElseExpression();
if (elseExp != null) {
if( elseExp != null ) {
buffer.append("ELSE ");
elseExp.accept(this);
buffer.append(" ");
}

buffer.append(" END");
buffer.append("END");
}

public void visit(WhenClause whenClause) {
buffer.append(" WHEN ");
buffer.append("WHEN ");
whenClause.getWhenExpression().accept(this);
buffer.append(" THEN ");
whenClause.getThenExpression().accept(this);
buffer.append(" ");
}

public void visit(AllComparisonExpression allComparisonExpression) {
Expand Down
42 changes: 20 additions & 22 deletions src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void visit(PlainSelect plainSelect) {
buffer.append("SELECT ");
Top top = plainSelect.getTop();
if (top != null)
top.toString();
buffer.append(top).append(" ");
if (plainSelect.getDistinct() != null) {
buffer.append("DISTINCT ");
if (plainSelect.getDistinct().getOnSelectItems() != null) {
Expand Down Expand Up @@ -130,6 +130,9 @@ public void visit(Union union) {
buffer.append(")");
if (iter.hasNext()) {
buffer.append(" UNION ");
if(union.isAll()){
buffer.append("ALL ");//should UNION be a BinaryExpression ?
}
}

}
Expand All @@ -146,9 +149,7 @@ public void visit(Union union) {

public void visit(OrderByElement orderBy) {
orderBy.getExpression().accept(expressionVisitor);
if (orderBy.isAsc())
buffer.append(" ASC");
else
if (!orderBy.isAsc())
buffer.append(" DESC");
}

Expand Down Expand Up @@ -176,6 +177,10 @@ public void visit(SubSelect subSelect) {
buffer.append("(");
subSelect.getSelectBody().accept(this);
buffer.append(")");
String alias = subSelect.getAlias();
if(alias != null){
buffer.append(" AS ").append(alias);
}
}

public void visit(Table tableName) {
Expand All @@ -199,18 +204,12 @@ public void deparseOrderBy(List<OrderByElement> orderByElements) {

public void deparseLimit(Limit limit) {
// LIMIT n OFFSET skip
buffer.append(" LIMIT ");
if (limit.isRowCountJdbcParameter()) {
buffer.append(" LIMIT ");
buffer.append("?");
} else if (limit.getRowCount() != 0) {
buffer.append(" LIMIT ");
buffer.append(limit.getRowCount());
} else {
/*
* from mysql docs: For compatibility with PostgreSQL, MySQL also supports the LIMIT row_count OFFSET offset
* syntax. To retrieve all rows from a certain offset up to the end of the result set, you can use some
* large number for the second parameter.
*/
buffer.append("18446744073709551615");
}

if (limit.isOffsetJdbcParameter()) {
Expand Down Expand Up @@ -240,7 +239,6 @@ public void setExpressionVisitor(ExpressionVisitor visitor) {
public void visit(SubJoin subjoin) {
buffer.append("(");
subjoin.getLeft().accept(this);
buffer.append(" ");
deparseJoin(subjoin.getJoin());
buffer.append(")");
}
Expand All @@ -251,20 +249,20 @@ public void deparseJoin(Join join) {
else {

if (join.isRight())
buffer.append("RIGHT ");
buffer.append(" RIGHT");
else if (join.isNatural())
buffer.append("NATURAL ");
buffer.append(" NATURAL");
else if (join.isFull())
buffer.append("FULL ");
buffer.append(" FULL");
else if (join.isLeft())
buffer.append("LEFT ");
buffer.append(" LEFT");

if (join.isOuter())
buffer.append("OUTER ");
buffer.append(" OUTER");
else if (join.isInner())
buffer.append("INNER ");
buffer.append(" INNER");

buffer.append("JOIN ");
buffer.append(" JOIN ");

}

Expand All @@ -275,12 +273,12 @@ else if (join.isInner())
join.getOnExpression().accept(expressionVisitor);
}
if (join.getUsingColumns() != null) {
buffer.append(" USING ( ");
buffer.append(" USING (");
for (Iterator<Column> iterator = join.getUsingColumns().iterator(); iterator.hasNext();) {
Column column = iterator.next();
buffer.append(column.getWholeColumnName());
if (iterator.hasNext()) {
buffer.append(" ,");
buffer.append(", ");
}
}
buffer.append(")");
Expand Down
Loading