Start adding DISTINCT support to SELECT.
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@949600 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -278,6 +278,7 @@ private SQLView View():
|
||||
private SQLSelect Select():
|
||||
{
|
||||
Integer i;
|
||||
boolean isDistinct = false;
|
||||
List<OrderByItem> orderBy = null;
|
||||
List<String> groupBy = null;
|
||||
Map<String, FieldDef> fieldDefs = FastMap.newInstance();
|
||||
@@ -289,7 +290,7 @@ private SQLSelect Select():
|
||||
int offset = -1, limit = -1;
|
||||
}
|
||||
{
|
||||
<SELECT> (
|
||||
<SELECT> (<DISTINCT> { isDistinct = true; })? (
|
||||
FieldDef(fieldDefs, fieldAlls, fieldAllAliases)
|
||||
( <COMMA> FieldDef(fieldDefs, fieldAlls, fieldAllAliases) )*
|
||||
)
|
||||
@@ -301,7 +302,7 @@ private SQLSelect Select():
|
||||
( <ORDER> <BY> orderBy=OrderByList() )?
|
||||
( <OFFSET> offset=Integer() )?
|
||||
( <LIMIT> limit=Integer() )?
|
||||
{ return new SQLSelect(fieldAlls, fieldDefs, table, relations, whereCondition, havingCondition, groupBy, orderBy, offset, limit); }
|
||||
{ return new SQLSelect(isDistinct, fieldAlls, fieldDefs, table, relations, whereCondition, havingCondition, groupBy, orderBy, offset, limit); }
|
||||
}
|
||||
|
||||
private void Relation(Map<String, Relation> relations):
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import org.ofbiz.base.util.StringUtil;
|
||||
|
||||
public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSource {
|
||||
private final boolean isDistinct;
|
||||
private final List<FieldAll> fieldAlls;
|
||||
private final Map<String, FieldDef> fieldDefs;
|
||||
private final Table table;
|
||||
@@ -38,7 +39,8 @@ public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSo
|
||||
private final List<OrderByItem> orderBy;
|
||||
private final List<String> groupBy;
|
||||
|
||||
public SQLSelect(List<FieldAll> fieldAlls, Map<String, FieldDef> fieldDefs, Table table, Map<String, Relation> relations, Condition whereCondition, Condition havingCondition, List<String> groupBy, List<OrderByItem> orderBy, int offset, int limit) {
|
||||
public SQLSelect(boolean isDistinct, List<FieldAll> fieldAlls, Map<String, FieldDef> fieldDefs, Table table, Map<String, Relation> relations, Condition whereCondition, Condition havingCondition, List<String> groupBy, List<OrderByItem> orderBy, int offset, int limit) {
|
||||
this.isDistinct = isDistinct;
|
||||
this.fieldAlls = fieldAlls;
|
||||
this.fieldDefs = fieldDefs;
|
||||
this.table = table;
|
||||
@@ -55,6 +57,10 @@ public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSo
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
public boolean getIsDistinct() {
|
||||
return isDistinct;
|
||||
}
|
||||
|
||||
public Collection<FieldAll> getFieldAlls() {
|
||||
return fieldAlls;
|
||||
}
|
||||
@@ -97,6 +103,9 @@ public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSo
|
||||
|
||||
public StringBuilder appendTo(StringBuilder sb) {
|
||||
sb.append("SELECT");
|
||||
if (isDistinct) {
|
||||
sb.append(" DISTINCT");
|
||||
}
|
||||
StringUtil.appendTo(sb, fieldAlls, " ", null, ",");
|
||||
if (!fieldAlls.isEmpty() && !fieldDefs.isEmpty()) {
|
||||
sb.append(',');
|
||||
|
||||
Reference in New Issue
Block a user