ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / Managing databases / HFSQL / HFSQL functions
  • Example 1: Adding a record to a customer data file
  • Example 2: Transferring records between a data file and its alias
Example 1: Adding a record to a customer data file
PHPHFSQL ClassicHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses) The customer form is displayed on the screen. ScreenToFile is used to load the values entered in memory.
// Add a record to a customer data file
ScreenToFile()
IF HAdd(CUSTOMER) = False THEN
	Error("Unable to add the customer")
END
Example 2: Transferring records between a data file and its alias
HFSQL ClassicHFSQL Client/ServerHyper File 5.5OLE DBNative Connectors (Native Accesses) A "Customer" data file is created, along with its alias.
In the "Customer" data file, a new record is created by setting the automation identifier (IDCLIENT) to 1001.
In the ALIASCLIENT alias, the default automatic identifier management is retained: the automatic identifier starts at 1.
Records are copied from the alias to the "Client" data file using the function HCopyRecord function.. The record's automation ID is retained during copying (constant hCopieIdAuto). The copied record is then added to the "Customer" data file. The risks of duplicates are minimized.
// Create the CUSTOMER data file
HCreation(CUSTOMER)
// Assign the automatic identifier
CUSTOMER.CUSTOMERID = 1001
// Add a record into the Customer file 
// without calculating the automatic identifier
// The first 1000 records are reserved
IF HAdd(CLIENT, hSetIDAuto) = False THEN
	Error("Unable to add the customer")
	// Find out the error details by checking 
	// HErrorDuplicates, HErrorIntegrity
	// HErrorLock
END
// Create alias
HAlias(CUSTOMER, CUSTOMERALIAS)
HCreation(CUSTOMERALIAS)
// Add records into the CUSTOMERALIAS alias 
// (the automatic identifier will be set to 1)
IF HAdd(CUSTOMERALIAS) = False THEN
   	Error("Unable to add the customer")
   	// Find out the error details by checking 
	// HErrorDuplicates, HErrorIntegrity
   	// HErrorLock
END

// Other additions
...

// Copy the customers from CUSTOMERALIAS to CUSTOMER
i is int = 1
HRead(CUSTOMERALIAS, i)
// Copy the record 
// as long as records are still found in the alias
// and as long as the identifier does not exceed 1000
WHILE NOT HOut(CUSTOMERALIAS) AND CUSTOMERALIAS.CustomerID < 1001
   	// Copy the ALIASCLIENT record into the CLIENT data file
   	HCopyRecord(CLIENT, ALIASCLIENT, hCopyAutoID)
   	// Add the record
   	IF HAdd(CLIENT, hSetIDAuto) = False THEN
		Error("Unable to add the customer")
		// Find out the error details by checking 
		// HErrorDuplicates, HErrorIntegrity
		// HErrorLock
	END
   	// Next record of the alias
   	i++
   	HRead(CUSTOMERALIAS, i)
END
Minimum version required
  • Version 9
This page is also available for…
Comments
Example
If Hadd(Customers) = true

toastdisplay("Gravou com sucesso")

else

info("Erro inesperador! "+ herrorinfo() + error())

end

/// or

ok is boolean = Hadd(Customers)
Boller
18 Jul. 2020
Duplicar Registros
//Duplicar Registros

Nessa aula vou mostrar como eu faço para duplicar Registros

pedido.data_emissao=DateSys()
HAdd(pedido)
TableDisplay(TABLE_Pedido)

//Blog com Video e Exemplo

http://windevdesenvolvimento.blogspot.com.br/2016/10/aula-930-windev21-curso-246-dica.html

https://www.youtube.com/watch?v=gbFkTcVYeTA
De matos
04 Oct. 2016

Last update: 12/06/2024

Send a report | Local help