This happens when the schema defines an attribute without the length of the
field :

AttributeType cgi = AttributeTypeFactory.newAttributeType("propertyName",
String.class);

This goes away when we set the length to less than 10485760 using

AttributeType cgi = AttributeTypeFactory.newAttributeType("propertyName",
String.class, true, 30);

I tried the generated sql statement and the same error is thrown. Here is
the error :

ERROR: length for type varchar cannot exceed 10485760 SQL state: 22023

It seems like when generating the sql, the max value for VARCHAR comes up to
be MAX_INT. However, postgresql requires it to be less than or equal to
10485760. From what I understand from the code in PostgisDataStore.java, the
createSchema method should do a check for this case:

if (length < 1) {
      LOGGER.warning("FeatureType did not specify string length; defaulted
to 256");
      length = 256;
}
else if (length > MAX_ALLOWED_VALUE) // this is the check that I think
should be added and MAX_ALLOWED_VALUE should be set to 10485760 {
      length = MAX_ALLOWED_VALUE;
}

The complete method follows :

private StringBuffer makeSqlCreate(AttributeType[] attributeType)
        throws IOException {
        StringBuffer buf = new StringBuffer("");

        for (int i = 0; i < attributeType.length; i++) {
            String typeName = null;
            typeName = (String)
CLASS_MAPPINGS.get(attributeType[i].getType());
            if (typeName == null)
                typeName = (String)
GEOM_CLASS_MAPPINGS.get(attributeType[i].getType());
                
            if (typeName != null) {
                if (attributeType[i] instanceof GeometryAttributeType) {
                    typeName = "GEOMETRY";
                } else if (typeName.equals("VARCHAR")) {
                        int length = -1;
                        Filter f = attributeType[i].getRestriction();
                        if(f !=null && f!=Filter.ALL && f != Filter.NONE &&
(f.getFilterType() == FilterType.COMPARE_LESS_THAN || f.getFilterType() ==
FilterType.COMPARE_LESS_THAN_EQUAL)){
                                try{
                                CompareFilter cf = (CompareFilter)f;
                                if(cf.getLeftValue() instanceof LengthFunction){
                                        length =
Integer.parseInt(((LiteralExpression)cf.getRightValue()).getLiteral().toString());
                                }else{
                                        if(cf.getRightValue() instanceof 
LengthFunction){
                                        length =
Integer.parseInt(((LiteralExpression)cf.getLeftValue()).getLiteral().toString());
                                }
                                }
                                }catch(NumberFormatException e){
                                        length = 256;
                                }
                        }else{
                                length = 256;
                        }
                        
                        if (length < 1) {
                                LOGGER.warning("FeatureType did not specify 
string length;
defaulted to 256");
                                length = 256;
                        }
                  else if (length > MAX_ALLOWED_VALUE)
                  {
                        length = MAX_ALLOWED_VALUE;
                  }
                                
                    typeName = typeName + "(" + length + ")";
                }

                if (!attributeType[i].isNillable()) {
                    typeName = typeName + " NOT NULL";
                }

                //TODO review!!! Is toString() always OK???
                Object defaultValue = attributeType[i].createDefaultValue();

                if (defaultValue != null) {
                    typeName = typeName + " DEFAULT '"
                        + defaultValue.toString() + "'";
                }

                buf.append(" \"" + attributeType[i].getName() + "\" " +
typeName + ",");

            } else {
                String msg;
                if (attributeType[i] == null) {
                        msg = "AttributeType was null!";
                } else {
                        msg = "Type '" + attributeType[i].getType() + "' not
supported!";
                }
                throw (new IOException(msg));
            }
        }

        return buf.deleteCharAt(buf.length()-1);
    }

Regards,
Enamul Haque
R & D, Redknee Inc.


Jody Garnett wrote:
> 
> Enam wrote:
>> Not sure if this has been posted before. I'm getting an exception when
>> calling createSchema() :
>>
>> It seems like any attribute of type string uses VARCHAR(2147483647). Am I
>> doing something wrong here ?
>>   
> Sounds like we are doing something wrong? Can you do some research and 
> let us know what we are supposed to be using to represent String? When I 
> first saw your message I wondered if the createSchema statement was 
> resulting in an SQL request that was too long.
> 
> You can always try doing the same SQL as create schema generates by hand 
> while you experiment...
> Cheers,
> Jody
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Postgis-DataStore-tf3944630.html#a11203351
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to