Using the code from r1137, if I do
Table tbl = new TableBuilder("table1")
.addColumn(new ColumnBuilder("id", DataType.LONG))
.addColumn(new ColumnBuilder("txt_required", DataType.TEXT)
.setLengthInUnits(50))
.addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME)
.addColumns("id").setPrimaryKey())
.toTable(db);
System.out.println("Table created.");
Column col = tbl.getColumn("txt_required");
PropertyMap pm = col.getProperties();
pm.put(PropertyMap.REQUIRED_PROP, true);
pm.save();
System.out.println("Column altered.");
then the Access Database Engine correctly recognizes the txt_required column as "Required" and will not let me insert a NULL, verified with the VBScript in this discussion post.
However, if I use
pm.put(PropertyMap.REQUIRED_PROP, DataType.BOOLEAN, true);
instead of
pm.put(PropertyMap.REQUIRED_PROP, true);
then the Access Database Engine fails to respect the "Required" property as before.
i didn't think anyone would be specifying the data type for the known properties. is there a reason you are doing that? the current logic only looks for the "extra" information if you don't specify any type information (it presumes you know what you are doing).
also, what would you expect to happen if you specified ("Required", DataType.TEXT, true)? should the datatype be ignored if it is wrong?
Last edit: James Ahlborn 2018-02-05
That's just what the current UCanAccess code does. My UCanAccess test for the Jackcess r1137 fix was failing, and this was the reason why. I can change the UCanAccess code if necessary.
I'd say that if "Required" is a system-reserved property of type
Booleanthen an attempt to set it as aStringwould need to be cast toBoolean, i.e., the system requirement would trump the user-specified type. The less forgiving approach would be to simply throw an IllegalArgumentException, and I'd be okay with that too, in the spirit of "we should know what we're doing".FYI, I just changed the relevant line in UCanAccess from
to
and all of the UCanAccess tests pass (including my new one), so we can go with that if need be.
Last edit: Gord Thompson 2018-02-05
fixed in trunk, will be in the 2.1.11 release.
Thanks. Please remember to update the GitHub mirror.
Thanks again for the fix. All of our tests pass and we're looking forward to Jackcess 2.1.11 so we can release UCanAccess 4.0.4.