albfernandez / javadbf

Java library for reading and writing Xbase (dBase/DBF) files.
GNU Lesser General Public License v3.0
220 stars 98 forks source link

Identify auto incremental field #114

Closed edgarjoao closed 1 year ago

edgarjoao commented 1 year ago

Hi there, Is there a way to identify if a column is auto incremental?

albfernandez commented 1 year ago

Hi

Yes, you can use getType method in DBFField

sample


DBFReader reader = null;
try {
    // create a DBFReader object
    reader = new DBFReader(new FileInputStream(args[0]));

    int numberOfFields = reader.getFieldCount();

    for (int i = 0; i < numberOfFields; i++) {
        DBFField field = reader.getField(i);
        if (field.getType() == DBFDataType.AUTOINCREMENT) {
             System.out.println(field.getName() + " IS AUTOINCREMENT FIELD");
        }               
    }

} catch (DBFException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
finally {
    DBFUtils.close(reader);
}
edgarjoao commented 1 year ago

Nice, thank you @albfernandez