@@ -52,7 +52,7 @@ public void visit(PlainSelect plainSelect) {
5252 buffer .append ("SELECT " );
5353 Top top = plainSelect .getTop ();
5454 if (top != null )
55- top . toString ( );
55+ buffer . append ( top ). append ( " " );
5656 if (plainSelect .getDistinct () != null ) {
5757 buffer .append ("DISTINCT " );
5858 if (plainSelect .getDistinct ().getOnSelectItems () != null ) {
@@ -130,6 +130,9 @@ public void visit(Union union) {
130130 buffer .append (")" );
131131 if (iter .hasNext ()) {
132132 buffer .append (" UNION " );
133+ if (union .isAll ()){
134+ buffer .append ("ALL " );//should UNION be a BinaryExpression ?
135+ }
133136 }
134137
135138 }
@@ -146,9 +149,7 @@ public void visit(Union union) {
146149
147150 public void visit (OrderByElement orderBy ) {
148151 orderBy .getExpression ().accept (expressionVisitor );
149- if (orderBy .isAsc ())
150- buffer .append (" ASC" );
151- else
152+ if (!orderBy .isAsc ())
152153 buffer .append (" DESC" );
153154 }
154155
@@ -176,6 +177,10 @@ public void visit(SubSelect subSelect) {
176177 buffer .append ("(" );
177178 subSelect .getSelectBody ().accept (this );
178179 buffer .append (")" );
180+ String alias = subSelect .getAlias ();
181+ if (alias != null ){
182+ buffer .append (" AS " ).append (alias );
183+ }
179184 }
180185
181186 public void visit (Table tableName ) {
@@ -199,18 +204,12 @@ public void deparseOrderBy(List<OrderByElement> orderByElements) {
199204
200205 public void deparseLimit (Limit limit ) {
201206 // LIMIT n OFFSET skip
202- buffer .append (" LIMIT " );
203207 if (limit .isRowCountJdbcParameter ()) {
208+ buffer .append (" LIMIT " );
204209 buffer .append ("?" );
205210 } else if (limit .getRowCount () != 0 ) {
211+ buffer .append (" LIMIT " );
206212 buffer .append (limit .getRowCount ());
207- } else {
208- /*
209- * from mysql docs: For compatibility with PostgreSQL, MySQL also supports the LIMIT row_count OFFSET offset
210- * syntax. To retrieve all rows from a certain offset up to the end of the result set, you can use some
211- * large number for the second parameter.
212- */
213- buffer .append ("18446744073709551615" );
214213 }
215214
216215 if (limit .isOffsetJdbcParameter ()) {
@@ -240,7 +239,6 @@ public void setExpressionVisitor(ExpressionVisitor visitor) {
240239 public void visit (SubJoin subjoin ) {
241240 buffer .append ("(" );
242241 subjoin .getLeft ().accept (this );
243- buffer .append (" " );
244242 deparseJoin (subjoin .getJoin ());
245243 buffer .append (")" );
246244 }
@@ -251,20 +249,20 @@ public void deparseJoin(Join join) {
251249 else {
252250
253251 if (join .isRight ())
254- buffer .append ("RIGHT " );
252+ buffer .append (" RIGHT " );
255253 else if (join .isNatural ())
256- buffer .append ("NATURAL " );
254+ buffer .append (" NATURAL " );
257255 else if (join .isFull ())
258- buffer .append ("FULL " );
256+ buffer .append (" FULL " );
259257 else if (join .isLeft ())
260- buffer .append ("LEFT " );
258+ buffer .append (" LEFT " );
261259
262260 if (join .isOuter ())
263- buffer .append ("OUTER " );
261+ buffer .append (" OUTER " );
264262 else if (join .isInner ())
265- buffer .append ("INNER " );
263+ buffer .append (" INNER " );
266264
267- buffer .append ("JOIN " );
265+ buffer .append (" JOIN " );
268266
269267 }
270268
@@ -275,12 +273,12 @@ else if (join.isInner())
275273 join .getOnExpression ().accept (expressionVisitor );
276274 }
277275 if (join .getUsingColumns () != null ) {
278- buffer .append (" USING ( " );
276+ buffer .append (" USING (" );
279277 for (Iterator <Column > iterator = join .getUsingColumns ().iterator (); iterator .hasNext ();) {
280278 Column column = iterator .next ();
281279 buffer .append (column .getWholeColumnName ());
282280 if (iterator .hasNext ()) {
283- buffer .append (" , " );
281+ buffer .append (", " );
284282 }
285283 }
286284 buffer .append (")" );
0 commit comments