PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WD20] Unique Key
[WD20] Unique Key
Débuté par Curtis, 03 sep. 2015 21:24 - 4 réponses
Posté le 03 septembre 2015 - 21:24
I have a Barcode field that is a unique key. It's in a file called Test. If I try to add duplicate Barcodes via inline editing in the control center or by HAdd()/HModify() I get a duplicate key warning. But when I add duplicate Barcodes via an sql query I do not get a warning and the duplicate record are entered into the file.

Is this supposed to happen? Shouldn't the sql code fail on account of the duplicate keys?
Posté le 04 septembre 2015 - 06:55
Hi, you have to take in account that empty barcode fields are "key values" as well and two empty barcode fields will trigger a duplicates error. Afaik, HFSQL has no way to ignore empty keys / NULL keys for an otherwise unique key-item. Workaround: make the key item a key with duplicates allowed but make sure by programming that only unique values are fed and empty key values are accepted.
Posté le 04 septembre 2015 - 11:53
Hi Curtis,

Your question makes me think that you did not use the hcheckduplicates option in your hexecutequery. You should read all the details about it in the help.

However, PCSoft help advise to use hadd/hmodify/hedelete for all writing operations instead of queries (and it's much simpler to manage in your code, as an update query with hcheckduplicate forces a transaction, and you then have trouble knowing on which record of the query you got a duplicate error and...) well, you get the drill

Best regards
Posté le 04 septembre 2015 - 16:07
Thanks Fabrice. Unfortunately I have to use queries when dealing with multiple records as it is much faster than looping throuh h functions.
Posté le 04 septembre 2015 - 16:13
oops