FILEFLEX API REFERENCE



NAME
DBWriteRec -- Write data to the database

SYNTAX
DBWriteRec(control-code, record-num [,data [, encryption-list, key]])
DBWriteRec(control-code, record-num [, encryption-list, key])

CATEGORY
Updating Information

DESCRIPTION
To update all or part of a database record, you can use the FileFlex function DBWriteRec.

This function works by evaluating a control-code and writing record values based on that control code. Valid control codes are:

  • A: Write the absolute contents of the entire record
  • AE: Write the absolute contents of a record and encrypt
  • G: Write the contents of global variables directly to records
  • GE: Write the contents of globals and encrypt

If you pass a "G" as the first argument, you indicate to DBWriteRec that you want to take values from global variables and pass them to the database. The names of the global variables need to correspond to the names of the FileFlex fields. One important note: it's best to get the value of all fields into globals using DBGetCurrRecVal prior to changing a global's value. This is because FileFlex will write back the entire record and if a global is not defined for a given field, it will write an empty value into that field.

The second argument is the record number of the record to be updated. It can be a value, a variable, or the DBCurrRecNum() function.

When encrypting data, you'll need to pass a encryption field list to the command. An encryption field list consists of a list of field names, separated by commas (i.e., "SALARY,OFFER,MAX") of those fields you wish to encrypt. Fields not included in the encryption list will not be encrypted.

You can also write the entire record data at once, by creating an absolute data value and passing it to FileFlex. You'd use the "A" control code for this. To do this, be sure the values are contained in a separate container (i.e., a variable) whose name is supplied as the third argument. Values are formatted with the field name and contents, separated by a comma. For example, assume that the variable myData contained the following:

NAME,David Gewirtz
COMPANY, Component Software
PRODUCT, FileFlex

A call to DBWriteRec in the form:

put DBWriteRec("X", 33, myData) into dbResult

would place "David Gewirtz" into the field "NAME", "Component Software" into the field "COMPANY", and "FileFlex" into the field "PRODUCT", all on record 33.

To add a new record to a database file, you can use any of the various approaches to updating an individual record in the database but supply a record number that is exactly one number higher than the number of records in the current database. Before you add a record, then, you should use the DBCount function to determine how many records are in the database now, then add 1 to that value. Pass the result to the FileFlex DBWriteRec or DBWriteMemo function as appropriate.

The following lines will set up a variable called newRecNum to contain a value one higher than the number of records in the current database.

put DBCount()+1 into numRecs

Now you can use this value (which you might want to declare as a global variable for use in other functions) to add records to the file. To add an entire record to a database file in FileFlex, you can choose any of the three above update methods.

Index files are maintained automatically by FileFlex. Whenever you execute a DBWriteRec function call, FileFlex updates all currently open index files for that database. No special programming is needed.

The FileFlex 3.0 write and read functions contain the same capabilities and limits of previous versions, even though the FileFlex file format now supports all FoxPro data types including binary and huge memos. Future versions of FileFlex will add intelligent support for large object data typing, but we've got plenty to keep us busy with the current release.


NOTES
The syntax for this function was incorrectly described in earlier versions of FileFlex. It is important to note that the record number is ALWAYS the second parameter.

It is important that you pre-define and fill a complete set of global variables with names corresponding to those in the database. Since globals behave differently between development environments, passing a full set of globals is the best way to make sure everything works the way you want.


INTERNAL FUNCTION NUMBER
30


Copyright © 1992-1998 by David Gewirtz, under license to Component Enterprises, Inc.
Contact: info@component-net.com

Casa de Bender