version 1.5
OP Set access mode (connectionID; tableID; accessMode) Longint
Parameter | Type | Description | |
connectionID | Longint | Connection ID with target server | |
tableID | Longint | Number of the table in the database | |
0 = all tables | |||
accessMode | Longint | Access mode | |
0 = read-only | |||
Otherwise, read-write | |||
Function result | Longint | Error code result for the function |
Description
OP Set access mode sets the access mode for tableID to either read-only or read/write for this connection.
If you pass 0 in tableID, the function sets the access mode for all the tables in the database.
In read-only mode, the records in tableID that you retrieve on your local machine by using binds are locked. This means that you cannot delete or update those records. You can, however, add records.
When a new connection is opened, all the tables of the database are in read/write mode for this connection.
Read-Only Mode
While a table is in read-only mode, you will be able to display or print records in the table but not modify them. If you just want to display records, set the file to read-only mode. This ensures that other users will be able to access records in the table in read/write mode.
Note that read-only mode only applies to editing existing records. It does not affect the creation of new records. You can add records to a read-only table.
Read/Write Mode
If you want to modify records in a table, the table must be in read-write mode. By default, all tables are in read/write mode when you open a connection.
In read/write mode, you can save a modified record as long as no other user or process has acquired a lock on that record first. If the record is locked, you will be able to view the record but not modify it.
Accessing a table in read/write mode does not mean that a particular record is in read/write mode. In fact, a record might already be in use by another client; in this case, the record is returned to you in read-only mode and it is said to be locked.
To test whether or not a record is locked, you must download at least one field from the record. Three routines allow you to test the lock status of a record: OP Goto selected record, OP Goto record, and OP Load record.
Error Codes
If OP Set access mode executes correctly, it returns 0. Otherwise, this function returns one of the following errors:
Error Code | Description |
-9972 | Table number is out of range. |
10128 | The 4D Open for 4th Dimension package has not been initialized. |
10136 | The connection does not exist. |
10154 | This command cannot be executed right now. |
Example
In this example, we create a selection of customer records in order to print them. Since we do not intend to modify the content of these records, we set the access mode of the [Customers] table to read/only, allowing other processes access to the records.
C_LONGINT (vTableID) C_LONGINT (vFieldCompany;vCompValue) C_LONGINT ($errCode;vRecords) ` Get tabel [Customers] ID and field [Customers]Company ID $errCode := OP Get one field number (vConnectID;"[Customers]Company";vTableID;vFieldCompany) ` Query the table for all company with a name begining with Ab vCompValue := "Ab@" $errCode := OP Single query (vConnectID;vTableID;vFieldCompany;"=";->vCompValue;vRecords) ` Order the selection by Company name $errCode := OP Single order by (vConnectID;vTableID;vFieldCompany;">") ` Set access mode to read only, setting it is only necessary BEFORE loading a record $errCode := OP Set access mode (vConnectID;vTableID;0) PrintCustomerRecords
See Also
OP Load record, OP Unload record, READ ONLY, READ WRITE.