Unique index key

This forum is for eXpress++ general support.
Post Reply
Message
Author
skiman
Posts: 1199
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Unique index key

#1 Post by skiman »

Hi,

This new thread for the following i saw.

Brian wrote:
Do you use some form of str(recno(),10) in everyone of your indexes to insure unique index keys ?
Roger answered with :
This is an important point.
I2Bin(RecNo()) also works.
I have several index files with a non-unique key. I never had problems with it.
Example: in my sales file I have an index on month(date). This way the calculation of monthly totals is easy and fast, in my agenda if have an index with startdate, and so on. I never had problems with this. I could add an extra key to create unique indexes. Would this be necessary? Could the use of index files without unique keys influence index files where the index key is always unique?

Secondly a question about the I2Bin(recno()) as extra key? What about files with more than 32767 records. Does this generate an unique key with I2Bin?
Best regards,

Chris.
www.aboservice.be

User avatar
Tom
Posts: 1234
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Unique index key

#2 Post by Tom »

Besides, if you struggle with unique numbers and references: Take a look at "UuidCreate()" and "UuidToChar()". UuidCreate() creates an - world-wide - unique identifier, UuidToChar() translates this binary to a character string (lenght 36). This is inside Xbase++ since 1.9 SL1. I added a field "UUID" to all my tables which need unique identifieres; "APPEND BLANK" is translated using the preprocessor and looks if this field exists. If so, the unique identifier is replaced. This removed ALL problems I ever had with numbers and cross-table-references. It's not useful if numbering must be strictly incremental or if the numbers can be used by the users (like for invoice numbers or customer IDs). But in all other situations, like for table relations, it's just perfect. Even merging tables from different datasources isn't a problem anymore, since the UUIDs are unique in all situations.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

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

Re: Unique index key

#3 Post by rdonnay »

What about files with more than 32767 records. Does this generate an unique key with I2Bin?
Actually, yes it would be unique provided that the primary expression does not exceed 32k records.

For example, INDEX ON CUSTNMBR+I2Bin(Recno()) would be unique for the first 32k records with the same custnmbr.
If it is likely that a database would have more than 32k of the same custnmbr, then Tom's solution would be more appropriate.
The eXpress train is coming - and it has more cars.

bwolfsohn
Posts: 649
Joined: Thu Jan 28, 2010 7:07 am
Location: Alachua, Florida USA
Contact:

Re: Unique index key

#4 Post by bwolfsohn »

but if all you're doing is trying to generate a unique index key, str(recno()) will ALWAYS be unique.. what are the advantages of l2bin as opposed to str(recno())
Brian Wolfsohn
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises

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

Re: Unique index key

#5 Post by rdonnay »

I was told that it is faster when creating the indexes. I believe I got that information from Steffen.
The eXpress train is coming - and it has more cars.

Post Reply