DBUpdate

Maintained only to provide backward compatibility with legacy applications. Do not use in new code.

(Engine-Level Function)

Description: Executes in its own thread to update a VTScada database from a given stream and returns an indication of parameter errors.
Returns: Numeric
Usage: Script Only.
Function Groups: Database and Data Source
Related to: DBAdd | DBInsert | DBListGet | DBGetStream | DBListSize | DBRemove | DBSystem | DBTransaction | DBValue
Threaded: Yes
Format: DBUpdate(DBSysVal, Stream [, EventCode])
Parameters:  
DBSysVal  
Required. The database value to use. This is the return value from a DBSystem call.
Stream   
Required. Any stream value created from the contents of a database. This results from a DBGetStream statement.
EventCode  
Required. An optional variable in which the event code for the function is returned. This parameter may be used to indicate completion of the function, as it will not be set to a valid value until finished executing. It has the following meaning

Value 

Meaning

Database successfully updated

Update failed


EventCode may be replaced by a constant or Invalid if it is not required.
This parameter will not be set if there is a parameter error (see comments)

Comments: This function executes in the thread created by the DBSystem call, so it will not block other statements from executing. This does mean, however, that the timing for EventCode becoming valid (marking that the statement has finished executing) is unpredictable and should therefore be checked for validity prior to executing other statements that rely on this statement's results.

The return value for this function indicates if any of its key parameters (DBSysVal or Stream) are invalid. It will immediately return a value of false (0) unless a key parameter was invalid, in which case it will return true (1). Note that the return value only signals completion of the function's execution if it is true, otherwise the function will continue executing in the thread created for it.

Because the value of the Stream parameter is created from a database, the DBSystem statement that created the database had to have a valid first parameter (the file name in which the database contents are stored). Do not attempt to access the database file directly via a FileStream statement if any DBSystem functions referencing this file are active, since the results may be unpredictable.

This function is useful to synchronize the database setup on two machines over a network. It allows a secondary machine to load the file from the first, thus duplicating its attributes precisely.
If the database file has its read-only attribute set when this function is executed, it will be cleared automatically by execution of the function.

Example:

  OldDB = DBSystem(OldFile, "", 0, 0, 32 { key }, 2 { field 1 }, 3 { field 2 }); 
  NewDB = DBSystem(NewFile, "", 0, 0, 32 { key }, 2 { field 1 }, 3 { field 2 }); 
  If Valid(NewDB) && ! GotStream;
  [
    GotStream = 1; 
    DBGetstream(NewDB, Stream); 
  ]
  If Valid(OldDB) && Valid(Stream) && ! Updated;
  [
    Updated = 1; 
    DBUpdate(OldDB { Database to update }, 
             Stream { Database from which to update }, 
             Code { Event code holder }); 
  ]