Menu

#146 PropertyMap#put(String, DataType, Object) does not set DDL flag

2.1.11
closed
nobody
None
1
2018-02-28
2018-02-05
No

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.

Discussion

  • James Ahlborn

    James Ahlborn - 2018-02-05

    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
  • Gord Thompson

    Gord Thompson - 2018-02-05

    i didn't think anyone would be specifying the data type for the known properties. is there a reason you are doing that?

     
    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.

    what would you expect to happen if you specified ("Required", DataType.TEXT, true)? should the datatype be ignored if it is wrong?

     
    I'd say that if "Required" is a system-reserved property of type Boolean then an attempt to set it as a String would need to be cast to Boolean, 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".

     
  • Gord Thompson

    Gord Thompson - 2018-02-05

    FYI, I just changed the relevant line in UCanAccess from

    map.put(PropertyMap.REQUIRED_PROP, DataType.BOOLEAN, required[j]);
    

     
    to

    map.put(PropertyMap.REQUIRED_PROP, required[j]);
    

     
    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
  • James Ahlborn

    James Ahlborn - 2018-02-07
    • status: open --> closed
    • Group: Unassigned --> 2.1.11
     
  • James Ahlborn

    James Ahlborn - 2018-02-07

    fixed in trunk, will be in the 2.1.11 release.

     
    • Gord Thompson

      Gord Thompson - 2018-02-07

      Thanks. Please remember to update the GitHub mirror.

       
  • Gord Thompson

    Gord Thompson - 2018-02-28

    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.

     

Log in to post a comment.

MongoDB Logo MongoDB