Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Data Conversion code for critical analysis
Message
De
10/02/2003 23:42:10
Larry Long
ProgRes (Programming Resources)
Georgie, États-Unis
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00750090
Message ID:
00751766
Vues:
17
Bhavbhuti,

At first glance I don't see anything wrong. I would, however, add a RECYCLE clause to your DELETE statements just in case you may need to recover the files later.

HTH,
Larry Long

>Hi all,
>
>Can any of you critically analyse this code for me, it is from a method iApplication.DataConversion() called from iApplication.DoPostProcessingHook() of CB62. It does require to be polished but what I want to know about more is it's reliability and any suggestion that any of you may have will be really appreciated. The code follows:
>
>
>*** define local variables
>LOCAL lnFiles, laFiles, lnI, ;
>	lnTables, laTables, lnJ, ;
>	lnExists, laExists, lnK, ;
>	lcOldDeleted, lcOldSafety
>
>DIMENSION laFiles[1], laTables[1], laExists[1]
>
>
>*** look for the stage 1 0 byte flag file
>lnFiles = ADIR(laFiles, "FreshInstallation.flg")
>
>IF lnFiles > 0
>	*** check for tables in Data dir
>	lnFiles = ADIR(laFiles, "Data\*.dbf")
>
>	IF lnFiles > 0
>		*** existing tables means that there may be existing data
>		WAIT WINDOW "Reinstall Detected, Converting Data, Please wait ..." NOWAIT
>
>
>		*** create if required the temporary dir
>		lnFiles = ADIR(laFiles, "Trashcan", "D")
>
>		IF lnFiles = 0
>			MD Trashcan
>		ENDIF
>
>
>		CD Trashcan
>
>
>		*** empty trashcan
>		lnFiles = ADIR(laFiles, "*.*")
>
>		FOR lnI = 1 TO lnFiles
>			DELETE FILE (laFiles[lnI, 1])
>		ENDFOR
>
>
>		*** copy to trashcan the vsodbcx generated prg sets
>		lnFiles = ADIR(laFiles, "..\Data\ReGenDBC*.*")
>
>		FOR lnI = 1 TO lnFiles
>			COPY FILE ("..\Data\" + laFiles[lnI, 1]) TO (laFiles[lnI, 1])
>		ENDFOR
>
>
>		*** execute in trashcan the vsodbcx generated prgs to get a clean copy of the dbcs
>		lnFiles = ADIR(laFiles, "ReGenDBC*.prg")
>
>		= ASORT(laFiles)
>
>		FOR lnI = 1 TO lnFiles
>			DO (laFiles[lnI, 1]) WITH , .T.
>		ENDFOR
>
>
>		lcOldDeleted = SET("DELETED")
>
>		SET DELETED OFF
>
>
>		*** find out the dbcs
>		lnFiles = ADIR(laFiles, "*.dbc")
>
>		FOR lnI = 1 TO lnFiles
>			*** open each dbc
>			OPEN DATABASE (laFiles[lnI, 1]) EXCLUSIVE
>
>
>			*** get all the table names for the dbc
>			lnTables = ADBOBJECTS(laTables, "TABLE")
>
>			FOR lnJ = 1 TO lnTables
>				*** open each table
>				IF USED(laTables[lnJ])
>					SELECT (laTables[lnJ])
>				ELSE
>					USE (laTables[lnJ])
>				ENDIF
>
>
>				*** if exists a same name table in data dir apped data from it
>				lnExists = ADIR(laExists, "..\Data\" + laTables[lnJ] + ".dbf")
>
>				IF lnExists > 0
>					APPEND FROM ("..\Data\" + laTables[lnJ])
>				ENDIF
>
>
>				*** close each table
>				USE
>			ENDFOR
>
>
>			*** close each dbc
>			CLOSE DATABASE
>		ENDFOR
>
>
>		SET DELETED &lcOldDeleted.
>
>
>		CD..
>
>
>		*** create stage 2 flag file
>		= FCLOSE(FCREATE("FreshConversion.flg"))
>	ELSE
>		*** no existing tables means that only the vsodbcx generated prgs are there
>		*** from the installation
>		WAIT WINDOW "Fresh Install Detected, Creating Data, Please wait ..." NOWAIT
>
>
>		*** execute here the vsodbcx generated prgs to get a clean copy of the dbcs
>		CD DATA
>
>		lnFiles = ADIR(laFiles, "ReGenDBC*.prg")
>
>		= ASORT(laFiles)
>
>		FOR lnI = 1 TO lnFiles
>			DO (laFiles[lnI, 1]) WITH , .T.
>		ENDFOR
>
>		CD ..
>
>
>		*** execute here the vsodbcx generated prgs to get a clean copy of the dbcs
>		CD Security
>
>		lnFiles = ADIR(laFiles, "ReGenDBC*.prg")
>
>		= ASORT(laFiles)
>
>		FOR lnI = 1 TO lnFiles
>			DO (laFiles[lnI, 1]) WITH , .T.
>		ENDFOR
>
>		CD..
>	ENDIF
>
>
>	*** clean up
>	CLOSE TABLES ALL
>	CLOSE DATABASES ALL
>
>
>	*** remove the stage 1 flag file
>	DELETE FILE FreshInstallation.flg
>
>
>	WAIT CLEAR
>ENDIF
>
>
>*** look for the stage 2 0 byte flag file
>lnFiles = ADIR(laFiles, "FreshConversion.flg")
>
>IF lnFiles > 0
>	*** data conversion is now complete
>	WAIT WINDOW "Fresh Conversion Detected, Moving Converted Data, Please wait ..." NOWAIT
>
>
>	*** create if required the temporary dir
>	*** this should be here anyways but can't predict better safe the error out
>	lnFiles = ADIR(laFiles, "Trashcan", "D")
>
>	IF lnFiles = 0
>		MD Trashcan
>	ENDIF
>
>
>	CD Trashcan
>
>
>	lcOldSafety = SET("SAFETY")
>
>	SET SAFETY OFF
>
>
>	*** find out each and every file in trashcan
>	lnFiles = ADIR(laFiles, "*.*")
>
>	FOR lnI = 1 TO lnFiles
>		IF laFiles[lnI, 1] # "REGENDBC"
>			*** delete any file which does not belong to vsodbcx generated prg sets
>			*** it seems they are open when they are last run
>			COPY FILE (laFiles[lnI, 1]) TO ("..\Data\" + laFiles[lnI, 1])
>			DELETE FILE (laFiles[lnI, 1])
>		ENDIF
>	ENDFOR
>
>
>	SET SAFETY &lcOldSafety.
>
>
>	CD..
>
>
>	*** remove the stage 2 flag file
>	DELETE FILE FreshConversion.flg
>
>
>	WAIT CLEAR
>ENDIF
>
L.A.Long
ProgRes
lalong1@charter.net
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform