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
  • Managing automatic identifiers
  • Reusing the deleted or freed records
  • Version of data file after an addition
  • Adding a record into a query
  • Adding records into a view
  • Browsing and adding records
  • Slowness when adding or deleting a record for the first time in an HFSQL data file
  • Addition into a database in Hyper File 5.5 format
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Adds:
  • the record found in memory into the data file (query or view).
  • WEBDEV - Server code the record found in a Record variable into the data file (query or view).
The indexes corresponding to all the keys used in the data file are automatically updated. The possible memos are added if the management of memos is enabled (HSetMemo).
After the call to HAdd:
  • Automatic error handling is available for several types of error: Duplicate error, Integrity error, Password error, Modification conflict and status error during modification conflict, Blocking error, etc. For more details, see HFSQL error handling help.
  • If the management of duplicates is enabled and if the data file contains a unique key, HErrorDuplicates returns True if the value of added key is not unique. The record is not added.
  • The added record becomes the current record. The automatic identifier is automatically filled. By default, the current iteration is not affected.
Note The entire record in memory is written to the data file with the values assigned to it (and, failing this, the contents of the previously read record). To clear the values from the record in memory, all you have to do is use HReset.
// Add a record in a data file
// (record described through programming)
Customer.LastName = "Clark"
Customer.FirstName = "Vince"
Customer.Address = "Palm Lane"
Customer.City = "Philadelphia"
Customer.Zip = "19101"
Customer.Country = "USA"
HAdd(Customer)
HFSQL ClassicHFSQL Client/ServerStored proceduresHyper File 5.5OLE DBNative Connectors (Native Accesses)
// Add a record entered in a window
// in the Customer data file
ScreenToFile()
HAdd(Customer)
Syntax

Adding the record found in memory into a data file, view or query Hide the details

<Result> = HAdd([<Data file> [, <Options>]])
<Result>: Boolean
  • True if the record was added,
  • False if a problem occurred (integrity error, duplicate error, etc.). HError is used to identify the error.
<Data file>: Optional character string
Name of the data file, view or query used.
If this name is not specified, HAdd will use the last data file used by the last HFSQL function (function starting with "H").
<Options>: Optional constant
Used to configure:
  • the effect of addition on the current browse.
  • the mode for calculating the automatic identifier. For more details, see Managing the automatic identifier during an addition.
  • the lock mode applied to the added record.
    • PHP Management of locks not available in PHP.
  • the management of duplicates.
  • the management of integrity.
Hyper File 5.5 This parameter is ignored.
hAffectBrowseInfluence of addition on route: Addition assigns route.
For example, HReadNext used after HAdd positions on the record found after the added record.
The hAffectBrowse constant has priority over the hWriteDefault constant.
hCheckDuplicatesDuplicate management mode: Controls duplicates for this operation, even if duplicate control is switched off (function HSetDuplicates)..
A WLanguage error occurs if the hIgnoreDuplicates and hCheckDuplicates constants are used at the same time.
PHP This constant is not available.
hCheckIntegrityIntegrity management mode: Controls operation integrity even if automatic integrity control is disconnected (function HSetIntegrity).
A WLanguage error occurs if the hIgnoreIntegrity and hCheckIntegrity constants are used at the same time.
PHP This constant is not available.
hFixeIdAutoAutomatic ID calculation mode The automatic identifier is not calculated at the time of addition: the identifier value will be that memorized at the time of addition.
The next identifier value calculated by the HFSQL engine will correspond to the largest identifier value in the data file +1.
If the constants hFixeIdAuto and hForceIdAuto are used at the same time, a WLanguage error is generated.
hForceIdAutoAutomatic identifier calculation mode: The automatic identifier is not calculated when the automation is added.. The identifier corresponds to:
  • the value assigned to the item through programming (CUSTOMERID = 7 for example)
  • the default identifier value specified in the data model editor (if the data file was just opened, with no record read)
  • the identifier value found in memory (identifier value for the last record read in the data file).
After adding the record, the next automatic identifier calculated by default by the HFSQL engine will be calculated without taking into account the value added by hForceIdAuto.
If the constants hFixeIdAuto and hForceIdAuto are used at the same time, a WLanguage error is generated.
hIgnoreDuplicatesDuplicate management mode: Ignores duplicate control for this operation, even if automatic duplicate control is connected (function HSetDuplicates)..
A WLanguage error occurs if the hIgnoreDuplicates and hCheckDuplicates constants are used at the same time.
PHP This constant is not available.
hIgnoreIntegrityIntegrity management mode: Ignores the integrity check on this add operation, even if the automatic integrity check is connected (function HSetIntegrity)..
A WLanguage error occurs if the hIgnoreIntegrity and hCheckIntegrity constants are used at the same time.
PHP This constant is not available.
hLockNo
(default value)
Added record blocking mode: No blocking: the added record will not be blocked.
PHP This constant is not available.
hLockReadWriteAdded record lock mode: Read/write lock: the added record will be locked for reading and writing.. This record cannot be read or modified by another application. Only the current application can modify it, read it or unlock it.

