ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / Managing databases / HFSQL / HFSQL functions
  • Example 1: Adding a record into a Customer file
  • Example 2: Transferring records between a data file and its alias
Example 1: Adding a record into a Customer 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 into a customer 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" file is created as well as its alias.
In the CUSTOMER file, a new record is created by fixing the automatic identifier (CUSTOMERID) to 1001.
In the CUSTOMERALIAS alias, the default management of automatic identifiers is kept: the automatic identifier starts from 1.
The records are copied from the alias into the CUSTOMER file by HCopyRecord. The automatic identifier of the record is kept during the copy (hCopyAutoId constant). Then, the copied record is added to the CUSTOMER file. The risks of duplicates are minimized.
// Create the CUSTOMER data file
HCreate(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(CUSTOMER, 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)
HCreate(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 record from CUSTOMERALIAS to CUSTOMER
   	HCopyRecord(CUSTOMER, CUSTOMERALIAS, hCopyAutoID)
   	// Add the record
   	IF HAdd(CUSTOMER, 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: 06/14/2024

Send a report | Local help