Update External Database from Variable
This command sets a database field value from a CopiaFacts variable. It should be used in a $type decision infobox. Note that the Extended Database Interface feature provides a much more comprehensive method of working with external databases.
The parameters on this command are used as follows:
|value||the value which is to be assigned to the database field. This can either be a constant value or can be the contents of a variable using the normal @ syntax.|
|index||the value which is to be used as an index to look up the record containing the data. This can either be a constant value or can be the contents of a variable using the normal @ syntax.|
|indexfile||the full pathname of the NDX index file to be used. See External Database Files for more information.|
|datafile||the full pathname of the DBF data file to be updated. See External Database Files for more information.|
|fieldname||the field name of the field containing the data which is to be assigned to variable varname. If the fieldname specified on this command matches the key field name in the specified indexfile, then this command will update the index entry to reflect the new key value.|
|oldvalue||the expected old value in the field, which is to be replaced by the new value supplied. You can use this feature in a multi-machine environment, to check that no other node has updated the value between your reading it and updating it. Control will transfer to the $error_exit if the values differ, and the system variable @LASTERROR will be set to 4167. It is your own responsibility to loop back and retry the update if you wish.|
To reference .DBF files which have Clipper or FoxPro indexes, use the datafile parameter to specify a '.DD' file with the same basename as the .DBF file. This .DD file will then contain the name of the index file, and the indexfile parameter must be used to specify the name of the index tag in the specified index file. See External Database Files for more information.
You do not normally need to provide the previous value of the field if only one machine is using the data file. However if you use different IIF files for the $lookup_var and the $update_dbf, it is still possible for other lines on the same machine to affect the result. In this case you need either to specify the old value or to move the process into a single infobox to maintain the integrity of your data file.
If the record is not found or the named field does not exist in the data file, the update fails and control transfers to the $error_exit, if specified. If the index or data files do not exist, the .IIF file is treated as invalid and selecting it will fail. You should not specify this command in an $auto_call IIF unless you assign both the index and data variables in the same IIF (with $set_var) or use pre-initialized system variables.
Increment a system-wide counter indexed by MYKEY:
$lookup_var myvar @mykey myindex mydata count
$set_var oldvar @myvar
$set_var myvar +1
$update_dbf @myvar @mykey myindex mydata count @oldvar
Part of the implementation of a password control which can update a password in the caller ID data file. Because there should not be any duplication of caller ID, it is reasonable not to bother to check the old field value:
$update_dbf @newpass @callerid cid.ndx cid.dbf mypass