home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TACCESS.ZIP / TACCESS.FIX
Encoding:
Text File  |  1988-03-29  |  3.4 KB  |  73 lines

  1.      The Borland Database Toolbox version 4.00  contains  a  subtle  bug  which
  2. affects  index  file operations in some cases.  Specifically, index files which
  3. allow for duplicate keys  and  use  record  numbers  greater  than  32767  will
  4. suddenly get unexpected results when searching for keys.  Typically, this would
  5. be a result of OK = false when you know the key should exist.
  6.  
  7.      This is caused by a subtle bug in the key comparison routine and has to do
  8. with  saving  a longint result into an integer.  There is another minor problem
  9. with indexes containing record numbers >  MaxLongInt.    Instead  of  returning
  10. duplicate  keys  in  record number order, the existing code will return them in
  11. sequence interpreted as signed numbers.  Normally  this  is  no  problem  since
  12. there  is  no  hard  disk  for  DOS that could possibly hold that many records.
  13. However if you're using the record number field for something else (say  counts
  14. instead  of  record numbers) this could possibly affect you.  The routine below
  15. will fix both problems at once.
  16.  
  17.      To fix the problems, replace the existing TaCompKeys routine in  the  file
  18. TACCESS.PAS  from  your  Database  Toolbox  master disk with the routine below.
  19. It's located about line 1050 in the file.  You then need to rebuild all of  the
  20. TACCESS.TPU  files  for  your  programs  (i.e.  running TABUILD again) and then
  21. recompile your programs themselves.  FURTHER, you should rebuild  all  of  your
  22. index  files  which  allow  for  duplicate  keys.  Since the bug can affect the
  23. AddKey routine, the index files themselves  may  contain  bad  information  and
  24. should  be  recreated from the data files.  I'll grant you that this is a pain,
  25. but do it anyway -- it'll save you headaches later on.
  26.  
  27.      Another comment for those people working with  medium  to  large  indexes.
  28. When  you  are  rerunning the TABUILD program as I described above, use the /W+
  29. option on the command line to enable the worksheet (i.e. use 'TABUILD /W+ PROG'
  30. to  compile  the  TPU  for  PROG).   One of the choices in the worksheet is the
  31. estimated number of records in the database.  This is really the maximum number
  32. of  keys in an index file and defaults to only 1000.  DO NOT UNDERESTIMATE THIS
  33. NUMBER!  It costs you very little to overstate this value and if  you  make  it
  34. too small it can cause bizarre errors to occur at runtime.  This number is used
  35. to calculate the constant MaxHeight and the default is  far  too  small  in  my
  36. opinion.    So  while  you're  fixing the other problem, be sure to adjust this
  37. constant as well.
  38.  
  39.      If you have any trouble with this fix, please leave me a  message  on  the
  40. Borland Compuserve forum for Turbo Pascal (GO BPROGA).
  41.  
  42.                 Scott Bussinger
  43.                 Professional Practice Systems
  44.                 110 South 131st Street
  45.                 Tacoma, WA  98444
  46.                 (206)531-8944
  47.                 Compuserve 72247,2671
  48.  
  49. function TaCompKeys(var K1,
  50.                         K2;
  51.                         DR1,
  52.                         DR2 : LongInt;
  53.                         Dup : Boolean ) : Integer;
  54. begin
  55.   if TaKeyStr(K1) = TaKeyStr(K2)
  56.    then
  57.     if not Dup or (DR1=DR2)
  58.      then
  59.       TaCompKeys := 0
  60.     else
  61.      if (DR1+$80000000) > (DR2+$80000000)
  62.       then
  63.        TaCompKeys := 1
  64.       else
  65.        TaCompKeys := -1
  66.    else
  67.     if TaKeyStr(K1) > TaKeyStr(K2)
  68.      then
  69.       TaCompKeys := 1
  70.      else
  71.       TaCompKeys := -1
  72. end;
  73.