//**************************************************************************** // $Module type: Package // $Module name: Reindex.pkg // $Author : Nils G. Svedmyr // Created : 2001-08-05 @ 09:18 // // Description : To reindex all DATAFLEX files in filelist.cfg // // $Rev History: // 2001-08-05 Module header created // 2007-04-04 Changed to usage of CMVdf12StatPnl.pkg to support new // logic of VDF 12. //**************************************************************************** //Use StatPnl.pkg Use CMVdf12StatPnl.pkg Use Func.pkg Use Working.pkg Use SyncFuncs.pkg //**************************************************************************** // $Module type: CLASS // $Module name: cReindex // $Author : Nils G. Svedmyr // Created : 2001-09-14 @ 12:38 // // Description : // // $Rev History // 2001-09-14 Module header created //**************************************************************************** Class cReindex is a DFObject Procedure Construct_Object Forward Send Construct_Object Property Integer piCheckFile 0 Property Handle phoStatPnl 0 Property String psSentinelName "RDCSentinel" Property Boolean pbAllowCancelState True Set_Attribute DF_RUNTIME_PROGRESS_FREQUENCY to 1 // Once for every new record. Used by Callback function. End_Procedure // Construct_Object Procedure End_Construct_Object Forward Send End_Construct_Object Send DoCheckToolFiles End_Procedure // End_Construct_Object Function IsTableIndexError Returns Boolean Integer iFile iRecords iCount iFoundCount Boolean bOk bOpen Get piCheckFile to iFile Get_Attribute DF_FILE_OPENED of iFile to bOpen If Not bOpen Open iFile Get_Attribute DF_FILE_RECORDS_USED of iFile to iRecords Clear iFile Repeat vFind iFile 0 gt If (Found) Increment iFoundCount Increment iCount Until (iCount > iRecords) Close iFile Function_Return (iRecords = iFoundCount) End_Function // IsTableIndexError Procedure DoCheckToolFiles Integer iRetval String sText Boolean bOk Get IsTableIndexError to bOk If bOk Procedure_Return Move "Index errors found in data tables. They need to be reindexed. This is probably because a different collating sequence is being used." to sText Get YesNo_Box (sText * " Reindex tables now?") to iRetval If (iRetval = MBR_No) Begin Move "Reindex process of tables cancelled by user." to sText Send Info_Box (sText * "Program will be aborted.") Abort End // If (iRetval = MBR_No) Begin Get ReindexFiles (Self) to sText // Proc in Reindex.pkg. ho=CallbackObject Returns: String with status text. Send Info_Box sText Procedure_Return End_Procedure // DoCheckToolFiles //*** Procedure: ReIndexFiles //*** Purpose : Re-index all files in the current filelist (current workspace). //*** Arguments: Callback Object id //*** Returns : String with status text Function ReindexFiles Handle hoCallBack Returns String Handle hStatpan Boolean bBadExists bSysfile Integer iFileNum iNumFiles iNumFilesAdjusted iErrFiles iRetval iVdfVer String sRootName sSortString sReadyMsg sDriver sProgramPath sSentinel //*** Start the status panel Move (Status_panel(Self)) to hStatpan Set phoStatPnl to hStatpan If hStatpan Begin //*** Setup sentinel // Get VdfMajorRev to iVdfVer Get psProgramPath of (phoWorkspace(ghoApplication)) to sProgramPath Get psSentinelName to sSentinel Get Get_File_Exists (sProgrampath + "\" + sSentinel + ".Exe") to iRetval If Not iRetval Begin Send Info_Box ("The sentinel program" * sProgrampath + "\" + sSentinel + ".Exe is missing. Program will be terminated.") Abort End // If Not iRetval Begin Set Allow_Cancel_State of hStatpan to (pbAllowCancelState(Self)) Set Sentinel_name of hStatpan to sSentinel Send Initialize_StatusPanel of hStatpan "Reindexing tables" "Searching Filelist.cfg" "" Send Start_StatusPanel of hStatpan End Repeat //*** get next used file number Get_Attribute DF_FILE_NEXT_USED of iFilenum to iFilenum If iFilenum Begin //*** Count the file Increment iNumFiles Open iFilenum //*** Skip Flexerrs Get_Attribute DF_FILE_ROOT_NAME of iFilenum to sRootname //*** Skip other driver's than DataFlex Get_Attribute DF_FILE_DRIVER of iFilenum to sDriver //*** Skip system files Get_Attribute DF_FILE_IS_SYSTEM_FILE of iFilenum to bSysfile If (Uppercase(Trim(sRootName)) <> "FLEXERRS" and Uppercase(sDriver) = FLEX_DRV_ID and Not(bSysFile)) Begin //*** Show file If hStatpan Set Message_Text of hStatpan to ("Re-indexing table" * sRootName) Close iFileNum //*** Open the file exclusively. Open iFileNum Mode DF_EXCLUSIVE If (Found) Begin // Then file is open in exclusive mode. Get IndexString iFileNum to sSortString // Function of this package. If (sSortString <> "") Begin Increment iNumFilesAdjusted //*** Check for bad and remove if exists Get Get_file_exists (sRootName + ".BAD") to bBadExists // Function of this package. If bBadExists Erasefile (Find_file(sRootName + ".BAD")) //*** Re-index all indexes of the file Sort iFileNum sSortString (DF_SORT_OPTION_BAD_DATA_FILE iOr DF_SORT_OPTION_DUP_DATA_FILE) hoCallBack Close iFileNum //*** Check for bad, if it exists something went wrong Get Get_file_exists (sRootName + ".BAD") to bBadExists If bBadExists Increment iErrFiles End // If (sSortString <> "") Begin End // If (Found) Begin End // If (Uppercase(Trim(sRootName)) <> "FLEXERRS") Begin Else If hStatpan Set Message_Text of hStatpan to ("Skip" * sRootName) End // If iFilenum Begin Until (iFileNum = 0) //*** Stop progress messages If hStatpan Send Stop_StatusPanel to hStatpan //*** Return string that the process is ready // -1 = don't count Flexerrs file. Move (String(iNumFilesAdjusted) * "DataFlex data tables re-indexed out of" * String(iNumFiles -1)) to sReadyMsg If iErrFiles ; Move (Append(sReadyMsg, ("\nBad or duplicate data was detected in" * String(iErrFiles) * "tables. Check the .bad files for details."))) to sReadyMsg Function_Return sReadyMsg End_Function // ReindexFiles //*** //*** Function: IndexString //*** Purpose : Detemine the available indexes of a file. //*** //*** Arguments: //*** Integer iFileNum - The number of the file //*** //*** Returns: //*** String - The string to be used in the sort command if you want //*** to re-index all indexes of the file //*** Function IndexString Integer iFileNum Returns String String sSortString Integer iLastIndex Integer iNumSegments Integer iCount Move "" to sSortString Get_Attribute DF_FILE_LAST_INDEX_NUMBER of iFileNum to iLastIndex For iCount From 1 to iLastIndex Get_Attribute DF_INDEX_NUMBER_SEGMENTS of iFileNum iCount to iNumSegments If iNumSegments Begin If (Length(sSortString)) ; Move (Append(sSortString, " ")) to sSortString Move (Append(sSortString, iCount)) to sSortString End Loop Function_Return sSortString End_Function // IndexString //*** Function: Callback //*** Purpose : Callback faciltiy enabler. Pass the information to the status //*** panel. Function Callback String sCallbackMsg Integer iCallbackType Returns Integer Number nReady nTotal nPerc If (iCallbackType <> DF_MESSAGE_PROGRESS_VALUE) ; Send Update_StatusPanel of (phoStatPnl(Self)) sCallbackMsg Else Begin //*** Interpret numbers Move (Left(sCallbackMsg, (Pos(",", sCallbackMsg) - 1))) to nReady Move (Right(sCallBackMsg, (Length(sCallbackMsg) - Pos(",", sCallbackMsg)))) to nTotal Move ((nReady/nTotal) * 100) to nPerc Send Update_StatusPanel of (phoStatPnl(Self)) ("__PROGRESS__" + String(Integer(nPerc))) Set Action_Text of (phoStatPnl(Self)) to ("Reindexing" * String(nReady) * "of" * String(nTotal)) End Function_Return (False) End_Function // Callback End_Class // cReindex