eliminating key violation problems 
Author Message
 eliminating key violation problems

I'm trying to write some code so that when a key violation
occurs the current record causing the violation in the
table frame gets eliminated.
I'm not having much success.

I've tried placing some code in the tableframes status method.
method status(var eventinfo statusevent)

if eventinfo.isprefilter() then
if eventinfo.reason()=statuswindow then
if eventinfo.statusvalue()="Key violation." then
action(datadeleterecord)
endif

else
endif
endif

I also tried placing code in the tableframes error method
if errorcode()=9729 then
errorclear()
deleterecord()
endif

Interactively I know i just press ctrl+del, but I'd like some
code to take care of it automatically.

Any help would be appreciated.
Thanks!



Thu, 23 Jul 1998 03:00:00 GMT
 eliminating key violation problems

Quote:

>I'm trying to write some code so that when a key violation
>occurs the current record causing the violation in the
>table frame gets eliminated.
>I'm not having much success.
[snip]
>I've tried placing some code in the tableframes status method.
>method status(var eventinfo statusevent)
>if eventinfo.isprefilter() then
>if eventinfo.reason()=statuswindow then
>if eventinfo.statusvalue()="Key violation." then
>action(datadeleterecord)
>endif
>else
>endif
>endif
>I also tried placing code in the tableframes error method
>if errorcode()=9729 then
>errorclear()
>deleterecord()
>endif
>Interactively I know i just press ctrl+del, but I'd like some
>code to take care of it automatically.
>Any help would be appreciated.
>Thanks!

If Paradox cannot successfully post a record because of a key
violation, you can hard - code to trap the error (you have, sort of),
and then undo the record using Action(dataCancelRecord):

if eventInfo.errorCode() = 9729 then
        msgInfo("Key Violation Error", "Cannot post changes.  Cancelling.")
        Active.Action(DataCancelRecord)
endIf

hope this helps.

=====================
James A. Hargreaves
HB & Associates Inc.
P.O. Box 1103
Antigonish, NS CANADA
B2G 2S3
=====================
902-863-2685
=====================



Thu, 23 Jul 1998 03:00:00 GMT
 eliminating key violation problems
Quote:

>I'm trying to write some code so that when a key violation
>occurs the current record causing the violation in the
>table frame gets eliminated.
>I'm not having much success.

>I've tried placing some code in the tableframes status method.
>method status(var eventinfo statusevent)

>if eventinfo.isprefilter() then
>if eventinfo.reason()=statuswindow then
>if eventinfo.statusvalue()="Key violation." then
>action(datadeleterecord)
>endif

>else
>endif
>endif

>I also tried placing code in the tableframes error method
>if errorcode()=9729 then
>errorclear()
>deleterecord()
>endif

>Interactively I know i just press ctrl+del, but I'd like some
>code to take care of it automatically.

>Any help would be appreciated.
>Thanks!

This shouldnt be too bad to accomplish. In the error method of the TableFrame, you can put a
statement sort of like this:

Method Error(Var EventInfo ErrorEvent)

   if errorHasErrorCode(PeKeyViol) then
     action(DataCancelRecord)  
   EndIf

EndMethod

This Works really slick and fast. You may want to ask the user to change the key though, they
may get upset if they have to type a bunch of stuff in then you throw it out.
Let me know how it works....

Dwight Furleigh Cat Ag Products



Fri, 24 Jul 1998 03:00:00 GMT
 eliminating key violation problems

writes:

Quote:
>   I think the place you want to put the code is in the action()
>method of the TableFrame:

>   method action( var eventInfo ActionEvent )
>    switch
>      case eventInfo.id() = DataPostRecord or
>           eventInfo.id() = DataUnlockRecord :

>           dodefault  ; go ahead and try
>           if eventInfo.errorCode() = peKeyViol then
>                self.cancelEdit()
>                errorClear()
>           endif
>    endswitch

>DataPostRecord and DataUnlockRecord are the only actions
>that try to commit your changes to the underlying table
>(as far as I have been able to see).  It is where I do
>lots of my validity checking.

    This is similar to what I do, except I take it a step further.  I
first let them know what happened (by using a dialog box.) I then use a
t-cursor to qlocate() the existing record they were trying to enter.
Just a simple suggestion!  


Fri, 24 Jul 1998 03:00:00 GMT
 eliminating key violation problems
Quote:

> I'm trying to write some code so that when a key violation
> occurs the current record causing the violation in the
> table frame gets eliminated.
> I'm not having much success.

> I've tried placing some code in the tableframes status method.
> method status(var eventinfo statusevent)

> if eventinfo.isprefilter() then
> if eventinfo.reason()=statuswindow then
> if eventinfo.statusvalue()="Key violation." then
> action(datadeleterecord)
> endif

> else
> endif
> endif

> I also tried placing code in the tableframes error method
> if errorcode()=9729 then
> errorclear()
> deleterecord()
> endif

> Interactively I know i just press ctrl+del, but I'd like some
> code to take care of it automatically.

   I think the place you want to put the code is in the action()
method of the TableFrame:

   method action( var eventInfo ActionEvent )
    switch
      case eventInfo.id() = DataPostRecord or
           eventInfo.id() = DataUnlockRecord :

           dodefault  ; go ahead and try
           if eventInfo.errorCode() = peKeyViol then
                self.cancelEdit()
                errorClear()
           endif
    endswitch

DataPostRecord and DataUnlockRecord are the only actions
that try to commit your changes to the underlying table
(as far as I have been able to see).  It is where I do
lots of my validity checking.

--

Coupled Climate Dynamics Group/971            
NASA Goddard Space Flight Center              
Greenbelt, MD 20771



Fri, 24 Jul 1998 03:00:00 GMT
 eliminating key violation problems

: if eventInfo.errorCode() = 9729 then
:       msgInfo("Key Violation Error", "Cannot post changes.  Cancelling.")
:       Active.Action(DataCancelRecord)
: endIf

It's a real bad idea to use numeral values in place of constants.  From
release to release, numeric values for actions can change.  If you use
the constant, you'll be guaranteed forward compatibility.

Ie, in the next version of Paradox, what if 9729 is the Import dialog box
menu constant??

Andrew
--
Andrew Bennett



Tue, 28 Jul 1998 03:00:00 GMT
 
 [ 6 post ] 

 Relevant Pages 

1. INSERT INTO TABLE KEYED ONLY ON IDENTITY COLUMN RESULTS IN KEY VIOLATION (6.5)

2. Violation of PRIMARY KEY constraint Cannot insert duplicate key in object

3. Paradox Key Violation - changing a keyed field

4. Preventing Key Violation for duplicate keys

5. Reordering of key fields leads to key violations (Pdox 5.0)

6. Reordering of key fields leads to key violations (Pdox 5.0)

7. Unique key violation problem

8. Primary Key Contraint violation problem

9. Problem in incremental field and when it happens key violation

10. Problem in incremental field and when it happens key violation

11. Violation of PRIMARY KEY problem


 
Powered by phpBB® Forum Software