Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
10
Erster Beitrag:
vor 5 Jahren, 9 Monaten
Letzter Beitrag:
vor 5 Jahren, 9 Monaten
Beteiligte Autoren:
Clarion Ghost, Paulo Oliveira, Al, Piet van Zanten, issah

Duplicate Key Error

Startbeitrag von Clarion Ghost am 23.09.2012 10:32

Morning,

I am collecting email addresses. To prevent the user making duplicate entries I have made the data file item a unique key.

When I try to enter a duplicate email aaddress, WebDev, quite correctly, throws up its own system error.

I would prefer to display info("Duplicate Entry not allowed") and then return the user to the edit box when I try to HAdd or HModify.

How would I do this please.

Many Thanks

Antworten:

Simplest way might be to just do the ff:

if not hreadseekfirst(File,email,edt_email) then
screentofile()
hadd(file)
else
info("Email address already exists")
end

von issah - am 23.09.2012 14:31
Hi Ian,

Hadd(File)
If hErrorDuplicates() then

Look on the Webdev Solutions forum for my returntocapture solution.
Of course you can simplify the code for just one field.
1. Create the global string variables sError and sControl.
2. If hErrorDuplicates then sError="errtext"; sControl=MyControl..Alias; return
3. Page load (onload) code (browser): if sError"" THEN Info(sError); sError=""; ReturnToCapture(sControl)

Regards,
Piet

von Piet van Zanten - am 23.09.2012 15:37
Ian,
check the help for Assisted management of HyperFileSQL errors to enable/disable or customize it.

http://doc.windev.com/en-US/?3044188

von Paulo Oliveira - am 24.09.2012 08:55
Hi,

I have read through the above and am trying to understand how this works,

If I run

HSetDuplicates(Password,EmailAddress, False)
HModify(Password)

On it's own HSetDuplicates(Password,EmailAddress, False) switches off the duplicate check and the system error window, allowing duplicates to be entered.

Looking at the help text the following finds the duplicate and displays the INFO message. However it also displays system error window.

Am I getting closer?

Many Thanks

HModify(Password)
IF HErrorDuplicates() THEN
HSetDuplicates(Password,EmailAddress, False) // I expected this to switch off the window after finding the duplicate allowing the info message to display?
Info("Message")
RETURN
END

von Clarion Ghost - am 24.09.2012 14:58
Ian,
HSetDuplicates may cause serious problems, if you define one key as unique way do you need to store duplicate values on it?
The only use i see for this function is in some batch import processes to allow all the record to be imported and after that you run some code to be sure that the key only have unique values.

To achieve what you want (as far as i can undestand) HOnError is your best friend.
http://doc.windev.com/en-US/?3044017&name=honerror_function&q=HOnError

von Paulo Oliveira - am 24.09.2012 15:21
Hi.

I have been playing with HOnError but I am still not getting it? The following does the job

// Manage a duplicate error

IF HModify(File) = False THEN
Info("Duplicate Found")
END

When I run the code. I get two reponses.
1. The system error window displaying the data line and the field with the duplicated error, (In this instant an email address?)
and
2, The message "Duplicate Found"

If I can hide the system error window I think the problem is resolved.
I have searched the help pages for something to do this, but can't find anything?

Many Thanks

von Clarion Ghost - am 24.09.2012 16:18
example to disable the error management for all the errors, the operation is cancelled for every error and no display of system error window.

init code of the project:
HOnError("*",hErrAll,"disable_hf_errors")

Global procedure:
PROCEDURE disable_hf_errors()
RESULT opCancel

Your code:
IF HModify(File) = False THEN
IF HErrorDuplicates() = True THEN
Info("Duplicate Found")
else
error("blablabla",errorinfo())
end
END

von Paulo Oliveira - am 24.09.2012 16:26
Hello Ian

You are always going to get duplicate errors when you first create a record if the email address is blank and that it always a possibility

You could leave the email field as indexed but non unique and test for a duplicate manually. To do this, I use the Record number not a primary key

//this code is part of a larger general purpose duplicate checking proc but this is the general method

HAlias("Creditor","LDupChkAlias")
HChangeName("LDupChkAlias","Creditor")
IF HSeek("LDupChkAlias","CreditorCode",Complete(MySelf,20))
IF HRecnum() HRecNum(Creditor)
//there is a duplicate

Hseek() doesn't read the record so it is much faster than HReadSeek()

Regards
Al

von Al - am 24.09.2012 22:27
Hi Guys,

Thank you very much. The penny has finally dropped

von Clarion Ghost - am 25.09.2012 12:56
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.