Changeset 7721


Ignore:
Timestamp:
Jun 4, 2019, 10:21:01 AM (2 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #2181: Empty cells when parsing Excel files are always returned as the empty string

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.15-stable/src/core/net/sf/basedb/util/parser/FlatFileParser.java

    r7706 r7721  
    19811981    public String getString(int index)
    19821982    {
    1983       String value = result[index];
    1984       return emptyIsNull && value.length() == 0 ||
    1985         nullIsNull && "NULL".equalsIgnoreCase(value) ? null : value;
    1986     }
     1983      return fixString(result[index]);
     1984    }
     1985   
     1986    /**
     1987      Fix the value string according to options
     1988      for 'emptyIsNull', 'nullIsNull', etc.
     1989      @since 3.15.1
     1990    */
     1991    protected String fixString(String value)
     1992    {
     1993      return value == null ||
     1994        emptyIsNull && value.length() == 0 ||
     1995        nullIsNull && "NULL".equalsIgnoreCase(value)
     1996        ? null : value;
     1997    }
     1998   
    19871999   
    19882000    /**
     
    20022014    public Integer getInt(int index, NumberFormat parser, boolean nullIfException)
    20032015    {
    2004       return (Integer)Type.INT.parseString(get(index), parser, nullIfException);
     2016      return (Integer)Type.INT.parseString(getString(index), parser, nullIfException);
    20052017    }
    20062018
     
    20132025    public Long getLong(int index, NumberFormat parser, boolean nullIfException)
    20142026    {
    2015       return (Long)Type.LONG.parseString(get(index), parser, nullIfException);
     2027      return (Long)Type.LONG.parseString(getString(index), parser, nullIfException);
    20162028    }
    20172029   
     
    20322044    public Float getFloat(int index, NumberFormat parser, boolean nullIfException)
    20332045    {
    2034       return (Float)Type.FLOAT.parseString(get(index), parser, nullIfException);
     2046      return (Float)Type.FLOAT.parseString(getString(index), parser, nullIfException);
    20352047    }
    20362048
     
    20432055    public Double getDouble(int index, NumberFormat parser, boolean nullIfException)
    20442056    {
    2045       return (Double)Type.DOUBLE.parseString(get(index), parser, nullIfException);
     2057      return (Double)Type.DOUBLE.parseString(getString(index), parser, nullIfException);
    20462058    }
    20472059
     
    20542066    public Date getDate(int index, Formatter<Date> parser, boolean nullIfException)
    20552067    {
    2056       return (Date)Type.DATE.parseString(get(index), parser, nullIfException);
     2068      return (Date)Type.DATE.parseString(getString(index), parser, nullIfException);
    20572069    }
    20582070  }
     
    20862098    {
    20872099      Cell c = sheet.getCell(lineNo()+rowOffset, index+colOffset);
    2088       return sheet.getCellValueAsString(c);
     2100      return fixString(sheet.getCellValueAsString(c));
    20892101    }
    20902102   
Note: See TracChangeset for help on using the changeset viewer.