Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Form - changing the controls source property
Message
 
To
18/10/1997 08:14:49
George Alexander
Qatar Armed Forces
Doha, Qatar
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00054836
Message ID:
00055313
Views:
33
>Thank you very much for such a fabulous reply. It is a pleasure to have the help of an expert to a novice. I
>am always using Optimistic Table buffering. But the problem is I want to check the user entered primary key
>to be validated before the user leaves the field and before updation to the table. If I include the validation
>routine with the table buffering I get some violation errors which I dont know how to control. That is why I am
>forced to stick to the updation of the records from the memory variables.
>
>thanks very much
>
>alex

Alex,

Ok, so here's a real curve for you. Stop using primary keys that the suer enters. Insted assign the primary key programatically as an integer. This is called a surrogate key. The benefits are many, the user doesn't enter it so you can insure that it is always unique, the user doesn't know it exists so they will never want to change its value, it is meaningless so you never care what value it gets. Among others.

You can still have the fields the user wants to use to find records, but once you get the record the user asked for, your program grabs the surrogate key field's value and uses that to do everything else.

There are many problems with the way you are trying to do this now. For one, even you did check the uniquesness of the value in the control's valid event, there is no guaranttee that the value will still be unique when you commit the record to disk *some other user may have gotten in there with that value in the meantime.

When using surrogate keys you can create a table in your system that has two fields in it;

SysKeys.dbf
Table Name C
NextID I

Then you write a short program like this;

* NextId.Prg
LPARAMETERS pcTable
IF NOT USED("SysKeys")
SELECT 0
USE SysKeys ALIAS SysKeys AGAIN
ELSE
SELECT SysKeys
ENDIF
SET ORDER TO TableName
SEEK UPPER(pcTable)
DO WHILE NOT FLOCK()
ENDDO
IF FOUND()
liKey = NextID
REPLACE NextId WITH NextID + 1
ELSE
APPEND BLANK
REPLACE NextId WITH 1
liKey = 0
ENDIF
UNLOCK
RETURN liKey

Now in your dbc for every table's primary key field you put this as the Default Value;

NextID("TheTablesName")

Now NEVER supply a value for the primary key, the dbc will do that for you when you TableUpdate a new record.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform