|Powered by QM on a Linux server|
KnowledgeBase 00040: Dictionary Link Records
Developers moving to multivalue systems from relational databases are often surprised by the frequent need to include large numbers of TRANS() operations or T-conversions in dictionaries to retrieve data from a secondary file. QM's L-type link records allow developers to simplify such dictionaries.
The L-type Record
The L-type dictionary record has the form
1: L 2: Id expression 3: File namewhere Id expression is a QMBasic expression that constructs the id of the record to be accessed in the secondary file and File name is the name of that file.
As an example, the QM demonstration database includes a SALES file in which the ITEM field contains a multivalued list of items in an order. These item codes are the record ids to the STOCK file.
Using TRANS() in an I-type item, we could retrieve the price of an item with a dictionary item such as
1: I 2: TRANS(STOCK, ITEM, PRICE, 'V') 3: MD2 4: Price 5: 6R 6: MA typical dictionary might contain many I-types that retrieve different items from the STOCK file, requiring us to redefine the relationship between the two files every time. In this example, the relationship is provided simply by the ITEM value but it might be much more complex, resulting in repetition of the complex expression with a corresponding increase in maintenance effort and a greater chance of a typographical error going unnoticed.
We could instead create an L-type record named, perhaps, STK.
1: L 2: ITEM 3: STOCKThis defines the relationship between the two files but does not identify a particular field to be retrieved. Using this link record, the I-type to retrieve the price references the link name and the name of the field to be retrieved, separated by a percent sign.
1: I 2: STK%PRICE 3: MD2 4: Price 5: 6R 6: MWhen comparing the two methods for just one retrieved field, it may be hard to see the advantage but in a dictionary that defines access to many different items from the secondary file, the gains become clear.
The query processor allows use of links as part of a query sentence without needing a dictionary item at all for the specific field to be retrieved. Whereas we could do this with an EVAL expression such as
LIST SALES EVAL "TRANS(STOCK, ITEM, PRICE, 'V')"this now becomes simply
LIST SALES STK%PRICE
Links can also be used as data items inside I-type expressions:
STK%PRICE * TAX