diff --git a/src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java b/src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java index 42a09abc4..6b529eae3 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java @@ -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; @@ -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 selectItems; private Table into; @@ -48,7 +48,7 @@ public class PlainSelect implements SelectBody { /** * The {@link FromItem} in this query - * + * * @return the {@link FromItem} */ public FromItem getFromItem() { @@ -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 getSelectItems() { @@ -90,7 +91,7 @@ public void setWhere(Expression where) { /** * The list of {@link Join}s - * + * * @return the list of {@link Join}s */ public List getJoins() { @@ -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 getGroupByColumnReferences() { @@ -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 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 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; } @@ -210,14 +213,13 @@ 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) { @@ -225,15 +227,12 @@ public static String getStringList(List list) { } /** - * 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) { diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java index d48c4d1eb..73de347ee 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java @@ -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); } diff --git a/src/test/java/net/sf/jsqlparser/test/select/SelectTest.java b/src/test/java/net/sf/jsqlparser/test/select/SelectTest.java index 221216a91..8bcf39b76 100644 --- a/src/test/java/net/sf/jsqlparser/test/select/SelectTest.java +++ b/src/test/java/net/sf/jsqlparser/test/select/SelectTest.java @@ -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); }