Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Algorithm for generating unique value for the 6 char fie
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00503649
Message ID:
00503695
Vues:
30
>>>See SYS(2015) in VFP Help for generating a unique file name. You could set the default value for your ID field to something like Right(Sys(2015), 6)
>>>
>>Yes, I was thinking about it too, but are you sure, it's 100% safe approach?
>
>The only 100% safe approach is to make the default value of your keyid field a function that calls a SP in the DBC. My default value for keyid fields is GetPrimaryKey("TableName"). My SP locates the TableName in the Kounters table. If not there, it adds a record to the Kounters table with that Tablename and an initial count of 0. Then the SP takes the current value in the Kount field, adds 1, replace the Kount field with new value, and returns the integer which becomes the unique value of the keyid field.
>
Yep, this is how it works for other databases too. Unfortunatelly, in Lookups database we didn't use this approach, but rather use Code as PK, where Code is a char field (sometimes 1 char, sometimes 2). Lender/Usage/Towns tables are exceptions, because they have more than 100 records (all others just have few). Yes, it's not clever to depend on user, but I can't change system design right now. So I have to do something for this particular situation. Actually, since all other tables have a blank record now (my manager did it because empty value is allowed for all main tables, so combobox should have an empty value in it - I don't think, it was a very wise decision, but anyway) I now have this problem everythere. Perhaps, I have to discuss it with him first.

>Depending on the user to do the right thing is a recipe for disaster.
>
>>>>Hi everybody,
>>>>
>>>>I have a table, there field Code (Character 6) is made PK. This table contains one blank record (this is by design). Now, each time I'm issuing append blank, I get an Error "Uniqueness of indexes is violated". I'm thinking about adding a default value for this field, but I don't want to use NextID table approach, because this database doen't have a NextID table and I don't want to change it.
>>>>Therefore I'm seeking for the idea of a function, which will generate Unique ID automatically (Char 6).
>>>>
>>>>Or may be you have other ideas? Simple way, which was suggested by my manager, just make this index to be regular and deal this checking on the form level. I disagree, because our data is not secure enough, so if somebody will edit this table directly, there is a chance for adding duplicates.
>>>>
>>>>What do you think? I know, it's not recommended to use character PK (meangful), but this table was designed long time ago and I don't want to change it.
>>>>
>>>>Thanks in advance.
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