LOCATE, INSERT and DELETE never quite felt intuitive so I wrote some examples and tests to explain things to myself.
--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
---
You received this message because you are subscribed to the Google Groups "Pick and MultiValue Databases" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mvdbms+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mvdbms/0e20c843-ffa2-4ee2-8561-1ab695534085n%40googlegroups.com.
The default style of LOCATE is as found in products such as Prime Information, PI/open and with certain mode settings in UniVerse and Unidata.
If only field is specified, LOCATE searches for a field that matches string. If field and value are specified but subvalue is omitted, LOCATE searches for a value within the specified field that matches string. If field, value and subvalue are specified, LOCATE searches for a subvalue within the specified field and value that matches string.
Searching commences at the starting position defined in the IN clause. If a match is found, var is set to its field, value or subvalue position as appropriate to the level of the search. If no match is found, var is set to the position at which a new item should be inserted. For an unordered LOCATE this will be such that it would be appended.
Note that the syntax actually reads incorrectly. A LOCATE statement such as
LOCATE DT IN DATES<1> SETTING POS THEN ...
is not searching in DATES<1> at all. It is searching starting at DATES<1>.
UniVerse Style
Pick and Reality systems and the UniVerse database running in Ideal, Pick, Reality or IN2 flavour uses the IN clause to identify the item to be searched, not the starting position. The starting position is assumed to be the first item in the data but may be specified explicitly in the command by including the start item.
This format of LOCATE can be selected by including a line
$MODE UV.LOCATE
in the program on a line preceding the LOCATE statement.
Pick Style
The original Pick database used a very different syntax which can be used in QM without any special mode settings. Note that despite the presence of brackets, this is a statement and should not be confused with the LOCATE() function described below.
In all three styles, the THEN clause is executed if the string is found in dyn.array. The ELSE clause is found if the string is not found.
In QMBasic, unlike other multivalue environments, the SETTING clause is optional. If omitted, the THEN or ELSE clause is executed as described above but no positional information is returned.
Note that this syntax, as found in Information style multi value products, is actually illogical. The IN clause does not specify the data within which to search. Instead it specifies the start position for the search. The alternative syntax enabled by the UV.LOCATE compiler mode and described below is more logical. This syntax is found in Pick, Reality and some flavours of UniVerse.
Feel free to peruse here for QM documentation (I love this format):
--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
---
You received this message because you are subscribed to the Google Groups "Pick and MultiValue Databases" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mvdbms+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mvdbms/b613f6f1-08d0-4b87-8ef3-461045a3b36cn%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mvdbms/2ad3a01c-e3f2-49ef-9265-a2f2b8a536dcn%40googlegroups.com.
I agree, the format and structure is greate but is fails to mention the follows syntax supported in some Mutlivalue versions:
LOCATE element IN dyn.array<attribute.expr,val.expr,subval.expr>,var BY search.type SETTING location THEN
Statements
END ELSE
statements
END
Regards,
Jay LaBonte
To view this discussion visit https://groups.google.com/d/msgid/mvdbms/2ad3a01c-e3f2-49ef-9265-a2f2b8a536dcn%40googlegroups.com.