This constant is available for HFSQL Client/Server and Native Connectors only.
PHP This constant is not available.
hLockWriteAdded record lock mode: Lock in write mode: the added record will be locked in write mode.. This record can be read by another application but it cannot be modified by another application. Only the current application can modify it or unlock it.

This constant is available for HFSQL Client/Server and Native Connectors only.
PHP This constant is not available.
hWriteDefault
(default value)
Influence of addition on route: Addition does not assign current route.
For example, HReadNext used after HAdd positions on the record found after the current record before the addition.
The hAffectBrowse constant has priority over the hWriteDefault constant.
WEBDEV - Server code

Adding the content of a Record variable into a data file, view or query Hide the details

<Result> = HAdd(<Data file> , <Record> [, <Options>])
<Result>: Boolean
  • True if the record was added,
  • False if a problem occurred (integrity error, duplicate error, ...). HError is used to identify the error.
<Data file>: Character string
Name of the data file, view or query used.
<Record>: Record variable
Name of the Record variable containing the different values of items.
<Options>: Optional constant
Used to configure:
  • the effect of addition on the current browse.
  • the mode for calculating the automatic identifier. For more details, see Managing the automatic identifier during an addition.
  • the lock mode applied to the added record.
  • the management of duplicates.
  • the management of integrity.
Hyper File 5.5 This parameter is ignored.
hAffectBrowseInfluence of addition on route: Addition assigns route.
For example, HReadNext used after HAdd positions on the record found after the added record.
The hAffectBrowse constant has priority over the hWriteDefault constant.
hCheckDuplicatesDuplicate management mode: Controls duplicates for this operation, even if duplicate control is switched off (function HSetDuplicates)..
A WLanguage error occurs if the hIgnoreDuplicates and hCheckDuplicates constants are used at the same time.
hCheckIntegrityIntegrity management mode: Controls operation integrity even if automatic integrity control is disconnected (function HSetIntegrity).
A WLanguage error occurs if the hIgnoreIntegrity and hCheckIntegrity constants are used at the same time.
hFalsifyTimestampTimestamp field management: By default, a timestamp field contains the date and time of record creation/modification, calculated automatically..
This constant prevents the timestamp field from being updated: the last value in the record will be retained.
hFixeIdAutoAutomatic ID calculation mode The automatic identifier is not calculated at the time of addition: the identifier value will be that memorized at the time of addition.
The next identifier value calculated by the HFSQL engine will correspond to the largest identifier value in the data file +1.
If the constants hFixeIdAuto and hForceIdAuto are used at the same time, a WLanguage error is generated.
hForceIdAutoAutomatic identifier calculation mode: The automatic identifier is not calculated when the automation is added.. The identifier corresponds to:
  • the value assigned to the item through programming (CUSTOMERID = 7 for example)
  • the default identifier value specified in the data model editor (if the data file was just opened, with no record read)
  • the identifier value found in memory (identifier value for the last record read in the data file).
After adding the record, the next automatic identifier calculated by default by the HFSQL engine will be calculated without taking into account the value added by hForceIdAuto.
If the constants hFixeIdAuto and hForceIdAuto are used at the same time, a WLanguage error is generated.
hIgnoreDuplicatesDuplicate management mode: Ignores duplicate control for this operation, even if automatic duplicate control is connected (function HSetDuplicates)..
A WLanguage error occurs if the hIgnoreDuplicates and hCheckDuplicates constants are used at the same time.
hIgnoreIntegrityIntegrity management mode: Ignores the integrity check on this add operation, even if the automatic integrity check is connected (function HSetIntegrity)..
A WLanguage error occurs if the hIgnoreIntegrity and hCheckIntegrity constants are used at the same time.
hLockNo
(default value)
Added recording blocking mode: No blocking: the added recording will not be blocked.
hLockReadWriteAdded record lock mode: Read/write lock: the added record will be locked for reading and writing.. This record cannot be read or modified by another application. Only the current application can modify it, read it or unlock it.

This constant is available for HFSQL Client/Server and Native Connectors only.
hLockWriteAdded record lock mode: Lock in write mode: the added record will be locked in write mode.. This record can be read by another application but it cannot be modified by another application. Only the current application can modify it or unlock it.

This constant is available for HFSQL Client/Server and Native Connectors only.
hWriteDefault
(default value)
Influence of addition on route: Addition does not assign current route.
For example, HReadNext used after HAdd positions on the record found after the current record before the addition.
The hAffectBrowse constant has priority over the hWriteDefault constant.
Remarks

Managing automatic identifiers

