QMReadl() |
|
|
The QMReadl() function reads a record with a shareable read lock. It is analogous to the QMBasic READL statement.
Format
where
The QMReadl() function requests the server to return the record with key Id from the file opened as FileNo. A shareable read lock is applied to the record. Any number of users may hold a shareable read lock on the same record at one time but, while any user has a shareable read lock, no other user can establish an update lock or a file lock.
If the action is blocked by a lock held by another user, the function returns a null string and the Errno variable is set to SV_LOCKED. The QMStatus() function can be used to retrieve the user number of the process holding the lock.
If successful, the function returns the record as a dynamic array string and the Errno variable is set to SV_OK. The record is locked by the server process.
If the record cannot be found, the function returns a null string and the Errno variable is set to SV_ELSE. The QMStatus() function can be used to retrieve the error number. The record is locked by the server process. If the lock is not required, it should be released using the QMRelease() function.
Conditions that would normally cause a QMBasic program to abort or to take the ON ERROR clause of a READ statement return a null string and the Errno variable is set to SV_ON_ERROR. The QMStatus() function can be used to retrieve the error number.
In the C API library, the dynamic memory allocated for the returned string must subsequently be freed by the calling program. Note that attempting to read a non-existent record returns a pointer to a null string, not a NULL pointer.
Examples
The above program fragment opens the CLIENTS file and reads two client records. By using QMReadl() instead of QMRead(), there is no possibility that the first record has been updated by the time the second record is read. The program therefore sees a guaranteed consistent state of the data. A real program should test the ErrNo status from the read operations to determine if they were successful.
Note that the C example leaves variables Rec1 and Rec2 pointing to dynamically allocated memory areas that must be released using QMFree() when no longer needed.
|