#9 CSV Import Silently fails

open
None
5
2005-03-18
2003-12-29
Curly
No

The CSV import silently fails when the format of records
is not strictly correct. For instance, I have a CSV
export of a database that contains Integer, Float and
Date fields. Where these are not set, the database
export saves them as empty strings (""). When
importing these records they are ignored.

I changed the setObjectAt method in
pilotdb.tools.simplecreator.csv.plugin to:

/**
* Method setObjectAt.
* @param string
* @param newRecord
* @param i
*/
private void setObjectAt(String string, PilotDBRecord
newRecord, int i) throws Exception {
// NEW LINE to check for empty String
if ( string != null && !string.equals("") ) {
int type = db.getSchema().getField(i).getType();
switch (type) {
case PilotDBField.TYPE_STRING:
newRecord.setString(i, string);
break;
case PilotDBField.TYPE_BOOL:
newRecord.setBoolean(i, string);
break;
case PilotDBField.TYPE_INTEGER:
newRecord.setInteger(i, string);
break;
case PilotDBField.TYPE_FLOAT:
newRecord.setFloat(i,string);
break;
case PilotDBField.TYPE_DATE:
Date d = model.getJavaDateFormat().parse(string);
newRecord.setDate(i, new PilotDBDate(d));
break;
case PilotDBField.TYPE_TIME:
d = model.getJavaTimeFormat().parse(string);
newRecord.setTime(i, new PilotDBTime(d));
break;
default:
addError("Invalid Type {0}", new Object[]{new
Integer(type)});
}
}
}

Discussion

    • assigned_to: nobody --> trevershick