Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Primary keys and candidate keys
Message
 
 
À
07/09/2000 09:32:52
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00413219
Message ID:
00413541
Vues:
10
>>Make it a candidate key and do some error trapping because you WILL get an error if you try to update a duplicate value, or trap it logically using a SEEK to look for the value before updating the table and make it any type of key you want.
>
>Just to be clear: You may have to re-open the table with another alias and do the seek() on that. If you've got row bufferning, doing a seek will move the record pointer, try and update the table and if it is a duplicate key you'll get the error message anyways.
>
>Or you can use IndexSeek(), I believe. In either case, if they Return True, you have to check the primary key or record number to make sure the key you found isn't the one you're trying to save.

If you're using buffering, the new appended records would have negative recno().

This is the code, which we use:
********************************************************************
*  Description.......: wgUniqueText.Valid()
*  Calling Samples...:
*  Parameter List....:
*  Created by........:
*  Modified by.......: Nadya Nosonovsky 06/05/2000 12:08:49 PM
********************************************************************
*--- Checks to see if the value entered is unique.
local lcvalue,llunique,lnaction, lcfield, lcAlias, lcTag
llunique = .t.
lcAlias=alias()
if empty(lcAlias)
     lcAlias=thisform.dataenvironment.InitialSelectedAlias
endif
lcTag = this.pcValidTag && Tag Name, used in validation
lcField=this.pcFields && Field Name or combination of fields in validation
lcValue = iif(type("this.value") = "C", alltrim(this.value), this.value) && Store value entered.

*--- Make sure that it is NOT empty.
if empty(this.value)
     lnaction=messagebox('This field can not be blank! Would you like to try again?',20,'Warning')

     if lnaction = 6               && Return user to field.
          llunique = .f.
*--- Do nothing , false will be returned.

     else
*--- The user choose to cancel the edit or add.  Return them to review mode.
          llunique = .t.
          select (lcAlias)
          thisform.edit()
          thisform.navstand.navupdate()
          thisform.refresh()
     endif

endif

if llunique
*--- Check table.
     if thisform.addmode or (not thisform.addmode and oldval(lcfield,lcAlias)<>lcvalue)
*!*               select * from (lcAlias) ;
*!*                    where &lcfield == lcvalue to screen noconsole

*!*     *--- Test results of SELECT-SQL duplicate record check.

*!*               if _tally > 0
*!*                    llunique = .f.
*!*               endif
      if indexseek(lcValue,.f.,lcAlias, lcTag) && Field is duplicate
           llUnique=.f.
      endif     

          if !llunique          &&
               lnaction=messagebox('The value entered is not unique. Would you like to try again?',20,'Duplicate value')

               if lnaction = 6               && Return user to field.
                    llunique = .f.
*--- Do nothing , false will be returned.

               else
*--- The user choose to cancel the edit or add.  Return them to review mode.
                    llunique = .t.
                    select (lcAlias)
                    thisform.edit()
                    thisform.navstand.navupdate()
                    thisform.refresh()
               endif
          endif
     endif
endif
return llunique
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform