*!* This rebuilds the Indexes based on the IndexMetaData table. LPARAMETER tlDeleteIndex LOCAL lcOldSafety, lcCDXName, lcTableName, lcOldCollate, lcOldError, lcNoError lcError = .F. lcOldError = ON([Error]) ON ERROR lcError = .T. *!* Close the databases CLOSE DATABASE ALL *!* Try and open it exclusivley OPEN DATABASE (This.DBC_Name) EXCLUSIVE *!* If You couldn't open it return .F. IF lcError RETURN .F. ENDIF *!* Check for the Matadata Table for rebuilding IF !FILE([IndexMetaData.DBF]) =MESSAGEBOX([Não consigo reindexar os ficheiros , por favor contacte a Elaconta], 16, [Erro ao Indexar]) RETURN .F. ENDIF *!* Begin Rebuild process lcOldSafety = SET([Safety]) SET SAFETY OFF lcOldCollate = SET([Collate]) SELECT Table_Name DISTINCT FROM IndexMetaData WHERE !EMPTY(Table_Name) INTO CURSOR TableList SELECT TableList && Table To Scan *!* Check for CDX File and Delete them. SCAN SELECT 0 USE (ALLT(TableList.Table_Name)) EXCL && Open the Table DELETE TAG ALL && Delete the Tags USE IN (ALLT(TableList.Table_Name)) && Close the Tables ENDSCAN *!* Close the temp table. USE IN TableList *!* Reselect the index table and begin rebuilding the indexes SELECT IndexMetaData GO TOP IN IndexMetaData lcTableName = [] SCAN *!* If the table name has changed then clise the old one and open the new one IF lcTableName # ALLT(IndexMetaData.Table_name) *!* make sure the table is open before closing it IF USED(lcTableName) USE IN (lcTableName) ENDIF *!* Open the new table USE (ALLT(IndexMetaData.Table_name)) IN 0 EXCLUSIVE WAIT WINDOW NOWAIT NOCLEAR [A reconstruir os indices para : ]+ALLT(IndexMetaData.Table_name) ENDIF *!* Store the last table used before going to the next on *!* to test to see if its open. lcTableName = ALLT(IndexMetaData.Table_name) *!* Store the Info to variables lcTagStructure = ALLT(IndexMetaData.Index_Tag) lcTagName = ALLT(IndexMetaData.Index_Name) lcFilter = ALLT(IndexMetaData.Tag_Filter) lcCollate = ALLT(IndexMetaData.Collate) llAscending = IIF(IndexMetaData.Ascending,"ASCENDING", "DESCENDING") lcType = ALLT(IndexMetaData.Index_Type) lcIndexType = [] *!* Needed to build string DO CASE CASE lcType = [U] lcIndexType = [UNIQUE] CASE lcType = [C] lcIndexType = [CANDIDATE] ENDCASE *!* Select the table to index SELECT (lcTableName) *!* Set The Collate SET COLLATE TO lcCollate *!* Build the Index string IF [-] $ lcTagName =MESSAGEBOX([Invalid "Minus" Character In Tag Name.]+CHR(13)+ ; [Index Skipped You Will Need To Create It Manually], 64, [Reindexer Warning]) ELSE *!* Note for Users with Large Tags... WAIT WINDOW NOWAIT NOCLEAR [Rebuilding Tag ]+lcTagName+[ For Table ]+lcTableName *!* Added the ability for a Filter in the Primary Key. IF lcType = [P] && Primary Keys are diffrent IF EMPTY(lcFilter) ALTER TABLE &lcTableName ADD PRIMARY KEY &lcTagStructure TAG &lcTagName ELSE ALTER TABLE &lcTableName ADD PRIMARY KEY &lcTagStructure FOR &lcFilter TAG &lcTagName ENDIF ELSE *!* Build String for all other Indexes lcIndexCommand = [INDEX ON ]+lcTagStructure+[ TAG ]+lcTagName lcIndexCommand = lcIndexCommand + IIF(EMPTY(lcFilter), [], [ FOR ]+lcFilter) lcIndexCommand = lcIndexCommand + [ ] + llAscending lcIndexCommand = lcIndexCommand + [ ] + lcIndexType *!* Execute the String to build the index &lcIndexCommand ENDIF ENDIF SELECT IndexMetaData ENDSCAN *!* Close The Last Table opened IF USED(lcTableName) USE IN (lcTableName) ENDIF This.ReBuild_Relations() IF USED([IndexMetaData]) USE IN IndexMetaData ENDIF SET COLLATE TO lcOldCollate SET SAFETY &lcOldSafety ON ERROR &lcOldError WAIT CLEAR RETURN !lcError