Revision 46517

View differences:

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/function/dataaccess/ForeingValueFunction.java
52 52
              "foreing_key_field - Name of the field in the current table that contains the foreign key of the table that we want to access.",
53 53
              "field_name - Name of the field of the related table that we want to access."
54 54
            }, 
55
            "OBJECT"
55
            "OBJECT",
56
            true
56 57
    );
57 58
  }
58 59

  
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/function/dataaccess/GetattrFunction.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.expressionevaluator.impl.function.dataaccess;
7

  
8
import java.util.Objects;
9
import org.apache.commons.lang3.StringUtils;
10
import org.gvsig.expressionevaluator.Code;
11
import org.gvsig.expressionevaluator.Codes;
12
import org.gvsig.expressionevaluator.ExpressionBuilder;
13
import org.gvsig.fmap.dal.DALLocator;
14
import org.gvsig.fmap.dal.DataManager;
15
import org.gvsig.fmap.dal.SQLBuilder;
16
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
17
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
18
import org.gvsig.fmap.dal.feature.FeatureQuery;
19
import org.gvsig.fmap.dal.feature.FeatureType;
20

  
21
/**
22
 *
23
 * @author fdiaz
24
 */
25
public class GetattrFunction extends org.gvsig.expressionevaluator.impl.function.programming.GetattrFunction {
26

  
27
    @Override
28
    public ExpressionBuilder.Value toValue(ExpressionBuilder builder, Codes args) {
29
        try {
30
            SQLBuilder sqlBuilder = (SQLBuilder) builder.getProperty("SQLBUILDER");
31
            if(sqlBuilder == null){
32
                return super.toValue(builder, args);
33
            }
34
            if(!(args.get(0) instanceof Code.Identifier)){
35
                return super.toValue(builder, args);
36
            }
37
            if(!(args.get(1) instanceof Code.Constant)){
38
                return super.toValue(builder, args);
39
            }
40
            String tableName = ((Code.Identifier)args.get(0)).name();
41
            String columnName = Objects.toString(((Code.Constant)args.get(1)).value(), null);
42
            if(StringUtils.isBlank(tableName) || StringUtils.isBlank(columnName)){
43
                return super.toValue(builder, args);
44
            }
45
            FeatureAttributeDescriptor attr = null;
46
            FeatureQuery query = (FeatureQuery) builder.getProperty("Query");
47
            if(query != null){
48
                attr = query.getExtraColumns().get(columnName);
49
            }
50
            if(attr == null) {
51
                String builderTable = (String) builder.getProperty("Table");
52
                FeatureType featureType = null;
53
                if(StringUtils.equalsIgnoreCase(builderTable, tableName)){
54
                    featureType = (FeatureType) builder.getProperty("FeatureType");
55
                } else {
56
                    DataManager dataManager = DALLocator.getDataManager();
57
                    featureType = dataManager.getStoresRepository().getFeatureType(tableName);
58
                }
59
                if (featureType == null) {
60
                    return super.toValue(builder, args);
61
                }
62
                attr = featureType.getAttributeDescriptor(columnName);
63
                if (attr == null) {
64
                    return super.toValue(builder, args);
65
                }
66
            }
67
            SQLBuilder.TableNameBuilder table = sqlBuilder.createTableNameBuilder();
68
            table.name(tableName);
69
            SQLBuilder.Column column = sqlBuilder.column(table, columnName);
70
            return column;
71
        } catch (Exception ex) {
72
            return super.toValue(builder, args);
73
        }
74
    }
75
    
76
    
77
}
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/function/dataaccess/SelectFunction.java
25 25

  
26 26
import java.util.List;
27 27
import org.apache.commons.lang3.Range;
28
import org.apache.commons.lang3.StringUtils;
28 29
import org.gvsig.expressionevaluator.Code;
29 30
import org.gvsig.expressionevaluator.Codes;
30 31
import org.gvsig.expressionevaluator.ExpressionRuntimeException;
......
41 42
import org.gvsig.expressionevaluator.Code.Callable;
42 43
import org.gvsig.expressionevaluator.ExpressionBuilder;
43 44
import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
45
import org.gvsig.fmap.dal.DALLocator;
46
import org.gvsig.fmap.dal.DataManager;
44 47
import org.gvsig.fmap.dal.SQLBuilder;
48
import org.gvsig.fmap.dal.feature.FeatureType;
45 49
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureQueryOrder;
46 50

  
47 51
/**
......
183 187
            }
184 188

  
185 189
            if (columns != null) {
186
                for (Code column : columns.parameters()) {
187
                    if (column instanceof Code.Identifier) {
188
                        select.column().name(
189
                                select.from().table(),
190
                                ((Code.Identifier) column).name()
191
                        );
190
                if(columns.parameters().isEmpty()){
191
                    select.column().all();
192
                } else {
193
                    for (Code column : columns.parameters()) {
194
                        if (column instanceof Code.Identifier) {
195
                            String tableName = select.from().table().getName();
196
                            String columnName = ((Code.Identifier) column).name();
197
                            String builderTable = (String) builder.getProperty("Table");
198
                            FeatureType featureType = null;
199
                            if(StringUtils.equalsIgnoreCase(builderTable, tableName)){
200
                                featureType = (FeatureType) builder.getProperty("FeatureType");
201
                            } else {
202
                                DataManager dataManager = DALLocator.getDataManager();
203
                                featureType = dataManager.getStoresRepository().getFeatureType(tableName);
204
                            }
205
                            if(featureType == null){
206
                                select.column().name(
207
                                        select.from().table(),
208
                                        columnName
209
                                );
210
                            } else if(featureType.get(columnName) != null) {
211
                                select.column().name(
212
                                        select.from().table(),
213
                                        columnName
214
                                );
215
                            } else {
216
                                select.column().name(
217
                                        columnName
218
                                ).table(null);
219
                            }
220
                        }
192 221
                    }
193 222
                }
194 223
            }
......
214 243
        }
215 244
    }
216 245
    
217
    
218

  
219 246
}
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/DefaultDALExpressionBuilder.java
15 15
import static org.gvsig.fmap.dal.DataManager.FUNCTION_ISSELECTED_CURRENT_ROW;
16 16
import static org.gvsig.fmap.dal.DataManager.FUNCTION_SELECT;
17 17
import static org.gvsig.fmap.dal.DataManager.FUNCTION_SELECT_COUNT;
18
import org.gvsig.fmap.dal.SQLBuilder.SelectBuilder;
18 19
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder;
20
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase;
19 21

  
20 22
/**
21 23
 *
......
23 25
 */
