Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions api/src/org/labkey/api/data/ConvertHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.labkey.api.collections.ConcurrentHashSet;
import org.labkey.api.exp.PropertyType;
import org.labkey.api.gwt.client.DefaultScaleType;
import org.labkey.api.gwt.client.FacetingBehaviorType;
import org.labkey.api.query.FieldKey;
Expand Down Expand Up @@ -1210,6 +1211,61 @@ public void testInvalidInfDoubleConverter()
}
}
}

@Test
public void testEmpty()
{
assertNull(JdbcType.CHAR.convert(""));
assertNull(JdbcType.VARCHAR.convert(""));
assertNull(JdbcType.LONGVARCHAR.convert(""));

// PropertyType is used for domain defined tables.
// I would expect these to return null.
assertEquals("", PropertyType.STRING.convert(""));
assertEquals("", PropertyType.MULTI_LINE.convert(""));
assertEquals("", PropertyType.XML_TEXT.convert(""));

// Since we often convert "through" string, I'm not sure this low-level
// method should modify "". This could potentially mess up
// converting array->string->array for instance.
// [] -> "" -> null
// vs
// [] -> "" -> []
assertNull(ConvertHelper.convert("", String.class));
assertNull(ConvertUtils.convert(""));
assertNull(ConvertUtils.convert("", String.class));
}

@Test
public void testBlank()
{
// blank strings do not get the empty string special handling.
assertEquals(" ", JdbcType.CHAR.convert(" "));
assertEquals(" ", JdbcType.VARCHAR.convert(" "));
assertEquals(" ", JdbcType.LONGVARCHAR.convert(" "));
assertEquals(" ", PropertyType.STRING.convert(" "));
assertEquals(" ", PropertyType.MULTI_LINE.convert(" "));
assertEquals(" ", PropertyType.XML_TEXT.convert(" "));
assertEquals(" ", ConvertHelper.convert(" ", String.class));
assertEquals(" ", ConvertUtils.convert(" "));
assertEquals(" ", ConvertUtils.convert(" ", String.class));
}

@Test
public void testTrim()
{
// convert() does not trim. That is handled in DataIterator.
// e.g. see SimpleTranslator.createConvertColumn()
assertEquals(" x ", JdbcType.CHAR.convert(" x "));
assertEquals(" x ", JdbcType.VARCHAR.convert(" x "));
assertEquals(" x ", JdbcType.LONGVARCHAR.convert(" x "));
assertEquals(" x ", PropertyType.STRING.convert(" x "));
assertEquals(" x ", PropertyType.MULTI_LINE.convert(" x "));
assertEquals(" x ", PropertyType.XML_TEXT.convert(" x "));
assertEquals(" x ", ConvertHelper.convert(" x ", String.class));
assertEquals(" x ", ConvertUtils.convert(" x "));
assertEquals(" x ", ConvertUtils.convert(" x ", String.class));
}
}

// Note: Keep in sync with LabKeySiteWrapper.getConversionErrorMessage()
Expand Down
6 changes: 6 additions & 0 deletions api/src/org/labkey/api/data/JdbcType.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ protected void addSqlTypes(Collection<Integer> sqlTypes)
{
sqlTypes.add(Types.NCHAR);
}

@Override
public Object convert(Object o) throws ConversionException
{
return VARCHAR.convert(o);
}
},

DECIMAL(Types.DECIMAL, BigDecimal.class, null, "numberfield")
Expand Down