Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
5
Erster Beitrag:
vor 2 Jahren, 9 Monaten
Letzter Beitrag:
vor 2 Jahren, 9 Monaten
Beteiligte Autoren:
Curtis, Fabrice Harari, GuenterP

[WD20] Unique Key

Startbeitrag von Curtis am 03.09.2015 19: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?

Antworten:

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.

von GuenterP - am 04.09.2015 04:55
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

von Fabrice Harari - am 04.09.2015 09:53
Thanks Fabrice. Unfortunately I have to use queries when dealing with multiple records as it is much faster than looping throuh h functions.

von Curtis - am 04.09.2015 14:07
oops

von Curtis - am 04.09.2015 14:13
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.