OP New record

4D - Documentation   Français   English   German   4D Open for 4D, Command Theme List   4D Open for 4D, Command Alphabetical List   Back   Previous   Next

version 1.5


OP New record (connectionID; bindID) Longint

ParameterTypeDescription
connectionIDLongintConnection ID with target server
bindIDLongintBind list ID
Function resultLongintError code result for the function

Description

OP New record adds a record in the file specified by bindID. The new record will contain the values specified for the fields defined in bindID. All other fields in the same table will be initialized to the default value.

To add a new record, you must first create and define the bind, assign the values to be used in the new record, and then call OP New record. The values to be given to the fields can also be defined before creating and defining the bind.

The new record is automatically unloaded after it has been added.

Error Codes

If OP New record executes successfully, it returns 0. Otherwise, this function returns one of the following errors:

Error CodeDescription
-108Not enough memory to perform this operation.
-9967The record was not modified because it could not be loaded.
-9969Invalid field type requested.
-9971Field number is out of range.
-9972Table number is out of range.
-9998Duplicate index key .
10128The 4D Open for 4th Dimension package has not been initialized.
10136The connection does not exist.
10137The bind list does not exist.
10138The bind list is not related to this file.
10139The bind list is not defined.
10153Unable to convert this type of data.
10154This command cannot be executed right now.

Example

This example lets you copy customer records in the local database to the remote database. Assume that the same [Customers] table structure exists in both the local and the remote database.

      ` 
   C_LONGINT ($custBindID)
   C_LONGINT (remTableID;remFieldID)
   C_LONGINT ($errCode;vRecords;$unused)

   ` get local table name (in case it changes) and number
   $CustTableName := Table name (->[Customers])
   $CustTable := Table (->[Customers])
   $fieldName := $CustTableName + Field name ($CustTable;1)

   ` Get the remote table ID
   $errCode := OP Get one field number (vConnectID;$fieldName;remTableID;$unused)

   ` Create the bind list. It will be made of binds on the local database fields.
   $errCode := OP Create bind ($custBindID)
   For ($i;1; Count fields($CustTable))
      ` Get the local field name in the [Table]Field format, it MUST have the same name as the remote field
      $fieldName :=$CustTableName+ Field name ($custTable;$i)
      ` Bind using a pointer to the local field
      $errCode := OP Define bind by pointer ($custBindID;remTableID;$i;Field ($CustTable;$i))
   End for

   ALL RECORDS ([Customers])
   ` Get a pointer to the field holding the customer ID to lookup
   $custID:= ->[Customers]Customer ID

   ` Browse all the records in the local table
   While ( Not ( End selection ([Customers])))
      ` Lookup the remote table to see if the record exists
      $errCode := OP Single query (vConnectID;remTableID;1;"=";$custID;vRecords)
      If (vRecords = 0) 
         ` If the remote record does not exist : create it
         ` the values to be used in the new record are in the local current record 
         ` as defined in the bind list
         $errCode := OP New record (vConnectID;$custBindID)
      Else
         ` The code here could take care of updating the remote record with the current local values.
      End if
      NEXT RECORD ([Customers])
   End while
   
   $errCode := OP Delete bind ($custBindID)

See Also

OP Load record, OP Set access mode, OP Update record, SAVE RECORD.


4D - Documentation   Français   English   German   4D Open for 4D, Command Theme List   4D Open for 4D, Command Alphabetical List   Back   Previous   Next