ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / Managing databases / HFSQL / HFSQL functions
  • Example 1: Merging files that have a partial common structure
  • Example 2: Copying a record while keeping the value of its automatic identifier
  • Example 3: Copying a record while keeping the value of its automatic identifier
  • Example 4: Copying a record by using items with different names
HCopyRecord (Example)
Example 1: Merging files that have a partial common structure
WINDEVWEBDEV - Server codeJavaUser code (UMC)AjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5 The following example is used to merge the files named CUSTOMER and CUSTOMER2. The characteristics of these data files are as follows:
  • the LASTNAME and FIRSTNAME items are character strings in both data files
  • the customer code CUSTCODE is an integer in CUSTOMER.FIC
  • the customer code CUSTCODE is a string in CUSTOMER2.FIC
  • the ADDRESS item exists in CUSTOMER2 only
Once this code has been run, the CUSTCODE integer of CUSTOMER.FIC file was converted into a string in the CUSTOMER2.FIC file according to the conversion rules of WLanguage. ADDRESS was initialized to its default value in all the records copied into CUSTOMER2.
// Show the number of records in CUSTOMER2.FIC
Trace(HNbRec(CUSTOMER2))
 
HReadFirst(CUSTOMER, LASTNAME)
// Browse the records of CUSTOMER.FIC
WHILE NOT HOut(CUSTOMER)
// Add the record to CUSTOMER2
HCopyRecord(CUSTOMER2, CUSTOMER, hDefaultVal)
HAdd(CUSTOMER2)
 // Show the new number of records
Trace(HNbRec(CUSTOMER2))
// Go to next record
HReadNext(CUSTOMER, LASTNAME)
END
Example 2: Copying a record while keeping the value of its automatic identifier
WINDEVWEBDEV - Server codeJavaUser code (UMC)AjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5 The following code is used to copy a record from CUSTOMER to CUSTOMER2. These two files contain three common items:
  • LASTNAME, FIRSTNAME are character strings in both data files,
  • the customer code CUSTCODE is the automatic identifier in both data files.
The record for the customer named Smith must be copied from the CUSTOMER file to the CUSTOMER2 file. Using HModify allows you to keep the automatic identifier (HAdd would have generated a new identifier automatically, and therefore it is not used in this example).
HReadSeekFirst(CUSTOMER, "Smith")
HCopyRecord(CUSTOMER2, CUSTOMER, hCopyAutoID + hDefaultVal)
HModify(CUSTOMER2) // HModify keeps the automatic identifier
Example 3: Copying a record while keeping the value of its automatic identifier
WINDEVWEBDEV - Server codeJavaUser code (UMC)AjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5 The following code is used to copy all the records from CUSTOMER to CUSTOMERBIS.
The automatic identifier is copied and its value is kept during the addition (hSetIdAuto parameter in HAdd).
// Transfer the records from 'CUSTOMER' to 'CUSTOMERBIS'
EXTERN CUSTOMERBIS
HAlias(CUSTOMER, "CUSTOMERBIS")
HCreationIfNotFound("CUSTOMERBIS")
HReadFirst(CUSTOMER, CUUNIKKEY)
WHILE NOT HOut(CUSTOMER)
HCopyRecord(CUSTOMERBIS, CUSTOMER, hCopyAutoID)
HAdd(CUSTOMERBIS, hSetIDAuto)
HReadNext(CUSTOMER, CUUNIKKEY)
END
Example 4: Copying a record by using items with different names
WINDEVWEBDEV - Server codeJavaUser code (UMC)AjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5 The following code is used to copy a record from CUSTOMER to CUSTOMER2. The characteristics of these data files are as follows:
  • LASTNAME, FIRSTNAME are character strings in both data files,
  • IDAUTO is the automatic identifier in both data files,
  • the customer code CUSTCODE is an integer and it exists in CUSTOMER only,
  • the ADDRESS item exists in CUSTOMER2 only,
  • the CUSTOMERIDENTIFIER item is a string and it exists in CUSTOMER2 only.
This example is used to:
  • copy the CUSTOMER file into the CUSTOMER2 file by copying the customer code CUSTCODE into CUSTOMERIDENTIFIER.
  • store the value of the automatic identifier AUTOID.
  • initialize the address ADDRESS with its default value.
HCreation(CUSTOMER2)
HReadFirst(CUSTOMER, LASTNAME)
// Browse the records of CUSTOMER.FIC
WHILE NOT HOut(CUSTOMER)
// Add the record to CUSTOMER2
  HCopyRecord(CUSTOMER2, CUSTOMER, ...
"LASTNAME, FIRSTNAME, AUTOID, CUSTCODE", ...
"LASTNAME, FIRSTNAME, AUTOID, CUSTOMERIDENTIFIER", ...
hDefaultVal + hCopyAutoID)
HModify(CUSTOMER2)
// Go to next record
HReadNext(CUSTOMER, LASTNAME)
END
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help