Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionBuilder.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionBuilder.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionBuilder.java	(revision 44769)
@@ -167,6 +167,7 @@
         public String name();
         public List<Value> parameters();
         public Function parameter(Value parameter);
+        public Function format(String format);
     }
 
     public interface Method extends Value {
@@ -250,7 +251,7 @@
         }
     };
             
-    public static final Formatter<Value> BASE_FORMATTER = new BaseFormatter();
+    public Formatter<Value> formatter();
 
     public String quote_for_identifiers();
     
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionEvaluatorManager.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionEvaluatorManager.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionEvaluatorManager.java	(revision 44769)
@@ -57,6 +57,10 @@
     
     public ExpressionBuilder createExpressionBuilder();
 
+    public void registerExpressionBuilderFormatter(Formatter<ExpressionBuilder.Value> formatter);
+
+    public Formatter<ExpressionBuilder.Value> getExpressionBuilderFormatter();
+    
     public void registerGrammar(GrammarFactory factory) ;
 
     public Collection<GrammarFactory> getGrammarFactories();
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionUtils.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionUtils.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionUtils.java	(revision 44769)
@@ -125,16 +125,14 @@
             return null;
         }
         if( formatter==null ) {
-            formatter = ExpressionBuilder.BASE_FORMATTER;
+            ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
+            formatter = manager.getExpressionBuilderFormatter();
         }
         return value.toString(formatter);
     }
 
     public static String toString(Value value) {
-        if( value == null ) {
-            return null;
-        }
-        return value.toString(ExpressionBuilder.BASE_FORMATTER);
+      return toString(value, null);
     }
 
     public static String toString(Code code, Formatter formatter) {
@@ -148,10 +146,7 @@
     }
 
     public static String toString(Code code) {
-        if( code == null ) {
-            return null;
-        }
-        return code.toString(Code.EMPTY_FORMATTER);
+      return toString(code, null);
     }
 
     public static Expression createExpressionFromJSON(String json) {
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultStatement.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultStatement.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultStatement.java	(revision 44769)
@@ -21,6 +21,8 @@
 import org.gvsig.expressionevaluator.impl.function.programming.CodeBlockFunction;
 import org.gvsig.expressionevaluator.impl.DefaultCodeBuilder.BaseCodes;
 import org.gvsig.expressionevaluator.Code.Callable;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_TUPLE;
 
 /**
  *
@@ -666,7 +668,7 @@
                 if( context.isReservedWord(identifier) ) {
                     break;
                 }
-                Code code = context.getCodeBuilder().constant(identifier);
+                Code code = context.getCodeBuilder().identifier(identifier);
                 args.add(code);
                 context.next_token();
                 token = context.look_token();
@@ -683,7 +685,7 @@
                 );
             }
             if( this.id!=null ) {
-              Code code = context.getCodeBuilder().function(FUNCTION_LIST, args);
+              Code code = context.getCodeBuilder().function(FUNCTION_TUPLE, args);
               context.setCode(id, code);
             }
         }
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultExpressionBuilder.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultExpressionBuilder.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultExpressionBuilder.java	(revision 44769)
@@ -22,7 +22,6 @@
 import org.gvsig.expressionevaluator.ExpressionUtils;
 import org.gvsig.expressionevaluator.Formatter;
 import org.gvsig.expressionevaluator.ReprMethod;
-import static org.gvsig.expressionevaluator.ExpressionBuilder.BASE_FORMATTER;
 
 @SuppressWarnings({"UseSpecificCatch" ,"OverridableMethodCallInConstructor"})
 public class DefaultExpressionBuilder implements ExpressionBuilder {
@@ -55,7 +54,7 @@
     private static final String FORMAT_OPERATOR_DIV = "({0} / {1})";
     private static final String FORMAT_OPERATOR_CONCAT = "{0} || {1}";
 
-    public static class GroupBase extends AbstractValue implements Group {
+    public class GroupBase extends AbstractValue implements Group {
 
         protected Value value;
 
@@ -85,7 +84,7 @@
 
         @Override
         public String toString() {
-            return this.toString(BASE_FORMATTER);
+            return this.toString(formatter());
         }
         
         @Override
@@ -97,7 +96,7 @@
         }
     }
 
-    public static class VariableBase extends AbstractValue implements Variable {
+    public class VariableBase extends AbstractValue implements Variable {
 
         protected String name;
         protected ExpressionBuilder builder;
@@ -114,7 +113,7 @@
 
         @Override
         public String toString() {
-            return this.toString(BASE_FORMATTER);
+            return this.toString(formatter());
         }
         
         @Override
@@ -146,7 +145,7 @@
         }
     }
 
-    public static class ParameterBase extends AbstractValue implements Parameter {
+    public class ParameterBase extends AbstractValue implements Parameter {
 
         protected String name;
         protected Object value;
@@ -242,7 +241,7 @@
 
         @Override
         public String toString() {
-            return this.toString(BASE_FORMATTER);
+            return this.toString(formatter());
         }
         
         @Override
@@ -261,7 +260,7 @@
         }
     }
 
-    public static class ConstantBase extends AbstractValue implements Constant {
+    public class ConstantBase extends AbstractValue implements Constant {
 
         protected Object value;
         protected ExpressionBuilder builder;
@@ -278,7 +277,7 @@
 
         @Override
         public String toString() {
-            return this.toString(BASE_FORMATTER);
+            return this.toString(formatter());
         }
         
         @Override
@@ -308,7 +307,7 @@
         }
     }
 
-    public static class CustomBase extends AbstractValue implements Custom {
+    public class CustomBase extends AbstractValue implements Custom {
 
         protected Object value;
 
@@ -370,7 +369,7 @@
 
         @Override
         public String toString() {
-            return this.toString(BASE_FORMATTER);
+            return this.toString(formatter());
         }
         
         @Override
@@ -382,7 +381,7 @@
         }
     }
 
-    public static class FunctionBase extends AbstractValue implements Function {
+    public class FunctionBase extends AbstractValue implements Function {
 
         protected String name;
         protected String format;
@@ -406,6 +405,12 @@
         }
 
         @Override
+        public Function format(String format) {
+          this.format = format;
+          return this;
+        }
+
+        @Override
         public Function parameter(Value parameter) {
             this.parameters().add(parameter);
             return this;
@@ -444,7 +449,7 @@
         
         @Override
         public String toString() {
-            return this.toString(BASE_FORMATTER);
+            return this.toString(formatter());
         }
         
         @Override
@@ -601,7 +606,7 @@
 
         @Override
         public String toString() {
-            return this.toString(BASE_FORMATTER);
+            return this.toString(formatter());
         }
         
         @Override
@@ -631,10 +636,19 @@
 
     protected Value value;
     protected ExpressionEvaluatorManager manager;
+    protected Formatter<ExpressionBuilder.Value> formatter;
 
     public DefaultExpressionBuilder(ExpressionEvaluatorManager manager) {
         this.manager = manager;
     }
+    
+    @Override
+    public Formatter<ExpressionBuilder.Value> formatter() {
+      if( this.formatter == null ) {
+        this.formatter = this.manager.getExpressionBuilderFormatter();
+      }
+      return this.formatter;
+    }
 
     @Override
     public boolean isEmpty() {
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultExpressionEvaluatorManager.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultExpressionEvaluatorManager.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultExpressionEvaluatorManager.java	(revision 44769)
@@ -29,10 +29,12 @@
 import org.gvsig.expressionevaluator.SymbolTable;
 import org.gvsig.expressionevaluator.SymbolTableFactory;
 import org.gvsig.expressionevaluator.Compiler;
+import org.gvsig.expressionevaluator.Formatter;
 import org.gvsig.expressionevaluator.GrammarSet;
 import org.gvsig.expressionevaluator.ReprMethod;
 import org.gvsig.expressionevaluator.impl.repr.ReprNull;
 import org.gvsig.expressionevaluator.impl.repr.ReprObject;
+import org.gvsig.expressionevaluator.spi.formatter.value.BaseFormatter;
 import org.gvsig.tools.bookmarksandhistory.Bookmarks;
 import org.gvsig.tools.bookmarksandhistory.History;
 import org.gvsig.tools.bookmarksandhistory.impl.BaseBookmarks;
@@ -56,6 +58,7 @@
     private SymbolTable inmutableSymbolTable;
     private ResourcesStorage scriptsResourcesStorage;
     private List<ClassLoader> loaders;
+    private Formatter<ExpressionBuilder.Value> expressionBuilderFormatter;
 
     public DefaultExpressionEvaluatorManager() {
         this.symbolTableFactories = new HashMap<>();
@@ -63,6 +66,7 @@
         this.loaders = new ArrayList<>();
         this.scriptsResourcesStorage = ResourcesStorage.EMPTY_RESOURCESSTORAGE;
         this.loaders.add(this.getClass().getClassLoader());
+        this.expressionBuilderFormatter = new BaseFormatter();
     }
 
     @Override
@@ -471,5 +475,16 @@
     public List<ClassLoader> getClassLoaders() {
       return Collections.unmodifiableList(loaders);
     }
+
+    @Override
+    public Formatter<ExpressionBuilder.Value> getExpressionBuilderFormatter() {
+      return expressionBuilderFormatter;
+    }
+
+    @Override
+    public void registerExpressionBuilderFormatter(Formatter<ExpressionBuilder.Value> formatter) {
+      this.expressionBuilderFormatter = formatter;
+    }
+    
 }
 
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestDateExpressionBuilder.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestDateExpressionBuilder.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestDateExpressionBuilder.java	(revision 44769)
@@ -62,8 +62,6 @@
     protected SymbolTable createSymbolTable() {
         ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
         MutableSymbolTable symbolTable = manager.createSymbolTable();
-        symbolTable.setVar("precio", 200);
-        symbolTable.setVar("1990", 0.168873933773767);
         return symbolTable;
     }
 
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultGeometryExpressionBuilderHelper.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultGeometryExpressionBuilderHelper.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultGeometryExpressionBuilderHelper.java	(revision 44769)
@@ -7,17 +7,15 @@
 import org.gvsig.fmap.geom.Geometry;
 import org.gvsig.fmap.geom.primitive.Envelope;
 
-import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_VARIABLE;
 import org.gvsig.expressionevaluator.ExpressionBuilder.AbstractValue;
 import org.gvsig.expressionevaluator.ExpressionBuilder.Constant;
 import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
 import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_CONSTANT;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_VARIABLE;
 import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
 import org.gvsig.expressionevaluator.ExpressionBuilder.Visitor;
 import org.gvsig.expressionevaluator.ExpressionBuilder.VisitorFilter;
 import org.gvsig.expressionevaluator.Formatter;
-import org.gvsig.expressionevaluator.impl.DefaultExpressionBuilder.FunctionBase;
-import org.gvsig.expressionevaluator.impl.DefaultExpressionBuilder.ParameterBase;
 import org.gvsig.fmap.geom.GeometryUtils;
 import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper;
 import static org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.PARAMETER_TYPE_GEOMETRY;
@@ -45,13 +43,15 @@
     private static final String FORMAT_ST_GEOMFROMEWKB = "ST_GeomFromEWKB(({0}), ({1}))";
     private static final String FORMAT_ST_SIMPLIFY = "ST_Simplify(({0}), ({1}))";
 
-    public static class GeometryParameterBase 
-            extends ParameterBase 
+    public class GeometryParameterBase 
+            extends AbstractValue 
             implements GeometryParameter {
 
         protected Value srs;
         protected GeometryExpressionBuilderHelper builder;
-
+        protected String name;
+        protected Object value;
+        protected int type;
         /*
         Para un parametro de tipo Geometria, el srs sera siempre un Constant
         excepto cuando se le asigne una geometria contante al parametro y esta
@@ -61,7 +61,9 @@
         Si se quiere que el SRS sea un Parameter, se construira como tal.
         */
         public GeometryParameterBase(GeometryExpressionBuilderHelper builder) {
-            super();
+            this.type = PARAMETER_TYPE_CONSTANT;
+            this.name = null;
+            this.value = null;
             this.builder = builder;
         }
 
@@ -122,17 +124,69 @@
             return (Geometry) this.value;
         }
 