24 26
public class DefaultDALExpressionBuilder implements DALExpressionBuilder {
25 27

  
26
  private class DefaultSelectBuilder implements SelectBuilder {
27
    
28
    private Value columns;
29
    private String tableName;
30
    private Value where;
31
    private Long limit;
32
    private final ExpressionBuilder.Function order;
33
    private final ExpressionBuilder.Function order_mode;
34
    
35
    public DefaultSelectBuilder() {
36
      this.columns = expression().tuple(); // ALL === empty tuple
37
      this.where = null;
38
      this.order = expression().tuple();
39
      this.order_mode = expression().tuple();
40
      this.limit = null;
41
    }
28
    private final SQLBuilderBase sqlbuilder;
42 29

  
43
    @Override
44
    public SelectBuilder column(String name) {
45
      ((ExpressionBuilder.Function)columns).parameter(expression().column(name));
46
      return this;
30
    public DefaultDALExpressionBuilder() {
31
        this.sqlbuilder = new SQLBuilderBase();
47 32
    }
48

  
49
    @Override
50
    public SelectBuilder column_all() {
51
      this.columns = expression().tuple(); // ALL === empty tuple
52
      return this;
53
    }
54

  
55
    @Override
56
    public SelectBuilder from(String tableName) {
57
      this.tableName = tableName;
58
      return this;
59
    }
60

  
61
    @Override
62
    public SelectBuilder where(ExpressionBuilder.Value where) {
63
      this.where = where;
64
      return this;
65
    }
66

  
67
    @Override
68
    public SelectBuilder order(String columnName, boolean asc) {
69
      this.order.parameter(expression().variable(columnName));
70
      this.order_mode.parameter(expression().constant(asc));
71
      return this;
72
    }
73

  
74
    @Override
75
    public SelectBuilder limit(long limit) {
76
      this.limit = limit;
77
      return this;
78
    }
79

  
80
    @Override
81
    public ExpressionBuilder.Value toValue() {
82
      ExpressionBuilder.Function select = expression().function(FUNCTION_SELECT);
83
      
84
      select.parameter(columns);
85
      select.parameter(expression().variable(tableName));
86
      select.parameter(where);
87
      select.parameter(order);
88
      select.parameter(order_mode);
89
      select.parameter(expression().constant(limit));
90
      
91
      return select;
92
    }
93

  
94
    @Override
95
    public String toString() {
96
      return this.toString(formatter());
97
    }
98 33
    
99
    @Override
100
    public String toString(Formatter<Value> formatter) {
101
      return this.toValue().toString(formatter);
102
    }
103 34
    
104
  }
35

  
36
//  private class DefaultSelectBuilder implements SelectBuilder {
37
//    
38
//    private Value columns;
39
//    private String tableName;
40
//    private Value where;
41
//    private Long limit;
42
//    private final ExpressionBuilder.Function order;
43
//    private final ExpressionBuilder.Function order_mode;
44
//    
45
//    public DefaultSelectBuilder() {
46
//      this.columns = expression().tuple(); // ALL === empty tuple
47
//      this.where = null;
48
//      this.order = expression().tuple();
49
//      this.order_mode = expression().tuple();
50
//      this.limit = null;
51
//    }
52
//
53
//    @Override
54
//    public SelectBuilder column(String name) {
55
//      ((ExpressionBuilder.Function)columns).parameter(expression().column(name));
56
//      return this;
57
//    }
58
//
59
//    @Override
60
//    public SelectBuilder column_all() {
61
//      this.columns = expression().tuple(); // ALL === empty tuple
62
//      return this;
63
//    }
64
//
65
//    @Override
66
//    public SelectBuilder from(String tableName) {
67
//      this.tableName = tableName;
68
//      return this;
69
//    }
70
//
71
//    @Override
72
//    public SelectBuilder where(ExpressionBuilder.Value where) {
73
//      this.where = where;
74
//      return this;
75
//    }
76
//
77
//    @Override
78
//    public SelectBuilder order(String columnName, boolean asc) {
79
//      this.order.parameter(expression().variable(columnName));
80
//      this.order_mode.parameter(expression().constant(asc));
81
//      return this;
82
//    }
83
//
84
//    @Override
85
//    public SelectBuilder limit(long limit) {
86
//      this.limit = limit;
87
//      return this;
88
//    }
89
//
90
//    @Override
91
//    public ExpressionBuilder.Value toValue() {
92
//      ExpressionBuilder.Function select = expression().function(FUNCTION_SELECT);
93
//      
94
//      select.parameter(columns);
95
//      select.parameter(expression().variable(tableName));
96
//      select.parameter(where);
97
//      select.parameter(order);
98
//      select.parameter(order_mode);
99
//      select.parameter(expression().constant(limit));
100
//      
101
//      return select;
102
//    }
103
//
104
//    @Override
105
//    public String toString() {
106
//      return this.toString(formatter());
107
//    }
108
//    
109
//    @Override
110
//    public String toString(Formatter<Value> formatter) {
111
//      return this.toValue().toString(formatter);
112
//    }
113
//    
114
//  }
105 115
  
106 116
  
107 117
  private class DefaultSelectCountBuilder implements SelectCountBuilder {
......
164 174
  
165 175
  @Override
166 176
  public SelectBuilder select() {
167
    return new DefaultSelectBuilder();
177
    return this.sqlbuilder.select();
168 178
  }
169 179

  
170 180
  @Override
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/symboltable/DALSymbolTable.java
33 33
import org.gvsig.expressionevaluator.impl.function.dataaccess.ExistsTableFunction;
34 34
import org.gvsig.expressionevaluator.impl.function.dataaccess.ForeingValueFunction;
35 35
import org.gvsig.expressionevaluator.impl.function.dataaccess.GeometryFunction;
36
import org.gvsig.expressionevaluator.impl.function.dataaccess.GetattrFunction;
36 37
import org.gvsig.expressionevaluator.impl.function.dataaccess.InsertIntoTableFunction;
37 38
import org.gvsig.expressionevaluator.impl.function.dataaccess.IsSelectedCurrentRowFunction;
38 39
import org.gvsig.expressionevaluator.impl.function.dataaccess.RowTagFunction;
......
75 76
        this.addFunction(new CreateTableStructureFunction());
76 77
        this.addFunction(new SelectFromSelectionFunction());
77 78
        this.addFunction(new SelectCountFromSelectionFunction());
79
        this.addFunction(new GetattrFunction());
78 80
    }     
79 81
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureExtraColumns.java
44 44
    @Override
45 45
    public EditableFeatureAttributeDescriptor get(String columnName) {
46 46
        for (EditableFeatureAttributeDescriptor extraColumn : this.extraColumns) {
47
            if (StringUtils.equals(extraColumn.getName(), columnName)) {
47
            if (StringUtils.equalsIgnoreCase(extraColumn.getName(), columnName)) {
48 48
                return extraColumn;
49 49
            }
50 50
        }
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/paging/impl/FeaturePagingHelperImpl.java
583 583
            }, initialIndex, howMany);
584 584
        } catch (VisitCanceledException ex) {
585 585
            // Do nothing
586
        } catch (RuntimeException e) {
587
            throw e;
586 588
        } catch (Exception e) {
587 589
            if (e instanceof DataException) {
588 590
                throw ((DataException) e);
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/test/java/org/gvsig/expressionevaluator/TestExpressionBuilder.java
6 6
import org.gvsig.fmap.dal.DataManager;
7 7
import org.gvsig.fmap.dal.SQLBuilder;
8 8
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder;
9
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder.SelectBuilder;
10 9
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase;
11 10
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
12 11

  
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/TableIsEmptyOperation.java
28 28
import java.sql.Statement;
29 29
import org.apache.commons.lang3.StringUtils;
30 30
import org.gvsig.expressionevaluator.ExpressionBuilder;
31
import org.gvsig.fmap.dal.SQLBuilder;
31 32
import org.gvsig.fmap.dal.exception.DataException;
32 33
import org.gvsig.fmap.dal.feature.FeatureQuery;
33 34
import org.gvsig.fmap.dal.feature.FeatureType;
......
39 40
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
40 41
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE;
41 42
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_JDBCHELPER;
43
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_QUERY;
42 44
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_SYMBOLTABLE;
43 45
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_TABLE;
46
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation.getAllExtraColumns;
47
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation.process3_Where;
48
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation.process4_Aggregates;
49
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation.process5_GroupBys;
44 50
import org.gvsig.tools.evaluator.Evaluator;
45 51

  
46 52
public class TableIsEmptyOperation extends AbstractConnectionOperation {
......
79 85
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
80 86
        ExpressionBuilder expbuilder = sqlbuilder.expression();
81 87
        
82
        sqlbuilder.select().column().all();
83
        sqlbuilder.select().from().table()
88
        expbuilder.setProperty(PROP_FEATURE_TYPE, this.featureType);
89
        expbuilder.setProperty(PROP_TABLE, table);
90
        expbuilder.setProperty(PROP_SYMBOLTABLE, this.query==null? null:this.query.getSymbolTable());
91
        expbuilder.setProperty(PROP_JDBCHELPER, this.helper);
92
        expbuilder.setProperty(PROP_QUERY, this.query);
93
        
94
        SQLBuilder.SelectBuilder select = sqlbuilder.select();
95
//        select.column().all();
96
        select.from().table()
84 97
                .database(this.table.getDatabase())
85 98
                .schema(this.table.getSchema())
86 99
                .name(this.table.getTable());
87
        sqlbuilder.select().from().subquery(this.table.getSubquery());
100
        select.from().subquery(this.table.getSubquery());
101
        
102
//        ResultSetForSetProviderOperation.process2_ComputedFields(helper, featureType, query, sqlbuilder, select, null);
103
        process3_Where(helper, featureType, query, sqlbuilder, select);
88 104
        if (!StringUtils.isEmpty(baseFilter)) {
89
            sqlbuilder.select().where().set( expbuilder.custom(baseFilter) );
105
            select.where().set( expbuilder.custom(baseFilter) );
90 106
        }
107
        if (this.query != null && (query.hasAggregateFunctions() || query.hasGroupByColumns())) {
108
            process4_Aggregates(this.table, this.featureType, this.query, getAllExtraColumns(this.featureType, this.query), sqlbuilder, select, null);
109
            process5_GroupBys(this.table, this.featureType, this.query, getAllExtraColumns(this.featureType, this.query), sqlbuilder, select, null);
110
        }
91 111
        
92
        Evaluator filter = query == null ? null : query.getFilter();
93
        if (filter != null) {
94
            String sqlfilter = filter.getSQL();
95
            if (!StringUtils.isEmpty(sqlfilter)) {
96
                if (this.helper.supportFilter(this.featureType, filter)) {
97
                    // El and() hace un set() si no hay un filtro previo
98
                    sqlbuilder.select().where().and(expbuilder.toValue(sqlfilter));
99
                }
100
            }
101
        }        
102
//        if (!StringUtils.isEmpty(filter)) {
103
//            // El and() hace un set() si no hay un filtro previo
104
//            sqlbuilder.select().where().and(expbuilder.toValue(filter));
105
//        }
106 112
        sqlbuilder.select().limit(1);
107
        this.helper.processSpecialFunctions(sqlbuilder, featureType, null);
108
//        sqlbuilder.setProperties(
109
//                ExpressionBuilder.Variable.class, 
110
//                PROP_TABLE, table
111
//        );
113
        
112 114
        sqlbuilder.setProperties(
113 115
                null,
114 116
                PROP_FEATURE_TYPE, this.featureType,
115 117
                PROP_TABLE, table,
116 118
                PROP_SYMBOLTABLE, this.query==null? null:this.query.getSymbolTable(),
117
                PROP_JDBCHELPER, this.helper
119
                PROP_JDBCHELPER, this.helper,
120
                PROP_QUERY, this.query
118 121
        );
122

  
123
	this.helper.expandCalculedColumns(sqlbuilder);
124
        this.helper.processSpecialFunctions(sqlbuilder, featureType, null);
125
        if(select.getColumns().isEmpty()){
126
            select.column().value(expbuilder.constant(1));
127
        }
119 128
        String sql = sqlbuilder.select().toString();
120 129
        return sql;
121 130
    }
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/ResultSetForSetProviderOperation.java
34 34
import org.gvsig.expressionevaluator.ExpressionBuilder;
35 35
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_LET;
36 36
import static org.gvsig.expressionevaluator.ExpressionBuilder.VALUE_NULL;
37
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
37 38
import org.gvsig.expressionevaluator.ExpressionUtils;
38 39
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
40
import org.gvsig.expressionevaluator.SymbolTable;
39 41
import org.gvsig.fmap.dal.SQLBuilder;
40 42
import org.gvsig.fmap.dal.SQLBuilder.Column;
41 43
import org.gvsig.fmap.dal.SQLBuilder.OrderByBuilder;
......
128 130
    ) {
129 131
        double tolerance = -1; //query.getScale(); 
130 132
        ExpressionBuilder expbuilder = sqlbuilder.expression();
133
        
134
        expbuilder.setProperty(PROP_FEATURE_TYPE, this.storeType);
135
        expbuilder.setProperty(PROP_TABLE, table);
136
        expbuilder.setProperty(PROP_SYMBOLTABLE, this.query==null? null:this.query.getSymbolTable());
137
        expbuilder.setProperty(PROP_JDBCHELPER, this.helper);
138
        expbuilder.setProperty(PROP_QUERY, this.query);
139
        
131 140
        SelectBuilder select = sqlbuilder.select();
132 141
        select.from().table()
133 142
                .database(this.table.getDatabase())
......
513 522
                                }
514 523
                                value = expbuilder.function(fn, value);
515 524
                            } else {
516
                                throw new RuntimeException("Can't order by column '" + attrName + "', it does not have an aggregate function nor is it grouping by it.");
525
                                continue;
526
//                                throw new RuntimeException("Can't order by column '" + attrName + "', it does not have an aggregate function nor is it grouping by it.");
517 527
                            }
518 528
                            int nullsMode = OrderByBuilder.MODE_NULLS_LAST;
519 529
                            if ( !attr.allowNull() || attr.isPrimaryKey() ) {
......
740 750

  
741 751

  
742 752
    private static ExpressionBuilder.Value createValueFromAttribute(SQLBuilder sqlbuilder, FeatureAttributeDescriptor attr) {
743
        if (attr.getRelationType() != DynField.RELATION_TYPE_NONE) {
744
            return VALUE_NULL;
753
        switch(attr.getRelationType()) {
754
            case DynField.RELATION_TYPE_AGGREGATE:
755
            case DynField.RELATION_TYPE_COMPOSITION:
756
                return VALUE_NULL;
757
            case DynField.RELATION_TYPE_NONE:
758
            case DynField.RELATION_TYPE_IDENTITY:
759
            case DynField.RELATION_TYPE_COLLABORATION:
760
                break;
745 761
        }
762
        
746 763
        if( attr.isComputed() ) {
747 764
            FeatureAttributeEmulator attrEmulator = attr.getFeatureAttributeEmulator();
748 765
            if( !(attrEmulator instanceof FeatureAttributeEmulatorExpression) ) {
......
754 771
                return VALUE_NULL;
755 772
            }
756 773
            Code code = exp.getCode();
774

  
775
            SymbolTable symbolTable = ExpressionEvaluatorLocator.getExpressionEvaluatorManager().getInmutableSymbolTable();
776
            
777
            code.link(symbolTable);
757 778
            ExpressionBuilder.Value value = code.toValue(sqlbuilder.expression());
758 779
            return value;
759 780
        }
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/CountOperation.java
86 86
    public String getSQL() {
87 87
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
88 88
        ExpressionBuilder expbuilder = sqlbuilder.expression();
89
        
90
        expbuilder.setProperty(PROP_FEATURE_TYPE, this.featureType);
91
        expbuilder.setProperty(PROP_TABLE, table);
92
        expbuilder.setProperty(PROP_SYMBOLTABLE, this.query==null? null:this.query.getSymbolTable());
93
        expbuilder.setProperty(PROP_JDBCHELPER, this.helper);
94
        expbuilder.setProperty(PROP_QUERY, this.query);
89 95

  
90 96
        SelectBuilder select = sqlbuilder.select();
91 97
        select.from().table()
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/expressionbuilder/formatters/ComputedAttribute.java
67 67
                return false;
68 68
            }
69 69
            ExpressionBuilder.Variable variable = (ExpressionBuilder.Variable) value;
70
			FeatureAttributeDescriptor attr = featureType.getAttributeDescriptor(variable.name());
71
			if (attr == null) {
72
				FeatureQuery query = (FeatureQuery) value.getProperty(PROP_QUERY);
73
				if (query == null) {
74
					return false;
75
				}
76
				FeatureExtraColumns extraColumn = query.getExtraColumn();
77
				if (extraColumn == null) {
78
					return false;
79
				}
80
				attr = extraColumn.get(variable.name());
81
				if (attr == null ) {
82
					return false;
83
				}
84
			}
70
            FeatureAttributeDescriptor attr = featureType.getAttributeDescriptor(variable.name());
71
            if (attr == null) {
72
                    FeatureQuery query = (FeatureQuery) value.getProperty(PROP_QUERY);
73
                    if (query == null) {
74
                            return false;
75
                    }
76
                    FeatureExtraColumns extraColumn = query.getExtraColumn();
77
                    if (extraColumn == null) {
78
                            return false;
79
                    }
80
                    attr = extraColumn.get(variable.name());
81
                    if (attr == null ) {
82
                            return false;
83
                    }
84
            }
85 85

  
86 86
            if (!attr.isComputed()) {
87 87
                return false;
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/expressionbuilder/formatters/ToString.java
1
package org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters;
2

  
3
import java.text.MessageFormat;
4
import java.util.List;
5
import org.apache.commons.lang3.StringUtils;
6
import org.gvsig.expressionevaluator.ExpressionBuilder;
7
import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
8
import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
9
import org.gvsig.expressionevaluator.Formatter;
10
import org.gvsig.fmap.dal.SQLBuilder;
11

  
12
/**
13
 *
14
 * @author jjdelcerro
15
 */
16
public class ToString implements Formatter<Value> {
17

  
18
    private final Formatter<Value> formatter;
19
    private final SQLBuilder builder;
20
    
21
    public ToString(SQLBuilder builder, Formatter<Value> formatter) {
22
        this.builder = builder;
23
        this.formatter = formatter;
24
    }
25
    
26
    @Override
27
    public boolean canApply(Value value) {
28
        if (value instanceof Function) {
29
            if (value instanceof ExpressionBuilder.Function) {
30
                return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_TOSTR, ((Function) value).name());
31
            }
32
        }
33
        return false;
34
    }
35

  
36
    @Override
37
    public String format(Value function) {
38
            List<Value> parameters = ((Function) function).parameters();
39
            String p1 = parameters.get(0).toString(formatter);
40
            
41
            String r = MessageFormat.format(
42
                    "CAST ( {0} AS VARCHAR )",
43
                    p1
44
            );
45
            return r;
46
    }
47
    
48
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/JDBCHelperBase.java
27 27
import java.sql.Blob;
28 28
import java.sql.Clob;
29 29
import java.sql.ResultSet;
30
import java.sql.ResultSetMetaData;
31 30
import java.util.ArrayList;
32
import java.util.Collections;
33
import java.util.HashMap;
34 31
import java.util.HashSet;
35 32
import java.util.List;
36
import java.util.Map;
33
import java.util.ListIterator;
37 34
import java.util.function.Predicate;
35
import org.apache.commons.collections.CollectionUtils;
38 36
import org.apache.commons.io.IOUtils;
39 37
import org.apache.commons.lang3.ArrayUtils;
40 38
import org.apache.commons.lang3.StringUtils;
41 39
import org.apache.commons.lang3.mutable.MutableBoolean;
42 40
import org.apache.commons.lang3.mutable.MutableObject;
41
import org.apache.commons.lang3.tuple.ImmutablePair;
43 42
import org.apache.commons.lang3.tuple.Pair;
44 43
import org.gvsig.expressionevaluator.Code;
45 44
import org.gvsig.expressionevaluator.Expression;
46 45
import org.gvsig.expressionevaluator.ExpressionBuilder;
46
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$CONSTANT;
47
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$IDENTIFIER;
47 48
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
48 49
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
49 50
import org.gvsig.expressionevaluator.Function;
50 51
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType;
51 52
import org.gvsig.expressionevaluator.SymbolTable;
53
import org.gvsig.fmap.dal.DALLocator;
54
import org.gvsig.fmap.dal.DataManager;
52 55
import static org.gvsig.fmap.dal.DataManager.FUNCTION_EXISTS;
53 56
import static org.gvsig.fmap.dal.DataManager.FUNCTION_FOREING_VALUE;
54 57
import org.gvsig.fmap.dal.DataTypes;
55 58
import org.gvsig.fmap.dal.SQLBuilder;
59
import org.gvsig.fmap.dal.SQLBuilder.Column;
60
import org.gvsig.fmap.dal.SQLBuilder.SelectBuilder;
56 61
import org.gvsig.fmap.dal.exception.DataException;
57 62
import org.gvsig.fmap.dal.exception.InitializeException;
58 63
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression;
......
78 83
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
79 84
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
80 85
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCCantFetchValueException;
86
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection;
81 87
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
82 88
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
83 89
import org.gvsig.fmap.dal.store.jdbc2.JDBCStoreProvider;
......
86 92
import org.gvsig.fmap.dal.store.jdbc2.ResulSetControler;
87 93
import org.gvsig.fmap.dal.store.jdbc2.ResulSetControler.ResultSetEntry;
88 94
import org.gvsig.fmap.dal.store.jdbc2.impl.ResulSetControlerBase;
95
import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.ComputedAttribute;
89 96
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase;
90 97
import org.gvsig.fmap.geom.Geometry;
91 98
import org.gvsig.fmap.geom.GeometryLocator;
......
94 101
import org.gvsig.tools.evaluator.Evaluator;
95 102
import org.gvsig.tools.exception.BaseException;
96 103
import org.gvsig.tools.exception.NotYetImplemented;
104
import org.gvsig.tools.locator.LocatorException;
105
import org.gvsig.tools.util.ContainerUtils;
97 106
import org.gvsig.tools.visitor.FilteredVisitable;
98 107
import org.gvsig.tools.visitor.VisitCanceledException;
99 108
import org.gvsig.tools.visitor.Visitor;
100 109
import org.slf4j.Logger;
101 110
import org.slf4j.LoggerFactory;
102
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$CONSTANT;
103
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$IDENTIFIER;
104
import org.gvsig.fmap.dal.DataManager;
105
import org.gvsig.fmap.dal.SQLBuilder.Column;
106
import org.gvsig.fmap.dal.SQLBuilder.OrderByBuilder;
107
import org.gvsig.fmap.dal.SQLBuilder.SelectBuilder;
108
import org.gvsig.fmap.dal.SQLBuilder.SelectColumnBuilder;
109
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection;
110
import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.ComputedAttribute;
111
import org.gvsig.tools.util.ContainerUtils;
112 111

  
113 112
@SuppressWarnings("UseSpecificCatch")
114 113
public class JDBCHelperBase extends AbstractDisposable implements ResourceConsumer, JDBCHelper {
......
977 976
            usedLeftJoins.add(foreingTable.getName());
978 977
          }
979 978
          //No est? claro si debe a?adirse esta columna o no, OJO quitarlo o ponerlo altera los test de  H2
980
//          if ( !(sqlbuilder.select().has_group_by() || sqlbuilder.select().has_aggregate_functions()) ) {
981
//                sqlbuilder.select().column().name(foreingTable, columnNameForeing);
982
//          }
979
          //Si se comentarizan ojo con extra_column_names ya que se habr?n a?adido columnas que no estar?n en la select
980
          if ( !(sqlbuilder.select().has_group_by() || sqlbuilder.select().has_aggregate_functions()) ) {
981
                sqlbuilder.select().column().name(foreingTable, columnNameForeing);
982
          }
983 983
        }
984 984
      }
985 985
      
......
992 992
  }
993 993
 
994 994
    protected void addTableToColumnReferences(SQLBuilder sqlbuilder, FeatureType type) {
995
//        List<SelectBuilder> selectBuilders = new ArrayList<>();
996
//        selectBuilders.add(sqlbuilder.select());
997
//        sqlbuilder.select().accept((ExpressionBuilder.Visitable value) -> {
998
//            selectBuilders.add((SelectBuilder) value);
999
//
1000
//        }, (ExpressionBuilder.Visitable visitable) -> (visitable instanceof SelectBuilder));
1001
//        for (SelectBuilder selectBuilder : selectBuilders) {
1002
//            addTableToColumnReferencesInSingleSelect(sqlbuilder, selectBuilder);
1003
//        }
995
        SelectBuilder select = sqlbuilder.select();
996
        List<Pair<SQLBuilder.TableNameBuilder, FeatureType>> tables = new ArrayList<>();
997
        collectTablesFromSelect(select, tables, type);
1004 998

  
999
        addTableToColumnReferencesInSingleSelect(
1000
                sqlbuilder, 
1001
                select, 
1002
                tables
1003
        );
1004
        
1005
    }
1005 1006

  
1006
        addTableToColumnReferencesInSingleSelect(sqlbuilder, sqlbuilder.select(), new ArrayList<>());
1007
    private void collectTablesFromSelect(SelectBuilder select, List<Pair<SQLBuilder.TableNameBuilder, FeatureType>> tables, FeatureType type) throws LocatorException {
1008
        DataManager dataManager = DALLocator.getDataManager();
1007 1009
        
1010
        List<SQLBuilder.JoinBuilder> joins = select.from().getJoins();
1011
        if(!CollectionUtils.isEmpty(joins)){
1012
            for (SQLBuilder.JoinBuilder join : joins) {
1013
                SQLBuilder.TableNameBuilder joinTable = join.getTable();
1014
                FeatureType featureType = dataManager.getStoresRepository().getFeatureType(joinTable.getName());
1015
                tables.add(new ImmutablePair<>(joinTable,featureType));
1016
            }
1017
        }
1018
        SQLBuilder.TableNameBuilder table = select.from().table();
1019
        if(type == null){
1020
            type = dataManager.getStoresRepository().getFeatureType(table.getName());
1021
        }
1022
        tables.add(new ImmutablePair<>(table,type));
1008 1023
    }
1009 1024
    
1010
    protected void addTableToColumnReferencesInSingleSelect(SQLBuilder sqlbuilder, SelectBuilder select, List<Column> parentColumns) {
1025
    protected void addTableToColumnReferencesInSingleSelect(SQLBuilder sqlbuilder, SelectBuilder select, List<Pair<SQLBuilder.TableNameBuilder,FeatureType>> outerTables) {
1011 1026
        
1012 1027
        final SQLBuilder.TableNameBuilder table = select.from().table();
1013 1028

  
......
1016 1031
        List<ExpressionBuilder.Value> variablesToExclude = new ArrayList<>();
1017 1032
        
1018 1033
        select.accept((ExpressionBuilder.Visitable value) -> {
1019
            if(value instanceof ExpressionBuilder.Function) {
1020
                ExpressionBuilder.Function fn = (ExpressionBuilder.Function) value;
1021
                if(StringUtils.equals(fn.name(), ExpressionBuilder.FUNCTION_GETATTR)){
1022
                    ExpressionBuilder.Value p1 = fn.parameters().get(0);
1023
                    if(p1 instanceof ExpressionBuilder.Variable){
1024
                        ExpressionBuilder.Variable v = (ExpressionBuilder.Variable) p1;
1025
                        variablesToExclude.add(v);
1026
                    }
1027
                    ExpressionBuilder.Value p2 = fn.parameters().get(1);
1028
                    if(p2 instanceof ExpressionBuilder.Constant){
1029
                        ExpressionBuilder.Constant c = (ExpressionBuilder.Constant) p2;
1030
                        variablesToExclude.add(c);
1031
                    }
1032
                }
1033
            } else if(value instanceof Column) {
1034
            if(value instanceof Column) {
1034 1035
                Column c = (Column)value;
1035 1036
                if(c.table() == null || !c.table().has_name()){
1036 1037
                    variables.add(c);
......
1038 1039
                
1039 1040
            } else if(value instanceof ExpressionBuilder.Variable) {
1040 1041
                variables.add((ExpressionBuilder.Variable) value);
1041
//            } else if(value instanceof SelectColumnBuilder) {
1042
//                SelectColumnBuilder selectColumn = (SelectColumnBuilder)value;
1043
//                if(StringUtils.isNotBlank(selectColumn.getName()) && selectColumn.getTable().has_name()){
1044
//                    variablesToExclude.add(sel)
1045
//                }
1046 1042
            }
1047 1043

  
1048 1044
        }, new ExpressionBuilder.VisitorFilter() {
......
1056 1052
                if(select == visitable){
1057 1053
                    return true;
1058 1054
                }
1059
//                if(visitable instanceof OrderByBuilder) {
1060
//                    return false;
1061
//                }
1062 1055
                if(visitable instanceof SelectBuilder) {
1063
                    ArrayList<Column> columns = new ArrayList<>(parentColumns);
1064
                    for (SelectColumnBuilder column : select.getColumns()) {
1065
                        columns.add(sqlbuilder.column(
1066
                            table,
1067
                            column.getName()));
1068
                    }
1069
                    addTableToColumnReferencesInSingleSelect(sqlbuilder, (SelectBuilder) visitable, columns);
1056
                    ArrayList<Pair<SQLBuilder.TableNameBuilder, FeatureType>> tables = new ArrayList<>(outerTables);
1057
                    collectTablesFromSelect(select, tables, null);
1058
                    
1059
                    addTableToColumnReferencesInSingleSelect(sqlbuilder, (SelectBuilder) visitable, tables);
1070 1060
                    return false;
1071 1061
                }
1072 1062
                return true;
1073 1063
            }
1074 1064
        });
1075 1065
        
1076
        List<String> variableNamesToExclude = new ArrayList<>();
1077
        for(SQLBuilder.SelectColumnBuilder column : select.getColumns()){
1078
            if(StringUtils.isNotBlank(column.getAlias())){
1079
                variableNamesToExclude.add(column.getAlias());
1080
            } else {
1081
                parentColumns.add(sqlbuilder.column(
1082
                    table,
1083
                    column.getName()));
1084
            }
1085
        }
1086

  
1087 1066
        for (ExpressionBuilder.Variable variable : variables) {
1088 1067
            boolean found = false;
1089 1068
            for (ExpressionBuilder.Value v : variablesToExclude) {
......
1095 1074
            if(found){
1096 1075
                continue;
1097 1076
            }
1098
//            if(variableNamesToExclude.contains(variable.name())){
1099
//                continue;
1100
//            }
1101
            Column column = getColumn(parentColumns,variable.name());
1102
            if(column != null){
1077

  
1078
            SQLBuilder.TableNameBuilder tableName = getTable(outerTables,variable.name());
1079
            if(tableName != null){
1103 1080
                ExpressionBuilder.Variable variable_replacement = sqlbuilder.column(
1104
                        column.table(),
1081
                        tableName,
1105 1082
                        variable.name()
1106 1083
                );
1107 1084
                value_replacements.add(
......
1113 1090
            } else {
1114 1091
                ExpressionBuilder.Variable variable_replacement = null;
1115 1092
                if(variable instanceof SQLBuilder.Column){
1116
                    column = (SQLBuilder.Column) variable;
1093
                    Column column = (SQLBuilder.Column) variable;
1117 1094
                    if (column.table() == null || !column.table().has_name()) {
1118 1095
                        variable_replacement = sqlbuilder.column(
1119 1096
                                table,
......
1158 1135

  
1159 1136
    }
1160 1137
    
1161
    protected Column getColumn(List<Column> columns, String name){
1162
        for (int i = columns.size()-1; i >= 0; i--) {
1163
            if(StringUtils.equalsIgnoreCase(columns.get(i).name(), name)){
1164
                return columns.get(i);
1138
    protected SQLBuilder.TableNameBuilder getTable(List<Pair<SQLBuilder.TableNameBuilder, FeatureType>> outerTables, String columnName) {
1139
        ListIterator<Pair<SQLBuilder.TableNameBuilder, FeatureType>> it = outerTables.listIterator(outerTables.size());
1140
        while (it.hasPrevious()) {
1141
            Pair<SQLBuilder.TableNameBuilder, FeatureType> pair = it.previous();
1142
            FeatureType featureType = pair.getRight();
1143
            if(featureType.get(columnName) != null){
1144
                return pair.getLeft();
1165 1145
            }
1166 1146
        }
1167 1147
        return null;
1168 1148
    }
1169

  
1170 1149
    
1171 1150
    @Override
1172 1151
    public void setTransaction(DataTransactionServices transaction) {
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/test/resources/org/gvsig/fmap/dal/store/jdbc2/countries.csv
1
"FIPS/String/set/size=2/set/order=0";"ISO2/String/set/size=2/set/order=10";"ISO3/String/set/size=3/set/order=20";"UN/Decimal/set/precision=3/set/scale=0/set/roundMode=4/set/order=30";"NAME/String/set/size=50/set/order=40";"AREA/Integer/set/order=50";"POP2005/Integer/set/order=60";"REGION/Decimal/set/precision=3/set/scale=0/set/roundMode=4/set/order=70";"SUBREGION/Decimal/set/precision=3/set/scale=0/set/roundMode=4/set/order=80";"LON/Decimal/set/precision=6/set/scale=-1/set/roundMode=4/set/order=90";"LAT/Decimal/set/precision=5/set/scale=-1/set/roundMode=4/set/order=100"
2
"AC";"AG";"ATG";"28";"Antigua and Barbuda";"44";"83039";"19";"29";"-61.783";"17.078"
3
"AG";"DZ";"DZA";"12";"Algeria";"238174";"32854159";"2";"15";"2.632";"28.163"
4
"AJ";"AZ";"AZE";"31";"Azerbaijan";"8260";"8352021";"142";"145";"47.395";"40.430"
5
"AL";"AL";"ALB";"8";"Albania";"2740";"3153731";"150";"39";"20.068";"41.143"
6
"AM";"AM";"ARM";"51";"Armenia";"2820";"3017661";"142";"145";"44.563";"40.534"
7
"AO";"AO";"AGO";"24";"Angola";"124670";"16095214";"2";"17";"17.544";"-12.296"
8
"AQ";"AS";"ASM";"16";"American Samoa";"20";"64051";"9";"61";"-170.730";"-14.318"
9
"AR";"AR";"ARG";"32";"Argentina";"273669";"38747148";"19";"5";"-65.167";"-35.377"
10
"AS";"AU";"AUS";"36";"Australia";"768230";"20310208";"9";"53";"136.189";"-24.973"
11
"BA";"BH";"BHR";"48";"Bahrain";"71";"724788";"142";"145";"50.562";"26.019"
12
"BB";"BB";"BRB";"52";"Barbados";"43";"291933";"19";"29";"-59.559";"13.153"
13
"BD";"BM";"BMU";"60";"Bermuda";"5";"64174";"19";"21";"-64.709";"32.336"
14
"BF";"BS";"BHS";"44";"Bahamas";"1001";"323295";"19";"29";"-78.014";"24.628"
15
"BG";"BD";"BGD";"50";"Bangladesh";"13017";"15328112";"142";"34";"89.941";"24.218"
16
"BH";"BZ";"BLZ";"84";"Belize";"2281";"275546";"19";"13";"-88.602";"17.219"
17
"BK";"BA";"BIH";"70";"Bosnia and Herzegovina";"5120";"3915238";"150";"39";"17.786";"44.169"
18
"BL";"BO";"BOL";"68";"Bolivia";"108438";"9182015";"19";"5";"-64.671";"-16.715"
19
"BM";"MM";"MMR";"104";"Burma";"65755";"47967266";"142";"35";"96.041";"21.718"
20
"BN";"BJ";"BEN";"204";"Benin";"11062";"8490301";"2";"11";"2.469";"10.541"
21
"BP";"SB";"SLB";"90";"Solomon Islands";"2799";"472419";"9";"54";"160.109";"-9.611"
22
"BR";"BR";"BRA";"76";"Brazil";"845942";"186830759";"19";"5";"-53.089";"-10.772"
23
"BU";"BG";"BGR";"100";"Bulgaria";"11063";"7744591";"150";"151";"25.231";"42.761"
24
"BX";"BN";"BRN";"96";"Brunei Darussalam";"527";"373831";"142";"35";"114.591";"4.468"
25
"CA";"CA";"CAN";"124";"Canada";"909351";"32270507";"19";"21";"-109.433";"59.081"
26
"CB";"KH";"KHM";"116";"Cambodia";"17652";"13955507";"142";"35";"104.564";"12.714"
27
"CE";"LK";"LKA";"144";"Sri Lanka";"6463";"19120763";"142";"34";"80.704";"7.612"
28
"CF";"CG";"COG";"178";"Congo";"34150";"3609851";"2";"17";"15.986";"-0.055"
29
"CG";"CD";"COD";"180";"Democratic Republic of the Congo";"226705";"58740547";"2";"17";"23.654";"-2.876"
30
"BY";"BI";"BDI";"108";"Burundi";"2568";"7858791";"2";"14";"29.887";"-3.356"
31
"CH";"CN";"CHN";"156";"China";"932743";"1312978855";"142";"30";"106.514";"33.420"
32
"AF";"AF";"AFG";"4";"Afghanistan";"65209";"25067407";"142";"34";"65.216";"33.677"
33
"BT";"BT";"BTN";"64";"Bhutan";"4700";"637013";"142";"34";"90.429";"27.415"
34
"CI";"CL";"CHL";"152";"Chile";"74880";"16295102";"19";"5";"-69.433";"-23.389"
35
"CJ";"KY";"CYM";"136";"Cayman Islands";"26";"45591";"19";"29";"-81.198";"19.314"
36
"CM";"CM";"CMR";"120";"Cameroon";"46540";"17795149";"2";"17";"12.277";"5.133"
37
"CD";"TD";"TCD";"148";"Chad";"125920";"10145609";"2";"17";"18.665";"15.361"
38
"CN";"KM";"COM";"174";"Comoros";"223";"797902";"2";"14";"43.337";"-11.758"
39
"CO";"CO";"COL";"170";"Colombia";"103870";"4494579";"19";"5";"-73.076";"3.900"
40
"CS";"CR";"CRI";"188";"Costa Rica";"5106";"4327228";"19";"13";"-83.946";"9.971"
41
"CT";"CF";"CAF";"140";"Central African Republic";"62298";"4191429";"2";"17";"20.483";"6.571"
42
"CU";"CU";"CUB";"192";"Cuba";"10982";"11259905";"19";"29";"-77.781";"21.297"
43
"CV";"CV";"CPV";"132";"Cape Verde";"403";"506807";"2";"11";"-23.634";"15.071"
44
"CW";"CK";"COK";"184";"Cook Islands";"24";"13984";"9";"61";"-159.782";"-21.219"
45
"CY";"CY";"CYP";"196";"Cyprus";"924";"836321";"142";"145";"33.219";"35.043"
46
"DA";"DK";"DNK";"208";"Denmark";"4243";"5416945";"150";"154";"9.264";"56.058"
47
"DJ";"DJ";"DJI";"262";"Djibouti";"2318";"804206";"2";"14";"42.516";"11.900"
48
"DO";"DM";"DMA";"212";"Dominica";"75";"67827";"19";"29";"-61.356";"15.475"
49
"DR";"DO";"DOM";"214";"Dominican Republic";"4838";"9469601";"19";"29";"-70.729";"19.015"
50
"EC";"EC";"ECU";"218";"Ecuador";"27684";"13060993";"19";"5";"-78.497";"-1.385"
51
"EG";"EG";"EGY";"818";"Egypt";"99545";"72849793";"2";"15";"29.872";"26.494"
52
"EI";"IE";"IRL";"372";"Ireland";"6889";"4143294";"150";"154";"-8.152";"53.177"
53
"EK";"GQ";"GNQ";"226";"Equatorial Guinea";"2805";"484098";"2";"17";"10.488";"1.607"
54
"EN";"EE";"EST";"233";"Estonia";"4239";"1344312";"150";"154";"25.793";"58.674"
55
"ER";"ER";"ERI";"232";"Eritrea";"10100";"4526722";"2";"14";"38.219";"16.045"
56
"ES";"SV";"SLV";"222";"El Salvador";"2072";"6668356";"19";"13";"-88.866";"13.736"
57
"ET";"ET";"ETH";"231";"Ethiopia";"100000";"78985857";"2";"14";"39.616";"8.626"
58
"AU";"AT";"AUT";"40";"Austria";"8245";"8291979";"150";"155";"14.912";"47.683"
59
"EZ";"CZ";"CZE";"203";"Czech Republic";"7727";"10191762";"150";"151";"15.338";"49.743"
60
"FG";"GF";"GUF";"254";"French Guiana";"8815";"192099";"19";"5";"-53.241";"3.924"
61
"FI";"FI";"FIN";"246";"Finland";"30459";"5246004";"150";"154";"26.272";"64.504"
62
"FJ";"FJ";"FJI";"242";"Fiji";"1827";"828046";"9";"54";"177.974";"-17.819"
63
"FK";"FK";"FLK";"238";"Falkland Islands (Malvinas)";"1217";"2975";"19";"5";"-58.694";"-51.665"
64
"FM";"FM";"FSM";"583";"Micronesia, Federated States of";"70";"110058";"9";"57";"158.235";"6.883"
65
"FP";"PF";"PYF";"258";"French Polynesia";"366";"255632";"9";"61";"-149.462";"-17.626"
66
"FR";"FR";"FRA";"250";"France";"55010";"60990544";"150";"155";"2.550";"46.565"
67
"GA";"GM";"GMB";"270";"Gambia";"1000";"1617029";"2";"11";"-15.386";"13.453"
68
"GB";"GA";"GAB";"266";"Gabon";"25767";"1290693";"2";"17";"11.797";"-0.591"
69
"GG";"GE";"GEO";"268";"Georgia";"6949";"4473409";"142";"145";"43.518";"42.176"
70
"GH";"GH";"GHA";"288";"Ghana";"22754";"2253501";"2";"11";"-1.207";"7.960"
71
"GJ";"GD";"GRD";"308";"Grenada";"34";"105237";"19";"29";"-61.678";"12.118"
72
"GL";"GL";"GRL";"304";"Greenland";"41045";"57475";"19";"21";"-41.391";"74.719"
73
"GM";"DE";"DEU";"276";"Germany";"34895";"82652369";"150";"155";"9.851";"51.110"
74
"GQ";"GU";"GUM";"316";"Guam";"55";"16857";"9";"57";"144.707";"13.385"
75
"GR";"GR";"GRC";"300";"Greece";"12890";"11099737";"150";"39";"21.766";"39.666"
76
"GT";"GT";"GTM";"320";"Guatemala";"10843";"12709564";"19";"13";"-90.398";"15.256"
77
"GV";"GN";"GIN";"324";"Guinea";"24572";"9002656";"2";"11";"-10.942";"10.439"
78
"GY";"GY";"GUY";"328";"Guyana";"19685";"739472";"19";"5";"-58.974";"4.792"
79
"HA";"HT";"HTI";"332";"Haiti";"2756";"9296291";"19";"29";"-72.278";"19.142"
80
"HO";"HN";"HND";"340";"Honduras";"11189";"683411";"19";"13";"-86.863";"14.819"
81
"HR";"HR";"HRV";"191";"Croatia";"5592";"455149";"150";"39";"16.693";"45.723"
82
"HU";"HU";"HUN";"348";"Hungary";"9210";"10086387";"150";"151";"19.134";"47.070"
83
"IC";"IS";"ISL";"352";"Iceland";"10025";"295732";"150";"154";"-18.480";"64.764"
84
"IN";"IN";"IND";"356";"India";"297319";"1134403141";"142";"34";"78.500";"21.000"
85
"IR";"IR";"IRN";"364";"Iran (Islamic Republic of)";"163620";"69420607";"142";"34";"54.301";"32.565"
86
"IS";"IL";"ISR";"376";"Israel";"2171";"6692037";"142";"145";"34.851";"31.026"
87
"IT";"IT";"ITA";"380";"Italy";"29411";"5864636";"150";"39";"12.800";"42.700"
88
"IV";"CI";"CIV";"384";"Cote d'Ivoire";"31800";"18584701";"2";"11";"-5.556";"7.632"
89
"IZ";"IQ";"IRQ";"368";"Iraq";"43737";"27995984";"142";"145";"43.772";"33.048"
90
"JA";"JP";"JPN";"392";"Japan";"36450";"127896740";"142";"30";"139.068";"36.491"
91
"JM";"JM";"JAM";"388";"Jamaica";"1083";"2682469";"19";"29";"-77.320";"18.151"
92
"JO";"JO";"JOR";"400";"Jordan";"8824";"5544066";"142";"145";"36.319";"30.703"
93
"KE";"KE";"KEN";"404";"Kenya";"56914";"35598952";"2";"14";"37.858";"0.530"
94
"KG";"KG";"KGZ";"417";"Kyrgyzstan";"19180";"5203547";"142";"143";"74.555";"41.465"
95
"KN";"KP";"PRK";"408";"Korea, Democratic People's Republic of";"12041";"23615611";"142";"30";"126.451";"39.778"
96
"KR";"KI";"KIR";"296";"Kiribati";"73";"92003";"9";"57";"175.036";"-1.508"
97
"KS";"KR";"KOR";"410";"Korea, Republic of";"9873";"47869837";"142";"30";"128.103";"36.504"
98
"KU";"KW";"KWT";"414";"Kuwait";"1782";"2700";"142";"145";"47.376";"29.476"
99
"KZ";"KZ";"KAZ";"398";"Kazakhstan";"269970";"15210609";"142";"143";"67.301";"48.160"
100
"LA";"LA";"LAO";"418";"Lao People's Democratic Republic";"23080";"566391";"142";"35";"102.471";"19.905"
101
"LE";"LB";"LBN";"422";"Lebanon";"1023";"401074";"142";"145";"35.888";"33.920"
102
"LG";"LV";"LVA";"428";"Latvia";"6205";"2301793";"150";"154";"25.641";"56.858"
103
"BO";"BY";"BLR";"112";"Belarus";"20748";"9795287";"150";"151";"28.047";"53.540"
104
"LH";"LT";"LTU";"440";"Lithuania";"6268";"3425077";"150";"154";"23.897";"55.336"
105
"LI";"LR";"LBR";"430";"Liberia";"9632";"3441796";"2";"11";"-9.657";"6.682"
106
"LO";"SK";"SVK";"703";"Slovakia";"4808";"5386995";"150";"151";"19.491";"48.707"
107
"LS";"LI";"LIE";"438";"Liechtenstein";"16";"34598";"150";"155";"9.555";"47.153"
108
"LY";"LY";"LBY";"434";"Libyan Arab Jamahiriya";"175954";"5918217";"2";"15";"18.023";"27.044"
109
"MA";"MG";"MDG";"450";"Madagascar";"58154";"18642586";"2";"14";"46.706";"-19.374"
110
"MB";"MQ";"MTQ";"474";"Martinique";"106";"395896";"19";"29";"-61.021";"14.653"
111
"MG";"MN";"MNG";"496";"Mongolia";"156650";"2580704";"142";"30";"102.876";"46.056"
112
"MH";"MS";"MSR";"500";"Montserrat";"10";"5628";"19";"29";"-62.187";"16.736"
113
"MK";"MK";"MKD";"807";"The former Yugoslav Republic of Macedonia";"2543";"2033655";"150";"39";"21.698";"41.600"
114
"ML";"ML";"MLI";"466";"Mali";"122019";"1161109";"2";"11";"-3.524";"17.350"
115
"MO";"MA";"MAR";"504";"Morocco";"44630";"30494991";"2";"15";"-5.758";"32.706"
116
"MP";"MU";"MUS";"480";"Mauritius";"203";"1241173";"2";"14";"57.583";"-20.255"
117
"MR";"MR";"MRT";"478";"Mauritania";"102522";"2963105";"2";"11";"-10.332";"20.260"
118
"MT";"MT";"MLT";"470";"Malta";"32";"402617";"150";"39";"14.442";"35.890"
119
"MU";"OM";"OMN";"512";"Oman";"30950";"2507042";"142";"145";"57.407";"21.656"
120
"MV";"MV";"MDV";"462";"Maldives";"30";"295297";"142";"34";"72.920";"3.548"
121
"MX";"MX";"MEX";"484";"Mexico";"190869";"104266392";"19";"13";"-102.535";"23.951"
122
"MY";"MY";"MYS";"458";"Malaysia";"32855";"25652985";"142";"35";"102.195";"4.201"
123
"MZ";"MZ";"MOZ";"508";"Mozambique";"78409";"20532675";"2";"14";"37.923";"-14.422"
124
"MI";"MW";"MWI";"454";"Malawi";"9408";"13226091";"2";"14";"33.808";"-13.400"
125
"NC";"NC";"NCL";"540";"New Caledonia";"1828";"234185";"9";"54";"165.447";"-21.359"
126
"NE";"NU";"NIU";"570";"Niue";"26";"1632";"9";"61";"-169.869";"-19.052"
127
"NG";"NE";"NER";"562";"Niger";"126670";"1326419";"2";"11";"9.398";"17.426"
128
"AA";"AW";"ABW";"533";"Aruba";"0";"102897";"19";"29";"-69.977";"12.517"
129
"AV";"AI";"AIA";"660";"Anguilla";"0";"12256";"19";"29";"-63.032";"18.237"
130
"BE";"BE";"BEL";"56";"Belgium";"0";"10398049";"150";"155";"4.664";"50.643"
131
"HK";"HK";"HKG";"344";"Hong Kong";"0";"7057418";"142";"30";"114.129";"22.423"
132
"CQ";"MP";"MNP";"580";"Northern Mariana Islands";"0";"80258";"9";"57";"145.623";"15.005"
133
"FO";"FO";"FRO";"234";"Faroe Islands";"0";"48205";"150";"154";"-6.864";"62.050"
134
"AN";"AD";"AND";"20";"Andorra";"0";"73483";"150";"39";"1.576";"42.549"
135
"GI";"GI";"GIB";"292";"Gibraltar";"0";"291";"150";"39";"-5.345";"36.138"
136
"IM";"IM";"IMN";"833";"Isle of Man";"0";"78357";"150";"154";"-4.527";"54.229"
137
"LU";"LU";"LUX";"442";"Luxembourg";"0";"456613";"150";"155";"6.088";"49.771"
138
"MC";"MO";"MAC";"446";"Macau";"0";"47309";"142";"30";"113.545";"22.200"
139
"MN";"MC";"MCO";"492";"Monaco";"0";"325";"150";"155";"7.412";"43.750"
140
;"PS";"PSE";"275";"Palestine";"0";"3762005";"142";"145";"35.278";"32.037"
141
"MJ";"ME";"MNE";"499";"Montenegro";"0";"607969";"150";"39";"19.254";"42.792"
142
"MF";"YT";"MYT";"175";"Mayotte";"0";"0";"2";"14";"45.155";"-12.777"
143
;"AX";"ALA";"248";"Ã…land Islands";"0";"0";"150";"154";"19.952";"60.198"
144
"NF";"NF";"NFK";"574";"Norfolk Island";"0";"0";"9";"53";"167.953";"-29.037"
145
"CK";"CC";"CCK";"166";"Cocos (Keeling) Islands";"1";"0";"0";"0";"96.839";"-12.173"
146
"AY";"AQ";"ATA";"10";"Antarctica";"0";"0";"0";"0";"21.304";"-80.446"
147
"BV";"BV";"BVT";"74";"Bouvet Island";"0";"0";"0";"0";"3.412";"-54.422"
148
"FS";"TF";"ATF";"260";"French Southern and Antarctic Lands";"0";"0";"0";"0";"69.117";"-49.302"
149
"HM";"HM";"HMD";"334";"Heard Island and McDonald Islands";"0";"0";"0";"0";"73.507";"-53.111"
150
"IO";"IO";"IOT";"86";"British Indian Ocean Territory";"0";"0";"0";"0";"72.416";"-7.335"
151
"KT";"CX";"CXR";"162";"Christmas Island";"0";"0";"0";"0";"105.704";"-10.444"
152
;"UM";"UMI";"581";"United States Minor Outlying Islands";"0";"0";"0";"0";"-160.027";"-0.385"
153
"NH";"VU";"VUT";"548";"Vanuatu";"1219";"215366";"9";"54";"166.899";"-15.376"
154
"NI";"NG";"NGA";"566";"Nigeria";"91077";"141356083";"2";"11";"8.105";"9.594"
155
"NL";"NL";"NLD";"528";"Netherlands";"3388";"1632769";"150";"155";"5.389";"52.077"
156
"NO";"NO";"NOR";"578";"Norway";"30625";"4638836";"150";"154";"8.740";"61.152"
157
"NP";"NP";"NPL";"524";"Nepal";"14300";"27093656";"142";"34";"83.939";"28.253"
158
"NR";"NR";"NRU";"520";"Nauru";"2";"10111";"9";"57";"166.930";"-0.522"
159
"NS";"SR";"SUR";"740";"Suriname";"15600";"452468";"19";"5";"-55.912";"4.127"
160
"NU";"NI";"NIC";"558";"Nicaragua";"12140";"5462539";"19";"13";"-85.034";"12.840"
161
"NZ";"NZ";"NZL";"554";"New Zealand";"26799";"4097112";"9";"53";"172.235";"-42.634"
162
"PA";"PY";"PRY";"600";"Paraguay";"39730";"5904342";"19";"5";"-58.391";"-23.236"
163
"PE";"PE";"PER";"604";"Peru";"128000";"27274266";"19";"5";"-75.552";"-9.326"
164
"PK";"PK";"PAK";"586";"Pakistan";"77088";"158080591";"142";"34";"69.386";"29.967"
165
"PL";"PL";"POL";"616";"Poland";"30629";"38195558";"150";"151";"19.401";"52.125"
166
"PM";"PA";"PAN";"591";"Panama";"7443";"3231502";"19";"13";"-80.920";"8.384"
167
"PO";"PT";"PRT";"620";"Portugal";"9150";"10528226";"150";"39";"-8.058";"40.309"
168
"PP";"PG";"PNG";"598";"Papua New Guinea";"45286";"6069715";"9";"54";"143.459";"-5.949"
169
"PU";"GW";"GNB";"624";"Guinea-Bissau";"2812";"1596929";"2";"11";"-14.651";"12.125"
170
"QA";"QA";"QAT";"634";"Qatar";"1100";"796186";"142";"145";"51.191";"25.316"
171
"RE";"RE";"REU";"638";"Reunion";"250";"785159";"2";"14";"55.538";"-21.122"
172
"RO";"RO";"ROU";"642";"Romania";"22987";"21627557";"150";"151";"24.969";"45.844"
173
"MD";"MD";"MDA";"498";"Republic of Moldova";"3288";"3876661";"150";"151";"28.599";"47.193"
174
"RP";"PH";"PHL";"608";"Philippines";"29817";"84566163";"142";"35";"122.466";"11.118"
175
"RQ";"PR";"PRI";"630";"Puerto Rico";"887";"3946779";"19";"29";"-66.466";"18.221"
176
"RS";"RU";"RUS";"643";"Russia";"1638094";"143953092";"150";"151";"96.689";"61.988"
177
"RW";"RW";"RWA";"646";"Rwanda";"2467";"9233793";"2";"14";"29.917";"-1.998"
178
"SA";"SA";"SAU";"682";"Saudi Arabia";"214969";"2361236";"142";"145";"44.585";"24.023"
179
"SC";"KN";"KNA";"659";"Saint Kitts and Nevis";"36";"49138";"19";"29";"-62.769";"17.340"
180
"SE";"SC";"SYC";"690";"Seychelles";"46";"85532";"2";"14";"55.474";"-4.647"
181
"SF";"ZA";"ZAF";"710";"South Africa";"121447";"47938663";"2";"18";"23.121";"-30.558"
182
"LT";"LS";"LSO";"426";"Lesotho";"3035";"1980831";"2";"18";"28.243";"-29.581"
183
"BC";"BW";"BWA";"72";"Botswana";"56673";"1835938";"2";"18";"23.815";"-22.182"
184
"SG";"SN";"SEN";"686";"Senegal";"19253";"1177034";"2";"11";"-14.881";"15.013"
185
"SI";"SI";"SVN";"705";"Slovenia";"2014";"1999425";"150";"39";"14.827";"46.124"
186
"SL";"SL";"SLE";"694";"Sierra Leone";"7162";"5586403";"2";"11";"-11.792";"8.560"
187
"SN";"SG";"SGP";"702";"Singapore";"67";"4327468";"142";"35";"103.808";"1.351"
188
"SO";"SO";"SOM";"706";"Somalia";"62734";"8196395";"2";"14";"48.316";"9.774"
189
"SP";"ES";"ESP";"724";"Spain";"49904";"43397491";"150";"39";"-3.649";"40.227"
190
"ST";"LC";"LCA";"662";"Saint Lucia";"61";"16124";"19";"29";"-60.969";"13.898"
191
"SU";"SD";"SDN";"736";"Sudan";"237600";"36899747";"2";"15";"30.050";"13.832"
192
"SW";"SE";"SWE";"752";"Sweden";"41033";"9038049";"150";"154";"15.270";"62.011"
193
"SY";"SY";"SYR";"760";"Syrian Arab Republic";"18378";"18893881";"142";"145";"38.506";"35.013"
194
"SZ";"CH";"CHE";"756";"Switzerland";"4000";"7424389";"150";"155";"7.908";"46.861"
195
"TD";"TT";"TTO";"780";"Trinidad and Tobago";"513";"1323722";"19";"29";"-61.253";"10.468"
196
"TH";"TH";"THA";"764";"Thailand";"51089";"63002911";"142";"35";"100.844";"15.700"
197
"TI";"TJ";"TJK";"762";"Tajikistan";"13996";"6550213";"142";"143";"69.420";"38.665"
198
"TL";"TK";"TKL";"772";"Tokelau";"1";"1401";"9";"61";"-171.853";"-9.193"
199
"TN";"TO";"TON";"776";"Tonga";"72";"99361";"9";"61";"-175.185";"-21.202"
200
"TO";"TG";"TGO";"768";"Togo";"5439";"6238572";"2";"11";"1.081";"8.799"
201
"TP";"ST";"STP";"678";"Sao Tome and Principe";"96";"152622";"2";"17";"6.629";"0.201"
202
"TS";"TN";"TUN";"788";"Tunisia";"15536";"10104685";"2";"15";"9.596";"35.383"
203
"TU";"TR";"TUR";"792";"Turkey";"76963";"72969723";"142";"145";"35.179";"39.061"
204
"TV";"TV";"TUV";"798";"Tuvalu";"3";"10441";"9";"61";"179.219";"-8.514"
205
"TX";"TM";"TKM";"795";"Turkmenistan";"46993";"4833266";"142";"143";"59.384";"39.122"
206
"TZ";"TZ";"TZA";"834";"United Republic of Tanzania";"88359";"38477873";"2";"14";"34.823";"-6.270"
207
"UG";"UG";"UGA";"800";"Uganda";"19710";"28947181";"2";"14";"32.386";"1.280"
208
"UK";"GB";"GBR";"826";"United Kingdom";"24193";"60244834";"150";"154";"-1.600";"53.000"
209
"UP";"UA";"UKR";"804";"Ukraine";"57935";"46917544";"150";"151";"31.388";"49.016"
210
"US";"US";"USA";"840";"United States";"915896";"299846449";"19";"21";"-98.606";"39.622"
211
"UV";"BF";"BFA";"854";"Burkina Faso";"27360";"13933363";"2";"11";"-1.740";"12.278"
212
"UY";"UY";"URY";"858";"Uruguay";"17502";"3325727";"19";"5";"-56.012";"-32.800"
213
"UZ";"UZ";"UZB";"860";"Uzbekistan";"42540";"26593123";"142";"143";"63.170";"41.750"
214
"VC";"VC";"VCT";"670";"Saint Vincent and the Grenadines";"39";"119137";"19";"29";"-61.194";"13.248"
215
"VE";"VE";"VEN";"862";"Venezuela";"88205";"26725573";"19";"5";"-66.166";"7.125"
216
"VI";"VG";"VGB";"92";"British Virgin Islands";"15";"22016";"19";"29";"-64.390";"18.483"
217
"VM";"VN";"VNM";"704";"Viet Nam";"32549";"85028643";"142";"35";"105.314";"21.491"
218
"VQ";"VI";"VIR";"850";"United States Virgin Islands";"35";"111408";"19";"29";"-64.785";"17.741"
219
"WA";"NA";"NAM";"516";"Namibia";"82329";"2019677";"2";"18";"17.218";"-22.133"
220
"WF";"WF";"WLF";"876";"Wallis and Futuna Islands";"14";"15079";"9";"61";"-178.131";"-14.289"
221
"WS";"WS";"WSM";"882";"Samoa";"283";"183845";"9";"61";"-172.414";"-13.652"
222
"WZ";"SZ";"SWZ";"748";"Swaziland";"1720";"1124529";"2";"18";"31.497";"-26.562"
223
"YM";"YE";"YEM";"887";"Yemen";"52797";"21095679";"142";"145";"48.355";"15.807"
224
"ZA";"ZM";"ZMB";"894";"Zambia";"74339";"11478317";"2";"14";"26.320";"-14.614"
225
"ZI";"ZW";"ZWE";"716";"Zimbabwe";"38685";"13119679";"2";"14";"29.872";"-19.000"
226
"ID";"ID";"IDN";"360";"Indonesia";"181157";"226063044";"142";"35";"114.252";"-0.976"
227
"GP";"GP";"GLP";"312";"Guadeloupe";"169";"438403";"19";"29";"-61.441";"16.286"
228
"NT";"AN";"ANT";"530";"Netherlands Antilles";"80";"186392";"19";"29";"-68.870";"12.123"
229
"AE";"AE";"ARE";"784";"United Arab Emirates";"8360";"4104291";"142";"145";"54.163";"23.549"
230
"TT";"TL";"TLS";"626";"Timor-Leste";"1487";"1067285";"142";"35";"125.878";"-8.822"
231
"PC";"PN";"PCN";"612";"Pitcairn Islands";"0";"5";"9";"61";"-128.316";"-24.366"
232
"PS";"PW";"PLW";"585";"Palau";"0";"20127";"9";"57";"134.570";"7.501"
233
"RM";"MH";"MHL";"584";"Marshall Islands";"0";"5672";"9";"57";"168.963";"7.595"
234
"SB";"PM";"SPM";"666";"Saint Pierre and Miquelon";"0";"6346";"19";"21";"-56.325";"47.042"
235
"SH";"SH";"SHN";"654";"Saint Helena";"0";"6399";"2";"11";"-5.710";"-15.953"
236
"SM";"SM";"SMR";"674";"San Marino";"0";"30214";"150";"39";"12.460";"43.942"
237
"TK";"TC";"TCA";"796";"Turks and Caicos Islands";"0";"24459";"19";"29";"-71.950";"21.902"
238
"WI";"EH";"ESH";"732";"Western Sahara";"0";"440428";"2";"15";"-13.706";"24.554"
239
"RB";"RS";"SRB";"688";"Serbia";"0";"9863026";"150";"39";"20.806";"44.032"
240
"VT";"VA";"VAT";"336";"Holy See (Vatican City)";"0";"783";"150";"39";"12.451";"41.904"
241
"SV";"SJ";"SJM";"744";"Svalbard";"0";"0";"150";"154";"18.374";"78.830"
242
"RN";"MF";"MAF";"663";"Saint Martin";"0";"0";"19";"29";"-63.041";"18.094"
243
"TB";"BL";"BLM";"652";"Saint Barthelemy";"0";"0";"19";"29";"-63.043";"18.040"
244
"GK";"GG";"GGY";"831";"Guernsey";"0";"0";"150";"154";"-2.576";"49.459"
245
"JE";"JE";"JEY";"832";"Jersey";"0";"0";"150";"154";"-2.129";"49.219"
246
"SX";"GS";"SGS";"239";"South Georgia South Sandwich Islands";"0";"0";"0";"0";"-36.891";"-54.209"
247
"TW";"TW";"TWN";"158";"Taiwan";"0";"0";"0";"0";"120.946";"23.754"
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/test/java/org/gvsig/fmap/dal/store/jdbc2/AbstractTestUtils.java
397 397
        return store;
398 398
    }
399 399
    
400
    public FeatureStore openCountriesStore() throws Exception {
401
        return this.openCSVStore("/org/gvsig/fmap/dal/store/jdbc2/countries.csv");
402
    }
403

  
400 404
    public FeatureStore openSourceStore1() throws Exception {
401 405
        return this.openCSVStore("/org/gvsig/fmap/dal/store/jdbc2/testCreateSource1.csv");
402 406
    }
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/test/java/org/gvsig/fmap/dal/store/jdbc2/SQLBuilderTest.java
598 598
        //# attrNames:: [TYPE.DESCRIPTION, PHONE_TYPE.DESCRIPTION]
599 599

  
600 600
        assertEquals(
601
                "SELECT \"dbo\".\"test1\".\"ID\", \"dbo\".\"test1\".\"NAME\", \"dbo\".\"TYPES\".\"DESCRIPTION\", \"dbo\".\"test1\".\"TYPE\", \"dbo\".\"test1\".\"TYPE\" AS \"TYPE1\" FROM \"dbo\".\"test1\" LEFT JOIN \"dbo\".\"TYPES\" ON ( (\"dbo\".\"test1\".\"TYPE\") = (\"dbo\".\"TYPES\".\"ID\") ) LEFT JOIN \"dbo\".\"PHONE_TYPES\" ON ( (\"dbo\".\"test1\".\"PHONE_TYPE\") = (\"dbo\".\"PHONE_TYPES\".\"ID\") ) WHERE (( (\"dbo\".\"TYPES\".\"DESCRIPTION\") LIKE ('A%') ) AND ( (\"dbo\".\"PHONE_TYPES\".\"DESCRIPTION\") = ('mobile') )) ORDER BY \"TYPE\" ASC NULLS LAST",
601
//                "SELECT \"dbo\".\"test1\".\"ID\", \"dbo\".\"test1\".\"NAME\", \"dbo\".\"TYPES\".\"DESCRIPTION\", \"dbo\".\"test1\".\"TYPE\", \"dbo\".\"test1\".\"TYPE\" AS \"TYPE1\" FROM \"dbo\".\"test1\" LEFT JOIN \"dbo\".\"TYPES\" ON ( (\"dbo\".\"test1\".\"TYPE\") = (\"dbo\".\"TYPES\".\"ID\") ) LEFT JOIN \"dbo\".\"PHONE_TYPES\" ON ( (\"dbo\".\"test1\".\"PHONE_TYPE\") = (\"dbo\".\"PHONE_TYPES\".\"ID\") ) WHERE (( (\"dbo\".\"TYPES\".\"DESCRIPTION\") LIKE ('A%') ) AND ( (\"dbo\".\"PHONE_TYPES\".\"DESCRIPTION\") = ('mobile') )) ORDER BY \"TYPE\" ASC NULLS LAST",
602
                "SELECT \"dbo\".\"test1\".\"ID\", \"dbo\".\"test1\".\"NAME\", \"dbo\".\"TYPES\".\"DESCRIPTION\", \"dbo\".\"test1\".\"TYPE\", \"dbo\".\"test1\".\"TYPE\" AS \"TYPE1\", \"dbo\".\"TYPES\".\"DESCRIPTION\", \"dbo\".\"PHONE_TYPES\".\"DESCRIPTION\" FROM \"dbo\".\"test1\" LEFT JOIN \"dbo\".\"TYPES\" ON ( (\"dbo\".\"test1\".\"TYPE\") = (\"dbo\".\"TYPES\".\"ID\") ) LEFT JOIN \"dbo\".\"PHONE_TYPES\" ON ( (\"dbo\".\"test1\".\"PHONE_TYPE\") = (\"dbo\".\"PHONE_TYPES\".\"ID\") ) WHERE (( (\"dbo\".\"TYPES\".\"DESCRIPTION\") LIKE ('A%') ) AND ( (\"dbo\".\"PHONE_TYPES\".\"DESCRIPTION\") = ('mobile') )) ORDER BY \"TYPE\" ASC NULLS LAST",
602 603
                sqlbuilder.toString()
603 604
        );
604 605
        assertEquals(
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/fmap/dal/swing/searchpanel/FeatureStoreSearchPanel.java
95 95
    
96 96
    public boolean isAutomaticallySearch();
97 97
    
98
    public String getLastErrorMessage();
99
    
98 100
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/searchpanel/DefaultSearchPanel.java
10 10
import java.awt.event.KeyAdapter;
11 11
import java.awt.event.KeyEvent;
12 12
import java.net.URL;
13
import java.sql.SQLException;
13 14
import java.text.DateFormat;
14 15
import java.text.SimpleDateFormat;
15 16
import java.util.ArrayList;
......
137 138
	private final PropertiesSupportHelper propertiesHelper;
138 139
	private TaskStatusController taskStatusController;
139 140
        private boolean automaticallySearch;
141
        private String lastErrorMessage;
140 142
    private boolean initialized;
141 143

  
142 144
	public static class UseLabelsYesAction extends AbstractAction {
......
1007 1009
		status.setAutoremove(true);
1008 1010
		status.add();
1009 1011
		this.taskStatusController.bind(status);
1012
                List<Feature> features = null;
1010 1013
		try {
1011 1014
			status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Processing_search"));
1012 1015
			SwingUtilities.invokeLater(() -> {
......
1014 1017
				this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1015 1018
                            }
1016 1019
			});
1017
			final List<Feature> features;
1018 1020
			FeatureQuery myQuery;
1019 1021
//                myQuery = this.getQuery().getCopy();
1020 1022
			List<String> resultColumnNames = searchParams.getResultColumnNames();
......
1029 1031
				features
1030 1032
			);
1031 1033
			model.setValue(tableModel);
1032
			rowCount.setValue(tableModel.getRowCount());
1034
			rowCount.setValue(features.size());
1035
                        if(rowCount.longValue() > 0){
1036
                            //Force to get first row in this thread
1037
                            Feature f = features.get(0);
1038
                        }
1033 1039
        		resultModel = (SimpleFeaturesTableModel) model.getValue();
1034
		} catch (Exception ex) {
1035
			LOGGER.warn("Search not able to be executed. Can't get features or create table model", ex);
1036
			status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Errors_getting_new_feature_set") + "...");
1037
			status.abort();
1038
			resetTable();
1039
                        return STATUS_ERROR1;
1040
		} finally {
1041 1040
			SwingUtilities.invokeLater(() -> {
1042 1041
                            if(this.initialized){
1043 1042
				I18nManager i18n = ToolsLocator.getI18nManager();
......
1067 1066
				}
1068 1067
                            }
1069 1068
			});
1069
                        
1070
		} catch (Exception ex) {
1071
			LOGGER.warn("Search not able to be executed. Can't get features or create table model", ex);
1072
			status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Errors_getting_new_feature_set") + "...");
1073
			status.abort();
1074
                        DisposeUtils.disposeQuietly(features);
1075
                        this.lastErrorMessage = this.getLastErrorMessage(ex);
1076
                        if(StringUtils.isNotBlank(this.lastErrorMessage)){
1077
                            status.setTitle(this.lastErrorMessage);
1078
                        }
1079
			resetTable();
1080
                        return STATUS_ERROR1;
1070 1081
		}
1071 1082
                return STATUS_OK;
1072 1083
	}
......
1885 1896
    public boolean isAutomaticallySearch(){
1886 1897
        return automaticallySearch;
1887 1898
    }
1888
        
1899

  
1900
    @Override
1901
    public String getLastErrorMessage() {
1902
        return this.lastErrorMessage;
1903
    }
1904
    
1905
    private String getLastErrorMessage(Throwable ex) {
1906
        StringBuilder builder = new StringBuilder();
1907
        while (ex != null){
1908
            if(ex instanceof SQLException){
1909
                builder.append(ex.getLocalizedMessage());
1910
                builder.append("\n");
1911
            }
1912
            ex = ex.getCause();
1913
        }
1914
        return builder.toString();
1915
    }
1916
    
1889 1917
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/searchpanel/SearchConditionFieldController.java
33 33
import org.gvsig.fmap.dal.DALLocator;
34 34
import org.gvsig.fmap.dal.DataManager;
35 35
import org.gvsig.fmap.dal.DataStore;
36
import org.gvsig.fmap.dal.SQLBuilder;
36 37
import org.gvsig.fmap.dal.complements.Search;
37 38
import org.gvsig.fmap.dal.exception.DataException;
38 39
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder;
......
523 524
        final DefaultComboBoxModel model = new DefaultComboBoxModel();
524 525
        final FeatureStore theStore = field.getFeatureStore();
525 526
        final FeatureQuery query;
526
        if (this.store == theStore) {
527
            query = parameters.getQuery().getCopy(); // theStore.createFeatureQuery();
528
        } else {
529
            query = theStore.createFeatureQuery();
530
        }
527
        query = theStore.createFeatureQuery();
531 528
        query.addAttributeName(field.getDescriptor().getName());
532 529
        query.setFilter("");
533 530
        query.setLimit(updateValuesFeaturesLimit);
......
721 718
                        return;
722 719
                    }
723 720
                }
724
                // si no lo encuentra en el modelo lo a?ade
721
                // si no lo encuentra en el modelo lo a?ade
725 722
                final Field field = (Field) ddnFields.getSelectedItem();
726 723
                if (field == null) {
727 724
                    return;
......
1043 1040
                    );
1044 1041
                    op_composition = addNullBehavior(builder, op_composition, null_value);
1045 1042

  
1046
                    filter = builder.exists(builder.select()
1047
                            .column(parentDescriptor.getFeatureType().getPrimaryKey()[0].getName())
1048
                            .from(field.getFeatureStore().getName())
1049
                            .limit(1)
1050
                            .where(
1051
                                    builder.expression().and(
1052
                                            builder.expression().eq(
1053
                                                    builder.expression().column(
1054
                                                            field.getFeatureStore().getName(),
1055
                                                            getForeingKeyName(field.getFeatureStore(), this.store)
1056
                                                    ),
1057
                                                    builder.expression().column(
1058
                                                            this.store.getName(),
1059
                                                            getPrimaryKeyName(this.store)
1060
                                                    )
1061
                                            ),
1062
                                            op_composition
1063
                                    )
1064
                            )
1065
                            .toValue()
1066
                    );
1043
                    filter = buildExists(builder, field, op_composition);
1067 1044
                    break;
1068 1045
            }
1069 1046
        }
......
1072 1049
        return filter;
1073 1050
    }
1074 1051

  
1052
    private ExpressionBuilder.Value buildExists(DALExpressionBuilder builder, Field field, ExpressionBuilder.Value op_composition) {
1053
        ExpressionBuilder.Value filter;
1054
        SQLBuilder.SelectBuilder select = builder.select();
1055
        select.from().table().name(field.getFeatureStore().getName());
1056
        //select.column().name(parentDescriptor.getFeatureType().getPrimaryKey()[0].getName());
1057
        select.column().value(builder.expression().constant(1));
1058
        select.limit(1);
1059
        select.where().value(
1060
                builder.expression().and(
1061
                        builder.expression().eq(
1062
                                builder.expression().column(
1063
                                        field.getFeatureStore().getName(),
1064
                                        getForeingKeyName(field.getFeatureStore(), this.store)
1065
                                ),
1066
                                builder.expression().column(
1067
                                        this.store.getName(),
1068
                                        getPrimaryKeyName(this.store)
1069
                                )
1070
                        ),
1071
                        op_composition
1072
                )
1073
        );
1074
        filter = builder.exists(select);
1075
        return filter;
1076
    }
1077

  
1075 1078
    public JsonObject toJson() {
1076 1079
        JsonObjectBuilder fieldBuilder = Json.createObjectBuilder();
1077 1080

  
......
1230 1233
                            field.getFeatureStore().getName(),
1231 1234
                            descriptor.getName()
1232 1235
                    ));
1233
                    filter = builder.exists(builder.select()
1234
                            .column(parentDescriptor.getFeatureType().getPrimaryKey()[0].getName())
1235
                            .from(field.getFeatureStore().getName())
1236
                            .limit(1)
1237
                            .where(
1238
                                    builder.expression().and(
1239
                                            builder.expression().eq(
1240
                                                    builder.expression().column(
1241
                                                            field.getFeatureStore().getName(),
1242
                                                            getForeingKeyName(field.getFeatureStore(), this.store)
1243
                                                    ),
1244
                                                    builder.expression().column(
1245
                                                            this.store.getName(),
1246
                                                            getPrimaryKeyName(this.store)
1247
                                                    )
1248
                                            ),
1249
                                            op_composition
1250
                                    )
1251
                            )
1252
                            .toValue()
1253
                    );
1236
                    filter = buildExists(builder, field, op_composition);
1254 1237
            }
1255 1238
        }
1256 1239

  
......
1284 1267
                            descriptor.getName()
1285 1268
                    ));
1286 1269

  
1287
                    filter = builder.exists(builder.select()
1288
                            .column(parentDescriptor.getFeatureType().getPrimaryKey()[0].getName())
1289
                            .from(field.getFeatureStore().getName())
1290
                            .limit(1)
1291
                            .where(
1292
                                    builder.expression().and(
1293
                                            builder.expression().eq(
1294
                                                    builder.expression().column(
1295
                                                            field.getFeatureStore().getName(),
1296
                                                            getForeingKeyName(field.getFeatureStore(), this.store)
1297
                                                    ),
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff