Skip to content

Commit

Permalink
- make "select function" pass assertSqlCanBeParsedAndDeparsed
Browse files Browse the repository at this point in the history
  • Loading branch information
toben committed May 13, 2012
1 parent e22f5a3 commit 7a8bbbe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
75 changes: 37 additions & 38 deletions src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/

package net.sf.jsqlparser.statement.select;

import java.util.Iterator;
Expand All @@ -34,6 +33,7 @@
* The core of a "SELECT" statement (no UNION, no ORDER BY)
*/
public class PlainSelect implements SelectBody {

private Distinct distinct = null;
private List<SelectItem> selectItems;
private Table into;
Expand All @@ -48,7 +48,7 @@ public class PlainSelect implements SelectBody {

/**
* The {@link FromItem} in this query
*
*
* @return the {@link FromItem}
*/
public FromItem getFromItem() {
Expand All @@ -60,8 +60,9 @@ public Table getInto() {
}

/**
* The {@link SelectItem}s in this query (for example the A,B,C in "SELECT A,B,C")
*
* The {@link SelectItem}s in this query (for example the A,B,C in "SELECT
* A,B,C")
*
* @return a list of {@link SelectItem}s
*/
public List<SelectItem> getSelectItems() {
Expand Down Expand Up @@ -90,7 +91,7 @@ public void setWhere(Expression where) {

/**
* The list of {@link Join}s
*
*
* @return the list of {@link Join}s
*/
public List<Join> getJoins() {
Expand Down Expand Up @@ -146,8 +147,9 @@ public void setHaving(Expression expression) {
}

/**
* A list of {@link Expression}s of the GROUP BY clause. It is null in case there is no GROUP BY clause
*
* A list of {@link Expression}s of the GROUP BY clause. It is null in case
* there is no GROUP BY clause
*
* @return a list of {@link Expression}s
*/
public List<Expression> getGroupByColumnReferences() {
Expand All @@ -165,25 +167,26 @@ public String toString() {
sql += ((distinct != null) ? "" + distinct + " " : "");
sql += ((top != null) ? "" + top + " " : "");
sql += getStringList(selectItems);
sql += " FROM " + fromItem;
if (joins != null) {
Iterator<Join> it = joins.iterator();
while (it.hasNext()) {
Join join = it.next();
if (join.isSimple()) {
sql += ", " + join;
} else {
sql += " " + join;
if (fromItem != null) {
sql += " FROM " + fromItem;
if (joins != null) {
Iterator<Join> it = joins.iterator();
while (it.hasNext()) {
Join join = it.next();
if (join.isSimple()) {
sql += ", " + join;
} else {
sql += " " + join;
}
}
}
// sql += getFormatedList(joins, "", false, false);
sql += ((where != null) ? " WHERE " + where : "");
sql += getFormatedList(groupByColumnReferences, "GROUP BY");
sql += ((having != null) ? " HAVING " + having : "");
sql += orderByToString(orderByElements);
sql += ((limit != null) ? limit + "" : "");
}
// sql += getFormatedList(joins, "", false, false);
sql += ((where != null) ? " WHERE " + where : "");
sql += getFormatedList(groupByColumnReferences, "GROUP BY");
sql += ((having != null) ? " HAVING " + having : "");
sql += orderByToString(orderByElements);
sql += ((limit != null) ? limit + "" : "");

return sql;
}

Expand All @@ -210,30 +213,26 @@ public static String getFormatedList(List<?> list, String expression, boolean us
}

/**
* List the toString out put of the objects in the List comma separated. If the List is null or empty an empty
* string is returned.
*
* List the toString out put of the objects in the List comma separated. If
* the List is null or empty an empty string is returned.
*
* The same as getStringList(list, true, false)
*
*
* @see #getStringList(List, boolean, boolean)
* @param list
* list of objects with toString methods
* @param list list of objects with toString methods
* @return comma separated list of the elements in the list
*/
public static String getStringList(List<?> list) {
return getStringList(list, true, false);
}

/**
* List the toString out put of the objects in the List that can be comma separated. If the List is null or empty an
* empty string is returned.
*
* @param list
* list of objects with toString methods
* @param useComma
* true if the list has to be comma separated
* @param useBrackets
* true if the list has to be enclosed in brackets
* List the toString out put of the objects in the List that can be comma
* separated. If the List is null or empty an empty string is returned.
*
* @param list list of objects with toString methods
* @param useComma true if the list has to be comma separated
* @param useBrackets true if the list has to be enclosed in brackets
* @return comma separated list of the elements in the list
*/
public static String getStringList(List<?> list, boolean useComma, boolean useBrackets) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ public void visit(PlainSelect plainSelect) {
}
}

buffer.append(" ");

if (plainSelect.getFromItem() != null) {
buffer.append("FROM ");
buffer.append(" FROM ");
plainSelect.getFromItem().accept(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public void testBitwise() throws JSQLParserException {
}

public void testSelectFunction() throws JSQLParserException {
String statement = "SELECT 1+2 AS sum";
String statement = "SELECT 1 + 2 AS sum";
assertSqlCanBeParsedAndDeparsed(statement);
}

Expand Down

0 comments on commit 7a8bbbe

Please sign in to comment.