Insuring uniqueness of index keys

This forum is for eXpress++ general support.
Post Reply
Message
Author
Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Insuring uniqueness of index keys

#1 Post 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

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Insuring uniqueness of index keys

#2 Post 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)
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1428
Joined: Wed Feb 24, 2010 3:44 pm

Re: Insuring uniqueness of index keys

#3 Post 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
Last edited by Auge_Ohr on Thu Jan 26, 2017 9:45 pm, edited 1 time in total.
greetings by OHR
Jimmy

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: Insuring uniqueness of index keys

#4 Post by Cliff Wiernik »

What does the encode and decode functions do?

Isn't there alot of overhead with the file open/close exclusive requirements.

User avatar
Auge_Ohr
Posts: 1428
Joined: Wed Feb 24, 2010 3:44 pm

Re: Insuring uniqueness of index keys

#5 Post 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.
greetings by OHR
Jimmy

Post Reply