Click here to save this page

** Utility to Rebuild CDX Index Files.



**********************************************************
** Utility to ReBuild CDX index files.
**********************************************************
** Author      : Ramani (Subramanian.G)
**               FoxAcc Software / Winners Software
** Type        : Freeware with reservation to Copyrights
** Warranty    : Nothing implied or explicit
** Last modified : 19 November, 2004
**********************************************************
** Function to rebuild CDX index ... this does....
** First deletes the index and then recreates them
** How to ...
** Save this file as BuildIndex.PRG
**   or add to your library as BuildIndex
** =BuildIndex(myDBF)
*********************************************************
** FUNCTION BuildIndex
PARAMETERS myDBF
IF PARAMETERS() # 1
   RETURN .F.
ENDIF
LOCAL laIndex, cKey, cIndex
USE (myDBF)
DIMENSION laIndex(254,3)

** Load the index name and key names in array
FOR nCount = 1 TO 254
  IF !EMPTY(TAG(nCount))  && Checks for tags in the index
     laIndex(nCount,1) = TAG(nCount) + ' '  &&  tag name
     laIndex(nCount,2) = KEY(nCount) + ' '  &&  Key name
     IF PRIMARY(nCount) && Check Index type
        laIndex(nCount,3) = 'P'    && Primary Index
     ELSE
        IF CANDIDATE(nCount)
           laIndex(nCount,3) = 'C' && Candidate Index
         ELSE
           laIndex(nCount,3) = 'O' && Other Index types
        ENDIF
     ENDIF
  ELSE
     EXIT  && Exit the loop when no more tags are found
  ENDIF
ENDFOR

** Delete the tags
DELETE TAG ALL

** Rebuild Index
FOR nCount = 1 TO 254
  IF !EMPTY(laIndex(nCount,1))
     cIndex = ALLT(laIndex(nCount,1))
     cKey = ALLT(laIndex(nCount,2))
     IF laIndex(nCount,3) = 'P'
        ** Create Primary key type
         ALTER TABLE (myDBF) ADD PRIMARY KEY &ckey ;
              TAG &cindex
     ELSE
        IF laIndex(nCount,3)='C'
           && Candidate index
           INDEX ON &cKey TAG &cIndex candidate
        ELSE
           INDEX ON &cKey TAG &cIndex
        ENDIF
     ENDIF
  ELSE
     EXIT  && Exit the loop when no more tags are found
  ENDIF
ENDFOR
USE
RETURN .T.
*********************************************************
** EOF
*********************************************************


Home       Feedback       DataBase       VisualFoxProFAQ