Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A NICE message when Primary Key is violated
Message
De
04/05/2001 14:45:00
Walter Meester
HoogkarspelPays-Bas
 
 
À
04/05/2001 05:16:22
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00503380
Message ID:
00503704
Vues:
22
Hi kevin,

>How can I have a different message appear when a Primary Key is violated.

You can do this in two ways:
1. A general error handling routine
2. Use Record (or table) buffering and use TABLEUPDATE(2) in combination with AERROR() to determine if an index uniqueness viloation has ocorred.

Solution 1. is not that practical, because it is lot more difficult to recover from such an error.

Personally I use more or less the following approach:
IF !TABLEUPDATE(2, .T., cAlias)
   =AERROR(aErr1)
   DO CASE 
      CASE aErr1[1,1]=1884 && uniqueness violation
           .... Show a messagebox or resolve it in code

      CASE aErr1[1,1]=1539 AND INLIST(aErr1[1,5],1,2) && insert trigger
           ..... handle it

      CASE aErr1[1,1]=1539 AND aErr1[1,5]=3 AND TYPE("gaerrors[1,9]")="C" && delete trigger
           ..... handle it
    ENDCASE
ENDIF
Of course its better to build it in your framework classes so you can reuse this strategy.

As for all the guys trying to get you to use surrogate keys, please read Message #491025 (and surrounding messages) before you take a decision.

Walter,
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform