|
Performs a case-sensitive search for value in the index of the database and moves the record pointer to the first matching record in the database.
<MvFIND> requires at least one index be open for the database being searched. Attributes
If a match is found in the index, the record pointer moves to the first matching record in the database. If NAME is omitted, the primary database's main index will be searched. To succeed, the search must match starting at the first character in the indexed value. The first record found by <MvFIND> will differ depending on which index is the controlling index. If the record is NOT found the boolean variable alias.d.eof is true (1) and the end of the database with alias alias has been reached. If found, alias.d.eof is false (0). Also the variable g.MvFind_error will contain 'EOF' if <MvFIND> did not succeed, and null otherwise. ExamplesIn the example below, if the index file emp_names.mvx contains an index based on the employee field, the <MvFIND> will search for the first record in the database for which the employee name starts with 'Mary'. Example:<MvOPEN NAME="employees" DATABASE="{ g.path $ 'workers.dbf' }" INDEXES="{ g.path $ ' emp_names.mvx' }"> Since <MvFIND> always finds the first matching record, subsequent calls to <MvFIND> will find the same record again. Therefore, if you want to find all records matching a particular value, you should use other techniques. Use <MvSKIP> inside an <MvWHILE> loop to locate the rest of the records in the database that match. The advantage of starting with an <MvFIND> is that you can quickly locate the first such record. Since the database is indexed, you can be certain that other matching records will directly follow this one in indexed order. <MvSKIP> will skip in the order if the database is indexed. Example:<MvASSIGN NAME="l.search_string" VALUE="Mary"> <MvFIND> is always case-sensitive. If you want to do a case-insensitive search, you can create an index whose key expression converts all values to uppercase or lowercase, and then search using values in the desired case. The built-in string function toupper and tolower Example:<MvMAKEINDEX NAME="employees" INDEXFILE="emp_names.mvx" EXPR="{ tolower(employees.d.employees) }"> <MvFIND NAME="employees" VALUE="{ tolower(l.search_string) }"> Interaction Between Indexing and NavigationAll open indexes are updated automatically and immediately if the contents of the database are changed. In particular, if the indexed field of the current record changes, the record's position in indexed order may change, but the record pointer will continue to point to that record. This has an impact on the results given by <MvFIND> and <MvSKIP>. Suppose a database index contains the following entries, corresponding to the database's name field: Aardvark Consider the following code: <MvFIND VALUE="Dog"> <MvSKIP> <MvEVAL EXPR="db_alias.d.name"> This will display the value 'Giraffe', since the <MvSKIP> skips to the record following 'Dog' in the index. Now let's see what happens if a record is changed: <MvFIND VALUE="Dog"> <MvASSIGN NAME="db_alias.d.name" VALUE="Octopus"> <MvUPDATE> <MvSKIP> <MvEVAL EXPR="db_alias.d.name"> This will display the value 'Zebra'. Remember that when the name field of the 'Dog' record is changed, the index is immediately updated, as follows: Aardvark However, the record pointer still points to the same record, even though that record is at a different position in the index. Since the <MvSKIP> skips to the record following the current record ('Octopus') in the index, it now skips to the 'Zebra' record. |