ARGen Question

I know it is open source now but hopefully @Tim_Parnell, @Bob_Keeney2 or someone else that has used it can answer an occasional question.

In class setup for table for each field (except the Primary Key) there is a checkbox for Unique and only one can be set for table, but I am not sure what is for…

In the DB Schema one can make any number of fields on a table unique by creating a unique index for it, but as only one is allowed here and I don’t think the setting comes from the DB Schema… And the fields defined as unique (at least for SQLite) can be found by querying the the database… and those should not be able to be “unset” if this is about field value uniqueness within a table.

Also compound indices can be defined to be unique meaning that combination of field values must be unique in the table…

So over all I am not sure what this setting means or how it is used.

Can anyone provide a brief explanation?

Thanks,
-Karen

It adds a function to the class that lets you check if a passed value is unique for the field. I don’t recall if it adds anything to the Validate event.

Thank Tim,

What confused me is that only one is allowed per table when many can be defined in the DB…

So this is for trying to ensure uniqueness if it’s NOT being enforced by the DB itself for that field … same idea as for the manual foreign key setting in AR.

-Karen

In general AR does not rely on the database to enforce anything. Not sure if it’s still true or not but triggers and foreign key constraints didn’t always create an error that was catchable in Xojo so you sort of have to do that work up front to catch it.

Years ago SQLite did not have the ability to enforce foreign key constraints even though you could define them… But that changed some time ago but for years now, it would if you set the pragma to do so with each connection (which I do) and in that case Xojo does detect the error…

#######
Edit to add: Just checked:
Xojo Error Message just says ForeignKey Constraint failed… Not which field

I’m pretty sure I’ve seen Xojo being able to catch the SQLIte errors due to uniqueness violations with API 1 checking the DB.Error properties… though I don’t recall if the field name is included in the message (I think it is).

The issue for generality though would be getting the FieldName of the offending column from the message if the message has different wording with different DBs (likely!)

Do you recall if there was an issue with the other Databases beside Sqlite/REALSQL of Xojo not being able to detect/catch DB Constraint violation errors?

In any case if Xojo (or plugin vendors) can’t detect/catch constraints violations with ANY of their DB plugins, it would be a really big bug in the plugin IMO!

-Karen

1 Like

I do not recall. Sorry.