Here is a fairly clean solution to the issue of checking whether an attempt to insert or update a record complies with databse uniqueness requirements, and therefore would fail if the insert was attempted. This is an alternative to attempting the insert or update and then checking to see if it failed or not, so these tests are added to the list of other field or row validation tests: Using 'EXISTS' to check for whether any other records match the selected field. For completeness, the SQL commands are like this:
SELECT EXISTS (SELECT 1 FROM context WHERE context_short = '
the 'SELECT 1' subquery only needs to select one row to demonstrate that a record already exists with the same field value, although there shouldn't really be any more than one record already existing anyway in this particular instance because we're testing for uniqueness. I hope this helps anyone else who has faced the same issue as me.
Just to point out, in this instance I'm only using visible labels as variables so I can see what the output is during development. A normal non-visible variable should work just as well.
