Page 1 of 1
Insuring uniqueness of index keys
Posted: Thu Jan 26, 2017 1:34 pm
by Cliff Wiernik
We have a file that we add various comments in and log field changes. The index key is generally unique other than some system generate items that occur to fast. Thus, I need to add a fixed ID to the key in order to guarantee uniqueness.
Inquiring as to approaches other have used. I know recently Roger discuss about ADT files and using an autoincrement field. I have some of my own thoughts and am looking for the best way to handle this. As I add records to the DBF field, an additional field would contain this number that would be guaranteed to be unique.
Cliff
Re: Insuring uniqueness of index keys
Posted: Thu Jan 26, 2017 2:11 pm
by rdonnay
You could try: UuidToChar( UuidCreate() )
This will give you a much longer string than 15.
Try this:
Code: Select all
cId := Substr(Strtran(UuidToChar( UuidCreate() ),'-',''),1,15)
Re: Insuring uniqueness of index keys
Posted: Thu Jan 26, 2017 9:06 pm
by Auge_Ohr
i use external DBF as Counter which User have to access EXCLUSIVE.
Code: Select all
// just Dummy Code
FUNCTION New_Number(cDBF)
LOCAL nNumber := -1
DO WHILE nNumber > -10
IF Net_Use(cDBF,; // DBF Name
.T.,; // EXCLUSIVE !!!
"Counter" ) // ALIAS
nNumber := Decode(Counter->Number)
nNumber++
Counter->Number := Encode(nNumber)
SLEEP(1)
CLOSE Counter
EXIT
ENDIF
SLEEP(100)
nNumber--
ENDDO
RETURN nNumber // fail if nNumber < 0
Re: Insuring uniqueness of index keys
Posted: Thu Jan 26, 2017 9:23 pm
by Cliff Wiernik
What does the encode and decode functions do?
Isn't there alot of overhead with the file open/close exclusive requirements.
Re: Insuring uniqueness of index keys
Posted: Thu Jan 26, 2017 9:44 pm
by Auge_Ohr
Cliff Wiernik wrote:What does the encode and decode functions do?
nothing special ... just be sure User do not manipulate it.
Cliff Wiernik wrote:Isn't there alot of overhead with the file open/close exclusive requirements.
i do not care about overhead if it is secure.
i still do same technique with SQL in a separate field and also having a autoincrement field to compare.