PCL and Customization > System and Utility Functions > Database Locking
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX''">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX''">   
Database Locking
Having more than one process access a database simultaneously can damage the database. In order to prevent this, Patran locks the database while it is in use. Any executable that uses a database (translator, solver, etc.) should also perform a file lock to guarantee secure access of that database. If a database is locked, a message will be relayed indicating that the database is in use.
The stand-alone utility lockfile gives an application developer the ability to lock databases. If this utility is run for a database that is already locked, it will wait five minutes and retry. It will not lock a database until an existing database lock has been cleared.
The lockfile utility requires the name of the database to lock and a command string to execute. The lock will remain active as long as the command executes. The syntax for the lockfile utility is as follows:
lockfile <dbname> <cmd> <cmd_arg1> <cmd_arg2> . . .
Example: Modify the executable start_mytrans (shown in the Example in Spawning a Process, 186) to support database locking.
FUNCTION start_mytrans(dbname, count)
< same as previous example >
/* CHANGED: Format the argument string required by mytranslator */
str_formatc(cmd,”lockfile %s %s -db %s -cnt %d,” @
		dbname, mytrans, dbname, count)
 
/* Spawn the process and continue; do not wait for completion. */
/* If a process spawning error occurs, display it as severity 2 (WARNING) */
status = utl_process_spawn(cmd, FALSE)
IF ( utl_process_error( status ) ) THEN
		utl_display_error( status, 2)
ENDIF
END FUNCTION /* start_mytrans */
Using the previous example, this will execute the following command:
lockfile my.db mytranslator -db my.db -cnt 542