Revision 47167 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/expressionbuilder/formatters/Select.java
Select.java | ||
---|---|---|
37 | 37 |
private static final int LIMIT = 5; |
38 | 38 |
|
39 | 39 |
@Override |
40 |
public String format(Value function0) { |
|
41 |
Function function = (Function) function0; |
|
42 |
String tableName = (String) function.parameters().get(TABLE).toString(formatter); |
|
43 |
Value where = function.parameters().get(WHERE); |
|
44 |
Value order = function.parameters().get(ORDER); |
|
45 |
Value limit = function.parameters().get(LIMIT); |
|
46 |
Value order_mode = function.parameters().get(ORDER_MODE); |
|
40 |
public String format(Value function0) {
|
|
41 |
Function function = (Function) function0;
|
|
42 |
String tableName = (String) function.parameters().get(TABLE).toString(formatter);
|
|
43 |
Value where = function.parameters().get(WHERE);
|
|
44 |
Value order = function.parameters().get(ORDER);
|
|
45 |
Value limit = function.parameters().get(LIMIT);
|
|
46 |
Value order_mode = function.parameters().get(ORDER_MODE);
|
|
47 | 47 |
|
48 |
StringBuilder builder = new StringBuilder(); |
|
49 |
builder.append("(SELECT "); |
|
48 |
StringBuilder builder = new StringBuilder();
|
|
49 |
builder.append("(SELECT ");
|
|
50 | 50 |
|
51 |
try { |
|
52 |
Function columns = (Function) function.parameters().get(COLUMNS); |
|
53 |
if (!StringUtils.equalsIgnoreCase(((ExpressionBuilder.Function) columns).name(), FUNCTION_TUPLE)) { |
|
54 |
throw new IllegalArgumentException(); |
|
55 |
} |
|
56 |
if( columns.parameters().isEmpty() ) { |
|
57 |
builder.append("* "); |
|
58 |
} else { |
|
59 |
boolean needcomma = false; |
|
60 |
for (Value parameter : columns.parameters()) { |
|
61 |
if(needcomma) { |
|
62 |
builder.append(", "); |
|
63 |
} else { |
|
64 |
needcomma = true; |
|
65 |
} |
|
66 |
builder.append(parameter.toString(formatter)); |
|
51 |
try { |
|
52 |
Value c = function.parameters().get(COLUMNS); |
|
53 |
if (c instanceof ExpressionBuilder.Variable) { |
|
54 |
builder.append('"'); |
|
55 |
builder.append(((ExpressionBuilder.Variable)c).name()); |
|
56 |
builder.append("\" "); |
|
57 |
} else { |
|
58 |
Function columns = (Function) c; |
|
59 |
if (!StringUtils.equalsIgnoreCase(((ExpressionBuilder.Function) columns).name(), FUNCTION_TUPLE)) { |
|
60 |
throw new IllegalArgumentException(); |
|
61 |
} |
|
62 |
if (columns.parameters().isEmpty()) { |
|
63 |
builder.append("* "); |
|
64 |
} else { |
|
65 |
boolean needcomma = false; |
|
66 |
for (Value parameter : columns.parameters()) { |
|
67 |
if (needcomma) { |
|
68 |
builder.append(", "); |
|
69 |
} else { |
|
70 |
needcomma = true; |
|
71 |
} |
|
72 |
builder.append(parameter.toString(formatter)); |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
} catch (Exception ex) { |
|
77 |
throw new IllegalArgumentException("Invalid columns, need a tuple function as columns."); |
|
67 | 78 |
} |
68 |
} |
|
69 |
} catch (Exception ex) { |
|
70 |
throw new IllegalArgumentException("Invalid columns, need a tuple function as columns."); |
|
71 |
} |
|
72 | 79 |
|
73 |
builder.append(" FROM "); |
|
74 |
builder.append(tableName); |
|
75 |
if (where != null) { |
|
76 |
builder.append(" WHERE "); |
|
77 |
builder.append(where.toString(formatter)); |
|
78 |
} |
|
80 |
builder.append(" FROM ");
|
|
81 |
builder.append(tableName);
|
|
82 |
if (where != null) {
|
|
83 |
builder.append(" WHERE ");
|
|
84 |
builder.append(where.toString(formatter));
|
|
85 |
}
|
|
79 | 86 |
// for( int n=0 ; function.containsParameter("ORDER", n); n++) { |
80 | 87 |
// if( n>0 ) { |
81 | 88 |
// builder.append(", "); |
... | ... | |
87 | 94 |
// builder.append(" DESC "); |
88 | 95 |
// } |
89 | 96 |
// } |
90 |
if (limit != null) { |
|
91 |
builder.append(" LIMIT "); |
|
92 |
builder.append(limit.toString(formatter)); |
|
97 |
if (limit != null) { |
|
98 |
builder.append(" LIMIT "); |
|
99 |
builder.append(limit.toString(formatter)); |
|
100 |
} |
|
101 |
builder.append(")"); |
|
102 |
return builder.toString(); |
|
93 | 103 |
} |
94 |
builder.append(")"); |
|
95 |
return builder.toString(); |
|
96 |
} |
|
97 | 104 |
|
98 | 105 |
} |
Also available in: Unified diff