[Gvsig_desarrolladores] Info on shp/dbf driver

Francisco José Peñarrubia fpenarru en gmail.com
Lun Abr 6 19:54:54 CEST 2009


Hi, Stefano.

As far as I know, the Dbf driver 
(com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver.java) reads the field 
type from the dBase Header (using DbaseFileHeader class). It seems that 
we are only taking care of some field types:

    public int getFieldType(int i) throws ReadDriverException {
        char fieldType = fieldTypes[i];

        if (fieldType == 'L') {
            return Types.BOOLEAN;
        } else if ((fieldType == 'F') || (fieldType == 'N')) {
            if (dbf.getFieldDecimalLength(i)>0)
                return Types.DOUBLE;
            else
                return Types.INTEGER;
        } else if (fieldType == 'C') {
            return Types.VARCHAR;
        } else if (fieldType == 'D') {
            return Types.DATE;
        } else {
            throw new 
BadFieldDriverException(getName(),null,String.valueOf(fieldType));
        }
    }

 From here:

http://www.clicketyclick.dk/databases/xbase/format/data_types.html

It seems we should take care of '@' character, at least. Do you have any 
example of dbf file with this kind of data?.

Or maybe you mean the DbfWriter. Then, you can have a look to this 
function in DbaseFileWriterNIO:

 private String fieldString(Object obj,final int col) {
    String o;
    final int fieldLen = header.getFieldLength(col);
    switch (header.getFieldType(col)) {
      case 'C':
      case 'c':
        o = formatter.getFieldString(
          fieldLen,
          (obj instanceof NullValue)? NULL_STRING : ((StringValue) 
obj).getValue()
        );
        break;
      case 'L':
      case 'l':
        o = (obj instanceof NullValue) ? "F" : 
((BooleanValue)obj).getValue() == true ? "T" : "F";
        break;
      case 'M':
      case 'G':
        o = formatter.getFieldString(
          fieldLen,
          (obj instanceof NullValue) ? NULL_STRING : ((StringValue) 
obj).getValue()
        );
        break;
     /* case 'N':
      case 'n':
        // int?
        if (header.getFieldDecimalCount(col) == 0) {
           
          o = formatter.getFieldString(
            fieldLen, 0, (Number) (obj == null ? NULL_NUMBER : 
Double.valueOf(obj.toString()))
          );
          break;
      
         }
      */
      case 'N':
      case 'n':
      case 'F':
      case 'f':
        Number number = null;
        if(obj instanceof NullValue){
            number = NULL_NUMBER;
        }else{
            NumericValue gVal = (NumericValue) obj;
            number = new Double(gVal.doubleValue());
        }
        o = formatter.getFieldString(fieldLen,
                header.getFieldDecimalCount(col),
                    number);
        break;
      case 'D':
      case 'd':
          if (obj instanceof NullValue)
              o = NULL_DATE;
          else
              o = formatter.getFieldString(((DateValue)obj).getValue());
        break;
      default:
        throw new RuntimeException("Unknown type " + 
header.getFieldType(col));
    }

    return o;
  }

It seems there is not support to TIMESTAMP  type.

Hope this helps... If you find the problema and wants to contribute, 
please, let us know.

Thanks for your help.

Fran Peñarrubia
gvSIG Team


Stefano Orlando escribió:
> Playing a bit with data conversion in gvSIG 1.9 alpha, I've noticed 
> that the .shp driver (the .dbf part really) doesn't support the SQL 
> 'TIMESTAMP' type and that the driver determines the type of a column 
> reading the value from the first row of the table (so, if the value is 
> a null value, there are some troubles because there isn't a 'null' 
> data type in .dbf specs). Could you confirm these behaviours or I've 
> missed something? And if this is true, there will be any changes in 
> future versions of gvSIG?
> Thank you for your assistance!
>
> Stefano
> ------------------------------------------------------------------------
>
> _______________________________________________
> gvSIG_desarrolladores mailing list
> gvSIG_desarrolladores en runas.cap.gva.es
> http://runas.cap.gva.es/mailman/listinfo/gvsig_desarrolladores
>   



Más información sobre la lista de distribución gvSIG_desarrolladores