version 1.5
OP Delete record (connectionID; tableID) Longint
Parameter | Type | Description | |
connectionID | Longint | Connection ID with target server | |
tableID | Longint | Number of the table in the database | |
Function result | Longint | Error code result for the function |
Description
OP Delete record deletes the current record from tableID.
If there is no current record in tableID or if tableID is in read-only mode, OP Delete record has no effect.
If the record is locked, the record is not deleted and OP Delete record does not return an error. You must check the isLocked parameter of the OP Load record, OP Goto record, or OP Goto selected record function.
Error Codes
If OP Delete record executes successfully, it returns 0. Otherwise, this function returns one of the following errors:
Error Code | Description |
-9972 | Table number is out of range. |
-9986 | Record locked during an automatic deletion action. |
-9987 | There are records related to this record . |
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
This example lets you delete customer records in the remote database if they do not exist in the local database. Assume that the same [Customers] table structure exists in both the local and the remote database.
C_LONGINT (remTableID;remFieldID) C_LONGINT ($errCode;vRecords;$unused;$lock) C_LONGINT ($CustBind;$custLockBind) C_STRING (10;remCustID) ARRAY STRING (10;locCustIDs;0) ARRAY STRING (10;remCustIDs;0) ARRAY LONGINT (remCustRecordID;0) ` Get local table name (in case it changes) and number $CustTableName := Table name (->[Customers]) $CustTable := Table (->[Customers]) $fieldName := $CustTableName + Field name (->[Customers]Customer ID) ` Get the remote table ID $errCode := OP Get one field number (vConnectID;$fieldName;remTableID;remFieldID) ` Create a bind list to load remote customer IDs $errCode := OP Create bind ($custBind) $errCode := OP Define bind by pointer ($custBind;remTableID;remFieldID;->remCustIDs) ` Create another bind list to test record locks $errCode := OP Create bind ($custLockBind) $errCode := OP Define bind by pointer ($custLockBind;remTableID;remFieldID;->remCustID) ALL RECORDS ([Customers]) ` Load the local customer IDs in an array Selection to array ([Customers];[Customers]Customer ID;locCustIDs) $errCode := OP All records (vConnectID;remTableID) ` Load the remote customer IDs in an array $errCode := OP Selection to array (vConnectID;$custBind) ` Load also the record numbers for faster retrieval later $errCode := OP Get record numbers (vConnectID;remTableID;remCustRecordID) $deleteCount := 0 ` For each entry in the remote customer IDs For ($i;1; Size of array (remCustIDs)) ` Look up the remote customer ID into the local customer IDs array $local := Find in array (locCustIDs;remCustIDs {$i}) If ($local = -1) `If it was not found, the delete it from the remote table ` First make it the current record,load the ID and lock it, by going to its direct record number $errCode := OP Goto record (vConnectID;remTableID;remCustRecordID{$i};$custLockBind;$lock) ` We want to make sure that the record was not deleted and replaced by another one ` so we check that the Customer ID is really the one we are looking for. If (remCustID = locCustIDs {$i}) ` we will assume the record is not already locked by another process (i.e. $lock = 0) $errCode := OP Delete record (vConnectID;remTableID) $deleteCount := $deleteCount +1 End if End if End for ALERT ("There was "+ String ($deleteCount) + " records deleted on the remote table") $errCode := OP Delete bind ($custBind) $errCode := OP Delete bind ($custLockBind)
See Also
DELETE RECORD, OP Delete selection, OP Single query, OP Update record.