QMWrite

Top  Previous  Next

 

The QMWrite function writes a record. This is analogous to the QMBasic WRITE statement.

 

 

Format

 

VBQMWrite ByVal FileNo as Integer, ByVal Id as String, ByVal Rec as String

 

Cvoid QMWrite(int FileNo, char * Id, char * Rec)

 

ObjSession->Write(FileNo, Id, Rec)

 

where

 

FileNois the file number returned by a previous QMOpen() call.

 

Idis the id of the record to be written.

 

Recis the data to be written to this record.

 

 

The QMWrite function writes the given data to the file opened as FileNo. If a record with this Id already exists, it is replaced. If the record does not already exist, it is added.

 

An application should always obtain an update lock on the record before writing it. This function releases the lock.

 

When writing a new record to a directory file on a Linux or Unix system, the operating system level file that represents the QM record is created using the umask value specified by the UMASK configuration parameter or, if this parameter is not present, a default of 002. This behaviour can be modified by executing a UMASK command either from the LOGIN paragraph or by using the QMExecute() function.

 

 

Examples

 

VB

Rec = QMReadu(fClients, ClientNo, True, ErrNo)

Rec = QMReplace(Rec, 1, Pos, 0, NewData)

QMWrite fClients, ClientNo, Rec

C

Rec = QMReadu(fClients, ClientNo, TRUE, ErrNo);

Rec2 = QMReplace(Rec, 1, Pos, 0, NewData);

QMWrite(fClients, ClientNo, Rec2);

QMFree(Rec);

QMFree(Rec2);

QMBasic

Rec = session->Readu(fClients, ClientNo, @true, ErrNo)

Rec<1, Pos> = NewData

session->Write(fClients, Id, Rec)

 

The above program fragment reads a record with an update lock, modifies it and then writes it back to the file. A real program should test the ErrNo status from the read operations to determine if they were successful.

 

Note how the C example uses QMFree() to release the dynamic memory allocated to store Rec and Rec2.