home *** CD-ROM | disk | FTP | other *** search
- The Borland Database Toolbox version 4.00 contains a subtle bug which
- affects index file operations in some cases. Specifically, index files which
- allow for duplicate keys and use record numbers greater than 32767 will
- suddenly get unexpected results when searching for keys. Typically, this would
- be a result of OK = false when you know the key should exist.
-
- This is caused by a subtle bug in the key comparison routine and has to do
- with saving a longint result into an integer. There is another minor problem
- with indexes containing record numbers > MaxLongInt. Instead of returning
- duplicate keys in record number order, the existing code will return them in
- sequence interpreted as signed numbers. Normally this is no problem since
- there is no hard disk for DOS that could possibly hold that many records.
- However if you're using the record number field for something else (say counts
- instead of record numbers) this could possibly affect you. The routine below
- will fix both problems at once.
-
- To fix the problems, replace the existing TaCompKeys routine in the file
- TACCESS.PAS from your Database Toolbox master disk with the routine below.
- It's located about line 1050 in the file. You then need to rebuild all of the
- TACCESS.TPU files for your programs (i.e. running TABUILD again) and then
- recompile your programs themselves. FURTHER, you should rebuild all of your
- index files which allow for duplicate keys. Since the bug can affect the
- AddKey routine, the index files themselves may contain bad information and
- should be recreated from the data files. I'll grant you that this is a pain,
- but do it anyway -- it'll save you headaches later on.
-
- Another comment for those people working with medium to large indexes.
- When you are rerunning the TABUILD program as I described above, use the /W+
- option on the command line to enable the worksheet (i.e. use 'TABUILD /W+ PROG'
- to compile the TPU for PROG). One of the choices in the worksheet is the
- estimated number of records in the database. This is really the maximum number
- of keys in an index file and defaults to only 1000. DO NOT UNDERESTIMATE THIS
- NUMBER! It costs you very little to overstate this value and if you make it
- too small it can cause bizarre errors to occur at runtime. This number is used
- to calculate the constant MaxHeight and the default is far too small in my
- opinion. So while you're fixing the other problem, be sure to adjust this
- constant as well.
-
- If you have any trouble with this fix, please leave me a message on the
- Borland Compuserve forum for Turbo Pascal (GO BPROGA).
-
- Scott Bussinger
- Professional Practice Systems
- 110 South 131st Street
- Tacoma, WA 98444
- (206)531-8944
- Compuserve 72247,2671
-
- function TaCompKeys(var K1,
- K2;
- DR1,
- DR2 : LongInt;
- Dup : Boolean ) : Integer;
- begin
- if TaKeyStr(K1) = TaKeyStr(K2)
- then
- if not Dup or (DR1=DR2)
- then
- TaCompKeys := 0
- else
- if (DR1+$80000000) > (DR2+$80000000)
- then
- TaCompKeys := 1
- else
- TaCompKeys := -1
- else
- if TaKeyStr(K1) > TaKeyStr(K2)
- then
- TaCompKeys := 1
- else
- TaCompKeys := -1
- end;