+
         @Override
-        public GeometryParameter name(String value) {
-            return (GeometryParameter) super.name(value);
+        public GeometryParameter as_constant() {
+            this.type = PARAMETER_TYPE_CONSTANT;
+            if (this.value == null && this.name != null) {
+                this.value = this.name;
+            }
+            return this;
         }
 
         @Override
         public GeometryParameter as_variable() {
-            return (GeometryParameter) super.as_variable();
+            this.type = PARAMETER_TYPE_VARIABLE;
+            if (this.value != null && this.name == null) {
+                this.name = (String) this.value;
+            }
+            return this;
         }
+
+        @Override
+        public GeometryParameter name(String name) {
+            this.type = PARAMETER_TYPE_VARIABLE;
+            this.name = name;
+            return this;
+        }
         
         @Override
+        public String name() {
+            switch (this.type) {
+                case PARAMETER_TYPE_VARIABLE:
+                    return this.name;
+                case PARAMETER_TYPE_CONSTANT:
+                    if (this.value == null) {
+                        return null;
+                    }
+                    return this.value.toString();
+                default:
+                    if (this.name != null) {
+                        return this.name;
+                    }
+                    if (this.value != null) {
+                        return this.value.toString();
+                    }
+                    return null;
+            }
+        }
+
+        @Override
+        public int type() {
+            return this.type;
+        }
+
+        @Override
+        public boolean is_constant() {
+            return this.type == PARAMETER_TYPE_CONSTANT;
+        }
+
+        @Override
+        public boolean is_variable() {
+            return this.type == PARAMETER_TYPE_VARIABLE;
+        }
+
+        @Override
         public GeometryParameter as_geometry_variable() {
             this.type = PARAMETER_TYPE_GEOMETRY;
             if (this.value == null && this.name != null) {
@@ -147,19 +201,6 @@
         }
 
         @Override
-        public GeometryParameter as_constant() {
-            return (GeometryParameter) super.as_constant();
-        }
-
-        @Override
-        public String name() {
-            if( this.type == PARAMETER_TYPE_VARIABLE ) {
-                return this.name;
-            }
-            return super.name();
-        }
-
-        @Override
         public Object value() {
             try {
                 switch (this.type) {
@@ -188,6 +229,11 @@
                 throw new RuntimeException("Can't get value from parameter.", ex);
             }
         }
+        
+        @Override
+        public String toString() {
+          return this.toString(this.builder.builder().formatter()); 
+        }
 
         @Override
         public String toString(Formatter<Value> formatter) {
@@ -310,6 +356,11 @@
         }
 
         @Override
+        public String toString() {
+          return this.toString(builder.builder().formatter()); 
+        }
+
+        @Override
         public String toString(Formatter<Value> formatter) {
             if( formatter!=null && formatter.canApply(this) ) {
                 return formatter.format(this);
@@ -368,6 +419,11 @@
         }
 
         @Override
+        public String toString() {
+          return this.toString(this.builder.builder().formatter()); 
+        }
+
+        @Override
         public String toString(Formatter<Value> formatter) {
             if( formatter!=null && formatter.canApply(this) ) {
                 return formatter.format(this);
@@ -474,18 +530,13 @@
     }
 
     public Function builtin_function(String name, String format, Value... values) {
-        FunctionBase func = new FunctionBase(name, format);
-        for (Value theValue : values) {
-            func.parameter(theValue);
-        }
+        Function func = this.builder.function(name, values);
+        func.format(format);
         return func;
     }    
     
     public Function function(String name, Value... values) {
-        FunctionBase func = new FunctionBase(name);
-        for (Value theValue : values) {
-            func.parameter(theValue);
-        }
+        Function func = this.builder.function(name, values);
         return func;
     }    
     
Index: 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
===================================================================
--- 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	(revision 44768)
+++ 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	(revision 44769)
@@ -696,7 +696,7 @@
         case DynField.RELATION_TYPE_COMPOSITION:
           filter = builder.exists(builder.select()
                   .column(parentDescriptor.getFeatureType().getPrimaryKey()[0].getName())
-                  .table(field.getFeatureStore().getName())
+                  .from(field.getFeatureStore().getName())
                   .limit(1)
                   .where(
                           builder.expression().and(
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/expressionevaluator/DALExpressionBuilder.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/expressionevaluator/DALExpressionBuilder.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/expressionevaluator/DALExpressionBuilder.java	(revision 44769)
@@ -3,8 +3,7 @@
 import org.gvsig.expressionevaluator.ExpressionBuilder;
 import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
 import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
-import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW;
-import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_STORE;
+import org.gvsig.expressionevaluator.Formatter;
 
 /**
  *
@@ -18,7 +17,7 @@
     
     public SelectBuilder column_all();
     
-    public SelectBuilder table(String tableName);
+    public SelectBuilder from(String tableName); // from === table
     
     public SelectBuilder where(Value where);
     
@@ -30,6 +29,9 @@
     
     @Override
     public String toString();
+    
+    public String toString(Formatter<Value> formatter);
+    
   }
   
   public interface SelectCountBuilder {
@@ -46,6 +48,10 @@
 
   public ExpressionBuilder expression();
   
+  public Formatter<Value> formatter();
+  
+  public Formatter<Value> formatter(Formatter<Value> formatter);
+  
   public SelectBuilder select();
   
   public SelectCountBuilder select_count();
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/SQLBuilderBase.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/SQLBuilderBase.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/SQLBuilderBase.java	(revision 44769)
@@ -52,7 +52,6 @@
 import org.gvsig.tools.dataTypes.DataType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import static org.gvsig.expressionevaluator.ExpressionBuilder.BASE_FORMATTER;
 
 @SuppressWarnings("UseSpecificCatch")
 public class SQLBuilderBase implements SQLBuilder {
@@ -346,7 +345,7 @@
 
         @Override
         public String toString() {
-            return this.toString(BASE_FORMATTER);
+            return this.toString(formatter());
         }
         
         @Override
@@ -2980,7 +2979,7 @@
     }
 
     protected Formatter formatter() {
-        return ExpressionBuilder.BASE_FORMATTER;
+        return expression().formatter();
     }
 
     @Override
Index: 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/DALExpressionEvaluatorImplLibrary.java
===================================================================
--- 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/DALExpressionEvaluatorImplLibrary.java	(revision 44768)
+++ 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/DALExpressionEvaluatorImplLibrary.java	(revision 44769)
@@ -1,51 +0,0 @@
-/**
- * gvSIG. Desktop Geographic Information System.
- *
- * Copyright (C) 2007-2020 gvSIG Association.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.
- *
- * For any additional information, do not hesitate to contact us
- * at info AT gvsig.com, or visit our website www.gvsig.com.
- */
-package org.gvsig.expressionevaluator.impl;
-
-import org.gvsig.expressionevaluator.ExpressionEvaluatorLibrary;
-import org.gvsig.expressionevaluator.impl.symboltable.DALSymbolTableFactory;
-import org.gvsig.fmap.dal.DALLibrary;
-import org.gvsig.tools.ToolsLibrary;
-import org.gvsig.tools.library.AbstractLibrary;
-import org.gvsig.tools.library.LibraryException;
-
-public class DALExpressionEvaluatorImplLibrary extends AbstractLibrary {
-
-    @Override
-    public void doRegistration() {
-        registerAsServiceOf(ExpressionEvaluatorLibrary.class);
-        require(ToolsLibrary.class);
-        require(DALLibrary.class);
-    }
-
-    @Override
-    protected void doInitialize() throws LibraryException {
-    }
-
-    @Override
-    protected void doPostInitialize() throws LibraryException {
-        DALSymbolTableFactory.selfRegister();
-    }
-}
-
Index: 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/Exists.java
===================================================================
--- 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/Exists.java	(revision 0)
+++ 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/Exists.java	(revision 44769)
@@ -0,0 +1,36 @@
+package org.gvsig.expressionevaluator.impl.expressionbuilder.formatters;
+
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import static org.gvsig.fmap.dal.DataManager.FUNCTION_EXISTS;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class Exists implements Formatter<Value> {
+    
+    private final Formatter<Value> formatter;
+    
+    public Exists(Formatter<Value> formatter) {
+        this.formatter = formatter;
+    }
+    @Override
+    public boolean canApply(ExpressionBuilder.Value value) {
+        if (value instanceof ExpressionBuilder.Function) {
+            return StringUtils.equalsIgnoreCase(FUNCTION_EXISTS, ((Function) value).name());
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value function0) {
+        Function function = (Function) function0;
+        Value exp = function.parameters().get(0);
+        return "EXISTS("+exp.toString(formatter)+")";
+    }
+    
+}
Index: 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
===================================================================
--- 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	(revision 0)
+++ 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	(revision 44769)
@@ -0,0 +1,98 @@
+package org.gvsig.expressionevaluator.impl.expressionbuilder.formatters;
+
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_TUPLE;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import static org.gvsig.fmap.dal.DataManager.FUNCTION_SELECT;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+@SuppressWarnings("UseSpecificCatch")
+public class Select implements Formatter<Value> {
+
+  private final Formatter<Value> formatter;
+
+  public Select(Formatter<Value> formatter) {
+    this.formatter = formatter;
+  }
+
+  @Override
+  public boolean canApply(ExpressionBuilder.Value value) {
+    if (value instanceof ExpressionBuilder.Function) {
+      return StringUtils.equalsIgnoreCase(FUNCTION_SELECT, ((Function) value).name());
+    }
+    return false;
+  }
+
+  private static final int COLUMNS = 0;
+  private static final int TABLE = 1;
+  private static final int WHERE = 2;
+  private static final int ORDER = 3;
+  private static final int ORDER_MODE = 4;
+  private static final int LIMIT = 5;
+
+  @Override
+  public String format(Value function0) {
+    Function function = (Function) function0;
+    String tableName = (String) function.parameters().get(TABLE).toString();
+    Value where = function.parameters().get(WHERE);
+    Value order = function.parameters().get(ORDER);
+    Value limit = function.parameters().get(LIMIT);
+    Value order_mode = function.parameters().get(ORDER_MODE);
+
+    StringBuilder builder = new StringBuilder();
+    builder.append("(SELECT ");
+
+    try {
+      Function columns = (Function) function.parameters().get(COLUMNS);
+      if (!StringUtils.equalsIgnoreCase(((ExpressionBuilder.Function) columns).name(), FUNCTION_TUPLE)) {
+        throw new IllegalArgumentException();
+      }
+      if( columns.parameters().isEmpty() ) {
+            builder.append("* ");
+      } else {
+        boolean needcomma = false;
+        for (Value parameter : columns.parameters()) {
+          if(needcomma) {
+            builder.append(", ");
+          } else {
+            needcomma = true;
+          }
+          builder.append(parameter.toString(formatter));
+        }
+      }
+    } catch (Exception ex) {
+      throw new IllegalArgumentException("Invalid columns, need a tuple function as columns.");
+    }
+
+    builder.append(" FROM ");
+    builder.append(tableName);
+    if (where != null) {
+      builder.append(" WHERE ");
+      builder.append(where.toString(formatter));
+    }
+//        for( int n=0 ; function.containsParameter("ORDER", n); n++) {
+//          if( n>0 ) {
+//            builder.append(", ");
+//          }
+//          builder.append(function.getParameter("ORDER",n).toString(formatter));
+//          if( StringUtils.equalsIgnoreCase(function.getParameter("ORDER_MODE",n).toString(),"true") ) {
+//            builder.append(" ASC ");
+//          } else {
+//            builder.append(" DESC ");
+//          }
+//        }
+    if (limit != null) {
+      builder.append(" LIMIT ");
+      builder.append(limit.toString(formatter));
+    }
+    builder.append(")");
+    return builder.toString();
+  }
+
+}
Index: 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/DALFormatter.java
===================================================================
--- 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/DALFormatter.java	(revision 0)
+++ 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/DALFormatter.java	(revision 44769)
@@ -0,0 +1,58 @@
+package org.gvsig.expressionevaluator.impl.expressionbuilder.formatters;
+
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
+import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.expressionevaluator.spi.formatter.value.BaseFormatter;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class DALFormatter implements Formatter<Value> {
+
+    private final Formatter<ExpressionBuilder.Value>[] formatters;
+
+    public DALFormatter() {
+      this(null);
+    }
+    
+    public DALFormatter(Formatter<Value> formatter) {
+        if( formatter==null ) {
+          formatter = this;
+        }
+        this.formatters = new Formatter[]{
+            // new Exists(formatter),
+            new Select(formatter),
+            new BaseFormatter(formatter)
+        };
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        for (Formatter<Value> formatter : formatters) {
+            if (formatter.canApply(value)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value value) {
+        for (Formatter<Value> formatter : formatters) {
+            if (formatter.canApply(value)) {
+                return formatter.format(value);
+            }
+        }
+        return value.toString(this);
+    }
+    
+    public static void selfRegister() {
+      ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getExpressionEvaluatorManager();
+      manager.registerExpressionBuilderFormatter(new DALFormatter());
+    }
+    
+}
Index: 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/DALFunctions.java
===================================================================
--- 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/DALFunctions.java	(revision 44768)
+++ 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/DALFunctions.java	(revision 44769)
@@ -23,6 +23,10 @@
  */
 package org.gvsig.expressionevaluator.impl;
 
+import org.gvsig.expressionevaluator.impl.expressionbuilder.formatters.DALFormatter;
+import org.gvsig.expressionevaluator.impl.grammars.DataAccessGrammarFactory;
+import org.gvsig.expressionevaluator.impl.symboltable.DALSymbolTableFactory;
+
 /**
  *
  * @author jjdelcerro
@@ -34,4 +38,9 @@
 
   public static final String GROUP_DATA_ACCESS = "Data access";
 
+  public static void register() {
+    DataAccessGrammarFactory.selfRegister();
+    DALSymbolTableFactory.selfRegister();
+    DALFormatter.selfRegister();
+  }
 }
Index: 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/grammars/DataAccessGrammarFactory.java
===================================================================
--- 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/grammars/DataAccessGrammarFactory.java	(revision 44768)
+++ 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/grammars/DataAccessGrammarFactory.java	(revision 44769)
@@ -24,13 +24,11 @@
 package org.gvsig.expressionevaluator.impl.grammars;
 
 import java.util.UUID;
-import org.apache.commons.lang3.StringUtils;
 import org.gvsig.expressionevaluator.Code;
 import org.gvsig.expressionevaluator.CodeBuilder;
 import org.gvsig.expressionevaluator.Codes;
 import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
 import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
-import org.gvsig.expressionevaluator.ExpressionSyntaxException;
 import org.gvsig.expressionevaluator.Grammar;
 import org.gvsig.expressionevaluator.Statement;
 import org.gvsig.expressionevaluator.Statement.ArgsBuilder;
@@ -97,36 +95,27 @@
     @Override
     public Codes build(StatementContext context) {
       context.trace(this.toString() + ".build");
+      int n;
+      BaseCodes argsX;
+      
       CodeBuilder codeBuilder = context.getCodeBuilder();
       BaseCodes args = (BaseCodes) codeBuilder.args();
 
       Code columns = context.getCode("COLUMNS");
-      Code table = context.getCode("TABLE");
-      Code where = context.getCode("WHERE");
-//      Code order = context.getCode("ORDER");
-//      Code order_mode = context.getCode("ORDER_MODE");
-      Code limit = context.getCode("LIMIT");
-
-      if (columns == null) {
-        throw new ExpressionSyntaxException();
-      }
-      Callable tuple = codeBuilder.tuple();
-      args.add(tuple);
-      String s = (String) ((Code.Constant) columns).value();
-      if (!StringUtils.equalsIgnoreCase(s, "*")) {
-        ((BaseCodes) (tuple.parameters())).add(codeBuilder.constant(1));
-      }
+      args.add(columns);
       
+      Code table = context.getCode("TABLE");
       args.add(codeBuilder.identifier((String) ((Code.Constant) table).value()));
 
+      Code where = context.getCode("WHERE");
       if (where == null) {
         args.add(codeBuilder.constant(null));
       } else {
         args.add(where);
       }
 
-      int n = 1;
-      BaseCodes argsX = (BaseCodes) codeBuilder.args();
+      n = 1;
+      argsX = (BaseCodes) codeBuilder.args();
       while (true) {
         String argNameX = "ORDER" + String.valueOf(n);
         Code code = context.getCode(argNameX);
@@ -151,6 +140,7 @@
       }
       args.add(codeBuilder.tuple(argsX));
 
+      Code limit = context.getCode("LIMIT");
       if (limit == null) {
         args.add(codeBuilder.constant(null));
       } else {
@@ -201,9 +191,11 @@
   public Grammar create(Object... parameters) {
     ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
     if (this.grammar == null) {
+      CodeBuilder codeBuilder = manager.createCodeBuilder();
       Grammar theGrammar = manager.createGrammar(this.getName());
+      
       Statement stmt;
-
+      
       theGrammar.addReservedWord("EXISTS");
       theGrammar.addReservedWord("SELECT");
       theGrammar.addReservedWord("FROM");
@@ -237,10 +229,9 @@
 
       stmt = theGrammar.createStatement("SELECT");
       stmt.addRule(stmt.require_any_token("SELECT"));
-      stmt.addRule(stmt.switch_token()
-              .addCase("*", stmt.set_expression("COLUMNS", "*"))
-              .addCase("1", stmt.set_expression("COLUMNS", "1"))
-              .addDefault(stmt.fail())
+      stmt.addRule(stmt.optional_any_token("*")
+              .addRuleOnTrue(stmt.set_expression("COLUMNS", codeBuilder.tuple()))
+              .addRuleOnFalse(stmt.require_identifiers(",").capture_as("COLUMNS"))
       );
       stmt.addRule(stmt.require_any_token("FROM"));
       stmt.addRule(stmt.require_identifier().capture_as("TABLE"));
Index: 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
===================================================================
--- 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	(revision 44768)
+++ 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	(revision 44769)
@@ -4,6 +4,8 @@
 import org.gvsig.expressionevaluator.ExpressionBuilder;
 import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
 import org.gvsig.expressionevaluator.ExpressionUtils;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.expressionevaluator.impl.expressionbuilder.formatters.DALFormatter;
 import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW;
 import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_STORE;
 import static org.gvsig.fmap.dal.DataManager.FUNCTION_EXISTS;
@@ -49,7 +51,7 @@
     }
 
     @Override
-    public SelectBuilder table(String tableName) {
+    public SelectBuilder from(String tableName) {
       this.tableName = tableName;
       return this;
     }
@@ -89,11 +91,17 @@
 
     @Override
     public String toString() {
-      return this.toValue().toString();
+      return this.toString(formatter());
     }
     
+    @Override
+    public String toString(Formatter<Value> formatter) {
+      return this.toValue().toString(formatter);
+    }
+    
   }
   
+  
   private class DefaultSelectCountBuilder implements SelectCountBuilder {
     
     private String tableName;
@@ -143,6 +151,16 @@
   }
   
   @Override
+  public Formatter<Value> formatter() {
+    return this.formatter(null);
+  }
+  
+  @Override
+  public Formatter<Value> formatter(Formatter<Value> formatter) {
+    return new DALFormatter(formatter);
+  }
+  
+  @Override
   public SelectBuilder select() {
     return new DefaultSelectBuilder();
   }
Index: 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/impl/DALDefaultImplLibrary.java
===================================================================
--- 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/impl/DALDefaultImplLibrary.java	(revision 44768)
+++ 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/impl/DALDefaultImplLibrary.java	(revision 44769)
@@ -28,6 +28,7 @@
 import java.util.List;
 import java.util.Map;
 import org.gvsig.expressionevaluator.ExpressionEvaluatorLibrary;
+import org.gvsig.expressionevaluator.impl.DALFunctions;
 import org.gvsig.expressionevaluator.impl.grammars.DataAccessGrammarFactory;
 import org.gvsig.expressionevaluator.impl.symboltable.DALSymbolTableFactory;
 
@@ -193,8 +194,8 @@
         registerTags();
         DefaultFeatureAttributeDescriptor.registerPersistenceDefinition();
         DefaultFeatureType.registerPersistenceDefinition();
-        DataAccessGrammarFactory.selfRegister();
-        DALSymbolTableFactory.selfRegister();
+
+        DALFunctions.register();
         
         if (exs.size() > 0) {
             throw new LibraryException(this.getClass(), exs);
Index: 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
===================================================================
--- 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	(revision 0)
+++ 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	(revision 44769)
@@ -0,0 +1,101 @@
+package org.gvsig.expressionevaluator;
+
+import junit.framework.TestCase;
+import org.gvsig.expressionevaluator.impl.expressionbuilder.formatters.DALFormatter;
+import org.gvsig.fmap.dal.DALLocator;
+import org.gvsig.fmap.dal.DataManager;
+import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder;
+import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder.SelectBuilder;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class TestExpressionBuilder extends TestCase {
+
+    public TestExpressionBuilder(String testName) {
+        super(testName);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        new DefaultLibrariesInitializer().fullInitialize();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    // TODO add test methods here. The name must begin with 'test'. For example:
+    // public void testHello() {}
+    
+    protected LexicalAnalyzer createLexicalAnalyzer() {
+        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
+        LexicalAnalyzer lexer = manager.createLexicalAnalyzer();
+        return lexer;
+    }
+
+    protected org.gvsig.expressionevaluator.Compiler createCompiler() {
+        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
+        Compiler compiler = manager.createCompiler();
+        compiler.setLexicalAnalyzer(createLexicalAnalyzer());
+        return compiler;
+    }
+
+    protected SymbolTable createSymbolTable() {
+        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
+        MutableSymbolTable symbolTable = manager.createSymbolTable();
+        return symbolTable;
+    }
+
+    protected Interpreter createInterpreter(SymbolTable symbolTable) {
+        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
+        Interpreter interpreter = manager.createInterpreter();
+        interpreter.setSymbolTable(symbolTable);
+        return interpreter;
+    }
+    
+    private void link(Code code) {
+      code.link(createSymbolTable());
+    }
+
+    public void testUseCase1() {
+      DataManager dataManager = DALLocator.getDataManager();
+      DALExpressionBuilder builder = dataManager.createDALExpressionBuilder();
+
+      SelectBuilder select = builder.select()
+              .column("LID_ACCIDENTE")
+              .from("ARENA2_VEHICULOS")
+              .where(
+                      builder.expression().and(
+                              builder.expression().eq(
+                                      builder.expression().getattr("ARENA2_VEHICULOS","ID_ACCIDENTE"),
+                                      builder.expression().getattr("ARENA2_ACCIDENTES","LID_ACCIDENTE")
+                              ),
+                              builder.expression().eq(
+                                      builder.expression().column("MODELO"),
+                                      builder.expression().constant("307")
+                              )
+                      )
+              )
+              .limit(1);
+        ExpressionBuilder.Value exists = builder.exists(select.toValue(), "EXISTS123");
+
+        String filter = exists.toString(new DALFormatter());
+        
+        assertEquals("EXISTS((SELECT \"LID_ACCIDENTE\" FROM \"ARENA2_VEHICULOS\" WHERE (( (\"ARENA2_VEHICULOS\".\"ID_ACCIDENTE\") = (\"ARENA2_ACCIDENTES\".\"LID_ACCIDENTE\") ) AND ( (\"MODELO\") = ('307') )) LIMIT 1), 'EXISTS123')", filter);
+        
+        // Comprobamos que con el formatter por defecto obtenemos lo mismo.
+        assertEquals(filter, exists.toString());
+
+        Compiler compiler = createCompiler();
+
+        Code code = compiler.compileExpression(filter);
+        link(code);
+        assertEquals("EXISTS(SELECT(TUPLE(\"LID_ACCIDENTE\"), \"ARENA2_VEHICULOS\", ((\"ARENA2_VEHICULOS\".\"ID_ACCIDENTE\" = \"ARENA2_ACCIDENTES\".\"LID_ACCIDENTE\") AND (\"MODELO\" = '307')), TUPLE(), TUPLE(), 1), 'EXISTS123')", code.toString());
+    }
+    
+}
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/test/java/org/gvsig/expressionevaluator/TestGrammarCompiler.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/test/java/org/gvsig/expressionevaluator/TestGrammarCompiler.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/test/java/org/gvsig/expressionevaluator/TestGrammarCompiler.java	(revision 44769)
@@ -1,6 +1,7 @@
 package org.gvsig.expressionevaluator;
 
 import junit.framework.TestCase;
+import org.gvsig.expressionevaluator.impl.expressionbuilder.formatters.DALFormatter;
 import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
 
 /**
@@ -67,7 +68,7 @@
 
         Code code = compiler.compileExpression(source.toString());
         link(code);
-        assertEquals("SELECT(NULL, \"countries\", NULL, TUPLE(), TUPLE(), NULL)", code.toString());
+        assertEquals("SELECT(TUPLE(), \"countries\", NULL, TUPLE(), TUPLE(), NULL)", code.toString());
     }
 
     public void testSelect1() {
@@ -78,7 +79,7 @@
 
         Code code = compiler.compileExpression(source.toString());
         link(code);
-        assertEquals("SELECT(NULL, \"countries\", NULL, TUPLE(), TUPLE(), NULL)", code.toString());
+        assertEquals("SELECT(TUPLE(), \"countries\", NULL, TUPLE(), TUPLE(), NULL)", code.toString());
     }
     
     public void testSelect2() {
@@ -97,7 +98,7 @@
 
         Code code = compiler.compileExpression(source.toString());
         link(code);
-        assertEquals("BLOCK(LET('X', 0), FOREACH('row', SELECT(NULL, \"countries\", NULL, TUPLE(), TUPLE(), NULL), IFF((\"row\".\"LASTCENSUS\" > 0), LET('X', (\"X\" + \"row\".\"LASTCENSUS\")))))", code.toString());
+        assertEquals("BLOCK(LET('X', 0), FOREACH('row', SELECT(TUPLE(), \"countries\", NULL, TUPLE(), TUPLE(), NULL), IFF((\"row\".\"LASTCENSUS\" > 0), LET('X', (\"X\" + \"row\".\"LASTCENSUS\")))))", code.toString());
     }
 
     public void testSelect3() {
@@ -116,7 +117,7 @@
 
         Code code = compiler.compileExpression(source.toString());
         link(code);
-        assertEquals("BLOCK(LET('X', 0), FOREACH('row', SELECT(NULL, \"countries\", NULL, TUPLE(), TUPLE(), NULL), IFF((\"row\".\"LASTCENSUS\" > 0), LET('X', (\"X\" + \"row\".\"LASTCENSUS\")))))", code.toString());
+        assertEquals("BLOCK(LET('X', 0), FOREACH('row', SELECT(TUPLE(), \"countries\", NULL, TUPLE(), TUPLE(), NULL), IFF((\"row\".\"LASTCENSUS\" > 0), LET('X', (\"X\" + \"row\".\"LASTCENSUS\")))))", code.toString());
     }
 
     public void testSelectWhere() {
@@ -128,7 +129,7 @@
 
         Code code = compiler.compileExpression(source.toString());
         link(code);
-        assertEquals("SELECT(NULL, \"countries\", (\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), NULL)", code.toString());
+        assertEquals("SELECT(TUPLE(), \"countries\", (\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), NULL)", code.toString());
     }
 
     public void testSelectCountWhere() {
@@ -152,7 +153,7 @@
 
         Code code = compiler.compileExpression(source.toString());
         link(code);
-        assertEquals("SELECT(NULL, \"countries\", (\"countries\".\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), NULL)", code.toString());
+        assertEquals("SELECT(TUPLE(), \"countries\", (\"countries\".\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), NULL)", code.toString());
     }
 
     public void testSelectOrder() {
@@ -164,7 +165,7 @@
 
         Code code = compiler.compileExpression(source.toString());
         link(code);
-        assertEquals("SELECT(NULL, \"countries\", NULL, TUPLE(\"CONTINENT\", \"LASTCENSUS\"), TUPLE(TRUE, FALSE), NULL)", code.toString());
+        assertEquals("SELECT(TUPLE(), \"countries\", NULL, TUPLE(\"CONTINENT\", \"LASTCENSUS\"), TUPLE(TRUE, FALSE), NULL)", code.toString());
     }
 
     public void testSelectWhereOrder() {
@@ -177,7 +178,7 @@
 
         Code code = compiler.compileExpression(source.toString());
         link(code);
-        assertEquals("SELECT(NULL, \"countries\", (\"LASTCENSUS\" > 0), TUPLE(\"ID\"), TUPLE(TRUE), NULL)", code.toString());
+        assertEquals("SELECT(TUPLE(), \"countries\", (\"LASTCENSUS\" > 0), TUPLE(\"ID\"), TUPLE(TRUE), NULL)", code.toString());
     }
 
     public void testSelectWhereOrderLimit() {
@@ -191,7 +192,7 @@
 
         Code code = compiler.compileExpression(source.toString());
         link(code);
-        assertEquals("SELECT(NULL, \"countries\", (\"LASTCENSUS\" > 0), TUPLE(\"LASTCENSUS\"), TUPLE(FALSE), 3)", code.toString());
+        assertEquals("SELECT(TUPLE(), \"countries\", (\"LASTCENSUS\" > 0), TUPLE(\"LASTCENSUS\"), TUPLE(FALSE), 3)", code.toString());
     }
 
     public void testSelectLimit() {
@@ -203,7 +204,7 @@
 
         Code code = compiler.compileExpression(source.toString());
         link(code);
-        assertEquals("SELECT(NULL, \"countries\", NULL, TUPLE(), TUPLE(), 3)", code.toString());
+        assertEquals("SELECT(TUPLE(), \"countries\", NULL, TUPLE(), TUPLE(), 3)", code.toString());
     }
 
     public void testExists() {
@@ -223,7 +224,7 @@
     public void testExistsSelect1() {
         StringBuilder source = new StringBuilder();
         source.append("EXISTS(");
-        source.append(" SELECT 1 FROM countries");
+        source.append(" SELECT \"ISO_A2\" FROM countries");
         source.append("   WHERE countries.LASTCENSUS > 0 ; ");
         source.append(")");
 
@@ -234,13 +235,13 @@
         String id = "????????????????????????????????";
         String s = code.toString();
         s = s.substring(0, s.length()-id.length()-2)+id+s.substring(s.length()-2);
-        assertEquals("EXISTS(SELECT(TUPLE(1), \"countries\", (\"countries\".\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), NULL), 'EXISTS????????????????????????????????')", s);
+        assertEquals("EXISTS(SELECT(TUPLE(\"ISO_A2\"), \"countries\", (\"countries\".\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), NULL), 'EXISTS????????????????????????????????')", s);
     }
 
     public void testExistsSelect2() {
         StringBuilder source = new StringBuilder();
         source.append("EXISTS(");
-        source.append(" SELECT 1 FROM countries");
+        source.append(" SELECT \"ISO_A2\" FROM countries");
         source.append("   WHERE countries.LASTCENSUS > 0 ");
         source.append(")");
 
@@ -251,13 +252,13 @@
         String id = "????????????????????????????????";
         String s = code.toString();
         s = s.substring(0, s.length()-id.length()-2)+id+s.substring(s.length()-2);
-        assertEquals("EXISTS(SELECT(TUPLE(1), \"countries\", (\"countries\".\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), NULL), 'EXISTS????????????????????????????????')", s);
+        assertEquals("EXISTS(SELECT(TUPLE(\"ISO_A2\"), \"countries\", (\"countries\".\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), NULL), 'EXISTS????????????????????????????????')", s);
     }
 
     public void testExistsSelectLimit1() {
         StringBuilder source = new StringBuilder();
         source.append("EXISTS(");
-        source.append(" SELECT 1 FROM countries  ");
+        source.append(" SELECT \"ISO_A2\" FROM countries  ");
         source.append("   WHERE countries.LASTCENSUS > 0  ");
         source.append("   LIMIT 1; ");
         source.append(")");
@@ -269,7 +270,7 @@
         String id = "????????????????????????????????";
         String s = code.toString();
         s = s.substring(0, s.length()-id.length()-2)+id+s.substring(s.length()-2);
-        assertEquals("EXISTS(SELECT(TUPLE(1), \"countries\", (\"countries\".\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), 1), 'EXISTS????????????????????????????????')", s);
+        assertEquals("EXISTS(SELECT(TUPLE(\"ISO_A2\"), \"countries\", (\"countries\".\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), 1), 'EXISTS????????????????????????????????')", s);
     }
 
     public void testExistsSelectLimit2() {
@@ -278,7 +279,7 @@
         // Filtramos continentes por un campo del pais.
         StringBuilder source = new StringBuilder();
         source.append("EXISTS(");
-        source.append(" SELECT 1 FROM countries");
+        source.append(" SELECT \"ISO_A2\" FROM countries");
         source.append("   WHERE ");
         source.append("     continents.NAME = countries.CONTINENT AND ");
         source.append("     countries.LASTCENSUS < 0 ");
@@ -292,7 +293,7 @@
         String id = "????????????????????????????????";
         String s = code.toString();
         s = s.substring(0, s.length()-id.length()-2)+id+s.substring(s.length()-2);
-        assertEquals("EXISTS(SELECT(TUPLE(1), \"countries\", ((\"continents\".\"NAME\" = \"countries\".\"CONTINENT\") AND (\"countries\".\"LASTCENSUS\" < 0)), TUPLE(), TUPLE(), 1), 'EXISTS????????????????????????????????')", s);
+        assertEquals("EXISTS(SELECT(TUPLE(\"ISO_A2\"), \"countries\", ((\"continents\".\"NAME\" = \"countries\".\"CONTINENT\") AND (\"countries\".\"LASTCENSUS\" < 0)), TUPLE(), TUPLE(), 1), 'EXISTS????????????????????????????????')", s);
     }
 
     public void testExistsSelectLimit3() {
@@ -301,7 +302,7 @@
         // Filtramos continentes por un campo del pais.
         StringBuilder source = new StringBuilder();
         source.append("EXISTS(");
-        source.append(" SELECT 1 FROM countries");
+        source.append(" SELECT \"ISO_A2\" FROM countries");
         source.append("   WHERE ");
         source.append("     continents.NAME = countries.CONTINENT AND ");
         source.append("     countries.LASTCENSUS < 0 ");
@@ -314,14 +315,14 @@
 
         Code code = compiler.compileExpression(source.toString());
         link(code);
-        assertEquals("EXISTS(SELECT(TUPLE(1), \"countries\", ((\"continents\".\"NAME\" = \"countries\".\"CONTINENT\") AND (\"countries\".\"LASTCENSUS\" < 0)), TUPLE(), TUPLE(), 1), 'patata')", code.toString());
+        assertEquals("EXISTS(SELECT(TUPLE(\"ISO_A2\"), \"countries\", ((\"continents\".\"NAME\" = \"countries\".\"CONTINENT\") AND (\"countries\".\"LASTCENSUS\" < 0)), TUPLE(), TUPLE(), 1), 'patata')", code.toString());
     }
 
     public void testExistsSelectLimit4() {
         StringBuilder source = new StringBuilder();
         source.append("EXISTS(");
         source.append(" SELECT(");
-        source.append("   TUPLE(1), ");
+        source.append("   TUPLE(\"ISO_A2\"), ");
         source.append("   countries, ");
         source.append("   (countries.LASTCENSUS > 0), ");
         source.append("   TUPLE(), ");
@@ -339,7 +340,7 @@
         String id = "????????????????????????????????";
         String s = code.toString();
         s = s.substring(0, s.length()-id.length()-2)+id+s.substring(s.length()-2);
-        assertEquals("EXISTS(SELECT(TUPLE(1), \"countries\", (\"countries\".\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), 1), 'EXISTS????????????????????????????????')", s);
+        assertEquals("EXISTS(SELECT(TUPLE(\"ISO_A2\"), \"countries\", (\"countries\".\"LASTCENSUS\" > 0), TUPLE(), TUPLE(), 1), 'EXISTS????????????????????????????????')", s);
     }
 
 }
Index: 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/Exists.java
===================================================================
--- 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/Exists.java	(revision 0)
+++ 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/Exists.java	(revision 44769)
@@ -0,0 +1,36 @@
+package org.gvsig.expressionevaluator.impl.expressionbuilder.formatters;
+
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import static org.gvsig.fmap.dal.DataManager.FUNCTION_EXISTS;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class Exists implements Formatter<Value> {
+    
+    private final Formatter<Value> formatter;
+    
+    public Exists(Formatter<Value> formatter) {
+        this.formatter = formatter;
+    }
+    @Override
+    public boolean canApply(ExpressionBuilder.Value value) {
+        if (value instanceof ExpressionBuilder.Function) {
+            return StringUtils.equalsIgnoreCase(FUNCTION_EXISTS, ((Function) value).name());
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value function0) {
+        Function function = (Function) function0;
+        Value exp = function.parameters().get(0);
+        return "EXISTS("+exp.toString(formatter)+")";
+    }
+    
+}
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/test/java/org/gvsig/fmap/dal/store/h2/operations/sql/TestResultSetForSetProvider.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/test/java/org/gvsig/fmap/dal/store/h2/operations/sql/TestResultSetForSetProvider.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/test/java/org/gvsig/fmap/dal/store/h2/operations/sql/TestResultSetForSetProvider.java	(revision 44769)
@@ -122,7 +122,7 @@
     );
     StringBuilder filter = new StringBuilder();
     filter.append("EXISTS(");
-    filter.append(" SELECT 1 FROM countries");
+    filter.append(" SELECT \"ISO_A2\" FROM countries");
     filter.append("   WHERE ");
     filter.append("     TEST.STRING = countries.CONTINENT AND ");
     filter.append("     countries.LASTCENSUS < 0 ");
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/test/resources/org/gvsig/fmap/dal/store/h2/resultSetForSetProvider.sql
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/test/resources/org/gvsig/fmap/dal/store/h2/resultSetForSetProvider.sql	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/test/resources/org/gvsig/fmap/dal/store/h2/resultSetForSetProvider.sql	(revision 44769)
@@ -24,14 +24,14 @@
     "String", "Bool3", "Double", "Bool4", "Float", "Bool5", "Decimal", 
     NVL2("Geometry",ST_AsBinary("Geometry"),NULL), 
     NVL2(COALESCE((
-      SELECT 1 
+      SELECT "ISO_A2" 
       FROM "countries" 
       WHERE (("TEST"."STRING" = "countries"."CONTINENT") AND 
         ("countries"."LASTCENSUS" < 0)) LIMIT 1)),TRUE,FALSE) 
     AS "EXISTS62a964cd7bc24f409b97c03b9170408d" 
   FROM "PUBLIC"."test" 
   WHERE NVL2(COALESCE((
-    SELECT 1 
+    SELECT "ISO_A2" 
     FROM "countries" 
     WHERE (("TEST"."STRING" = "countries"."CONTINENT") AND 
       ("countries"."LASTCENSUS" < 0)) LIMIT 1)),TRUE,FALSE);
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/expressionbuilderformatter/H2SpatialFormatter.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/expressionbuilderformatter/H2SpatialFormatter.java	(revision 44768)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/expressionbuilderformatter/H2SpatialFormatter.java	(revision 44769)
@@ -3,10 +3,8 @@
 import org.gvsig.expressionevaluator.ExpressionBuilder;
 import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
 import org.gvsig.expressionevaluator.Formatter;
-import org.gvsig.expressionevaluator.spi.formatter.value.BaseFormatter;
+import org.gvsig.fmap.dal.DALLocator;
 import org.gvsig.fmap.dal.SQLBuilder;
-import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilderformatter.JDBCFormatter;
-import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilderformatter.Select;
 
 /**
  *
@@ -33,8 +31,7 @@
             new Constant(this.builder, this),
             new ST_AsBinary(this.builder, this),
             new Exists(this.builder, this),
-            new BaseFormatter(this),
-            new JDBCFormatter(this),
+            DALLocator.getDataManager().createDALExpressionBuilder().formatter(this),
         };
     }
 
