Dictionary Tips & Hints
This page contains tips, hints and common gotchas with Dictionary Items.
If you have any you think should be added, please send them to ‘u2tech’ at ‘y7mail.com’.
What are the dictionary item types
There are 4 types of dictionary items in UniData and UniVerse. They are:
- D-Type: This is a data descriptor
- I or V-Type: Interpretive descriptor/Virtual field
- PH: Phrases
- X-Type: User Defined
D-Type dictionary items point to a single attribute in a record. It is important that you structure your records so that each different type of data can be referenced by a D-Type dictionary item
I or V-Type dictionary items are for calculating or otherwise deriving information from a record. For example, if your record stores the date of birth or a person, you could create an I-Type dictionary item that can grab this information, compare it to the current date and calculate their actual age.
Another common example of I-Type usage is to use a key stored in the record to grab information from another file’s record using the ‘TRANS’ function.
PH-Type dictionary items, or ‘Phases’ contain parts of UniQuery statements, not including the verb (e.g. SELECT, LIST or SORT).
X-Type dictionary items are user defined. After the X in the first attribute, you are free to put whatever you want. This is the ideal place to store any meta-data you may need for the file. One example would be the next available @ID.
How are the PH dictionary items used?
The most common usage is in associations. Sometimes you have a multivalued list of items in one attribute (let’s say first names) that directly correlate to another multivalued list of items in another attribute (let’s say last names). In attribute 7 of your D-Type dictionary record you can specific an ‘association’. In this field you put the @ID of a PH-Type record that lists all the dictionary items that are related. This association comes in handy with the ‘WHEN ASSOCIATED’ clause in a UniQuery statement.
Apart from associations, the PH type dictionary item can be used to change the default query performed with LIST or SORT. You can do this by creating PH-Type dictionaries called @ (UniVerse), @REVISE (UniVerse), @UQ (UniData) and @LPTR (UniData/UniVerse). Normally a ‘LIST FILE’ will just list the @IDs from FILE, but if you put something like ‘LAST.NAME FIRST.NAME BY LAST.NAME’ in the @/@UQ dictionary, it ‘LIST FILE’ will actually do ‘LIST FILE LAST.NAME FIRST.NAME BY LAST.NAME’. @REVISE has exactly the same effect on the REVISE verb in UniVerse and @LPTR has the same effect in UniVerse/UniData when the LIST/SORT output is sent to the printer.
PH type dictionary items can also be used as a shorthand method of using common segments of statements. For example if the often to ‘LIST FILE LAST.NAME FIRST.NAME BY LAST.NAME BY FIRST.NAME’ you could store everything by ‘LIST FILE’ in a PH record SHORT and just run ‘LIST FILE SHORT’. This works in both UniVerse and UniData, but not ECLTYPE P mode in UniData.
Indexing I or V-Type dictionaries
One ‘gotcha’ is when you attempt to create an index, based of a dictionary that references another file or calls a subroutine.
Since the results of these dictionaries may change, without the main file changing, the index will not be updated and result in your queries being incorrect. To correct this, you will need to rebuild your index regularly.
Advice: Don’t index on these type of dictionary items.
UniQuery and the single quote
UniQuery simply cannot handle quote marks in a search string. It takes one look at them and jumps overboard screaming. In most situations this wouldn’t be an issue, but in the times where it is it can be downright annoying.
So, how do you get around this limitation?
One easy method is to create a new I-type dictionary item that removes the single quote from the data. You then have to make sure you strip it out of your search strings (as part of your normal sanitisation routine) then you can successfully search for data that may contain single quotes. Of course, you may need to do some post validation if you require it to exactly match.
Time for an example: In the demo account created by UniData is a file called STUDENT. Add a new student with the last name of “O’Brien”. Try to find this student… LIST STUDENT WITH LNAME = “O’Brien” returns nothing!
So, now to the dictionary item. LNAME is the D-Type dictionary item for the last name and below is the I-Type dictionary item that strips single quotes from it:
Using this new dictionary item instead of LNAME, we can now do a successful search for “OBrien”.