By default, the "automatic identifier" item is automatically updated when a record is added into a data file. There is no need to read the record again to find out the value of the automatic identifier. Simply use the syntax <Nom Fichier de données>.<Nom rubrique Identifiant automatique>.
The constants hForceIdAuto and hFixeIdAuto are used to modify the default behavior of the automation identifier.
For more details on automatic identifiers for new records, see Managing the automatic identifier during an addition.
PHPOLE DBNative Connectors (Native Accesses) Special case
  • If the database generates an automatic identifier, the HFSQL engine keeps this value. If the constants hForceIdAuto or hFixeIdAuto constants are specified, the HFSQL engine replaces the generated value with the desired value.
    Note: the constant hForceIdAuto is equivalent to hFixeIdAuto: the automatic identifier calculated by the HFSQL engine the next time a file is added will be unique in the data file.
  • If no automatic identifier is generated by the database, the HFSQL engine generates the value and assigns it to the automatic identifier.
WEBDEV - Server codePHPAjaxHFSQL ClassicHFSQL Client/ServerStored proceduresHyper File 5.5

Reusing the deleted or freed records

When adding a new record, the HFSQL engine optimizes the filling of the data file. The space corresponding to the deleted or freed records is used first when a new record is added.
The crossed records are not re-used.
WEBDEV - Server codePHPAjaxHFSQL ClassicHFSQL Client/ServerStored proceduresHyper File 5.5

Version of data file after an addition

If the record was added to the data file (no duplicate error and no integrity error), the version number of the data file is modified. To get the version number, use HVersion.

Adding a record into a query

Adding a record into a query can be performed:
  • in the query result.
  • in the data files handled by the query (hModifyFile constant used in HExecuteQuery or HExecuteSQLQuery). In this case, the hWithFilter constant is automatically selected.
Regardless of how the query is executed (with or without the constant hWithFilterconstant), adding records to a query is only possible for single-file queries. The calculated items specified during the addition are ignored. They are automatically calculated.
Caution:
  • No addition is allowed in a query that uses groups or aggregates.
  • Integrity and duplicates are not managed by operations on multi-file queries: it is advisable to use transactions to avoid any problems.
WEBDEV - Server codeAjaxHFSQL ClassicHFSQL Client/ServerStored procedures

Adding records into a view

You have the ability to add records into a view created on data files in HFSQL Classic format. These records are added in memory only. To add them into the data file linked to the view (simple view for example), you must use HViewToFile.

Browsing and adding records

You can configure the effect of adding a record during the browse of a data file (hWriteDefault and hAffectBrowse constants). The behavior of earlier versions can be kept with the hAffectBrowse constant.
PHPOLE DBNative Connectors (Native Accesses) Special cases
If the record is added during a browse, it will be visible in the current browse only. If other browse operations have been defined on this database, the new record will only be visible once these browse operations have been reinitialized.

Slowness when adding or deleting a record for the first time in an HFSQL data file

Accessing a record in an HFSQL data file for the first time may take long. To fix this problem:
  • Disable antivirus scanning for ".FIC", ".NDX", ".SDX", ".STX", ".MMO" and ".REP" files.
  • Disable the "Restore the system" option in Windows XP.
WEBDEV - Server codeAjaxStored proceduresHyper File 5.5

Addition into a database in Hyper File 5.5 format

If you use HAdd with a Hyper File 5.5 database:
  • The add options (<Options>) are ignored.
  • The TEXT items are automatically filled with space characters.
  • HAdd cannot be used on a view created from Hyper File 5.5 data files.
Business / UI classification: Business Logic
Component: wd300hf.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Exemplo de Transação Atômica
Exemplo básico:

Erro is Int = 0

Id is 8-byte Int = 0

TransactionStart(“tabela”, “tabelaitens”)

Tabela.campo = valor

If hadd(Tabela) = true
Id = tabela.Pai_ID
Info(“gravou pai ”)

TabelaItens.Pai_ID = ID
TabelaItens.Produto = valor

If hadd(tabelaItens) = true
Info(“gravou um item”)
Else
Erro++
End

Else

Erro++

End

If erro = 0
TransactionEnd()
Else
TransactionCancel()
End
Boller
23 Feb. 2023
Exemplo com Exception
HtransactionStart(Tablax,, tablay)
When Excepton in
Tablax.Campo = 1
If hadd()
End
HtransactionEnd()
DO
HtransactionCancel()
END
Boller
23 Feb. 2023
Exemplo
// Add a record in a data file
Customer.LastName = "Clark"
Customer.FirstName = "Vince"
Customer.Address = "Palm Lane"
Customer.City = "Philadelphia"
Customer.Zip = "19101"
Customer.Country = "USA"
IF HAdd(Customer) = true
info("Gravou")
else
info(Errorinfo(),Herrorinfo())
end

AGORA SE QUER ECONOMIZAR LINHAS DE CODIGO FAÇA ASSIM:

// in the Customer data file
ScreenToFile()
IF HAdd(Customer) = true
info("Gravou")
else
info(Errorinfo(),Herrorinfo())
end
Boller
18 Jan. 2023

Last update: 11/15/2024

Send a report | Local help