Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delete Relation Programmatically
Message
De
30/06/2005 18:09:22
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
 
 
À
30/06/2005 17:32:32
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Database:
Visual FoxPro
Divers
Thread ID:
01027883
Message ID:
01027928
Vues:
14
I didn't start a new thread as it's pretty much related to this one, just a bit more...

I need some code review help. I am trying to use the COPY TO command to copy tables from production to another directory for another application to use them. It's becoming like the Hydra; I fix one error and two more show up. Currently I'm having issues with the REMOVE TABLE command for one table because the relation needs to be deleted. I added code to loop through the tags and drop the foreign key, but I get a message that the table does not belong to a database and then when I choose not to pick one, it dies because it cannot resolve the backlink. I'm really tired of this database-table-link-ownership stuff and need someone to review it. The reason we do not just do a file copy is that tables and index files get out of sync and cause corrupted file problems. I thought this would be simple. It is not. We need to the structure of the database, and the files in the WebExportFiles table (also the CopyFiles cursor) to go to the Destination data directory (gcDefaultPath + '\data\'). You may see a few lines of extra code, it's because I'm still testing and I don't want to remove any of that yet, or it is used later on in other programs. Please help. I will send you something from North Carolina, or if you don't care about that, then chocolates or beer; whichever you prefer. I will be online on-and-off tonight. Thanks!
MB_OK = 0
MB_YESNO = 4
MB_ICONEXCLAMATION = 48
APPNAME_LOC = 0

lRunCopy = .T.

IF lRunCopy

	DELE FILE (gcDefaultPath + '\data\*.*')

	*!* ============================================================================
	*!*	#Defect#:1567	Author: Jay Johengen	Date: 06/28/2005
	*!*
	*!*	Description of changes: Modify the way production data is copied to avoid table corruptions.
	*!* ============================================================================

	COPY FILE (cPlanManagementDir + '\data\PlanMgmt.dbc') TO (gcDefaultPath + '\data\PlanMgmt.dbc')
	COPY FILE (cPlanManagementDir + '\data\PlanMgmt.dct') TO (gcDefaultPath + '\data\PlanMgmt.dct')
	COPY FILE (cPlanManagementDir + '\data\PlanMgmt.dcx') TO (gcDefaultPath + '\data\PlanMgmt.dcx')

	*		CREATE DATABASE (gcDefaultPath + '\data\WebCopyFiles') && Destination
	OPEN DATABASE (gcDefaultPath + '\data\PlanMgmt') && Source

	* REMOVE HARDCODING AFTER TESTING !!!
	*************************************
	USE d:\development\WebCopyFilesTest\WebExportFiles IN 0
	USE d:\development\WebCopyFilesTest\WebExportFiles AGAIN IN 0 ALIAS HoldTable
	*************************************

	SELECT *, .F. AS Copied FROM WebExportFiles INTO CURSOR CopyFiles READWRITE
	SELECT CopyFiles
	REPLACE ALL CopyFiles.FILE WITH ALLTRIM(PROPER(CopyFiles.FILE))

	LOCATE

	SCAN FOR AT('.DBF',UPPER(CopyFiles.FILE)) > 0 AND CopyFiles.Copied = .F. AND UPPER(CopyFiles.File) = 'INSERVICE.DBF'

SET STEP ON 

		FOR i = 1 TO 3
			m.TableError = .F.
			WAIT WINDOW 'Making Database Snapshot. Copying file ' + ALLTRIM(CopyFiles.FILE) NOWAIT
*			TRY
				USE (cPlanManagementDir + '\data\' + CopyFiles.FILE) SHARED IN 0 ALIAS SourceTable
				SELECT SourceTable
				COPY STRUCTURE TO (gcDefaultPath + '\data\' + ALLTRIM(CopyFiles.FILE))
				SET DATABASE TO (gcDefaultPath + '\data\PlanMgmt') && Destination
				IF INDBC(JUSTSTEM((CopyFiles.FILE)),"TABLE")
					FOR nCount = 1 TO 254
					   IF !EMPTY(TAG(nCount))  && Checks for tags in the index
						ALTER TABLE (JUSTSTEM(CopyFiles.FILE)) DROP FOREIGN KEY TAG (CDX(nCount))
					   ELSE
						EXIT  && Exit the loop when no more tags are found
					   ENDIF
					ENDFOR
					REMOVE TABLE JUSTSTEM((CopyFiles.FILE))
				ENDIF
				IF FILE(gcDefaultPath + '\data\' + CopyFiles.FILE)
					DELETE FILE (gcDefaultPath + '\data\' + CopyFiles.FILE)
				ENDIF
				IF FILE(cPlanManagementDir + '\data\' + CopyFiles.FILE)
					m.CopyFor = ALLTRIM(IIF(EMPTY(CopyFiles.ProdCopy), '', 'For ' + WebExportFiles.CopyFor))
					SELECT SourceTable
					COPY TO (gcDefaultPath + '\data\' + ALLTRIM(CopyFiles.FILE)) DATABASE (gcDefaultPath + '\data\PlanMgmt') WITH CDX &CopyFor
					USE (gcDefaultPath + '\data\' + CopyFiles.FILE) EXCLUSIVE IN 0 ALIAS DestinationTable
				ENDIF
			TRY
			CATCH TO oErrors
				m.TableError = .T.
				WAIT '' TIMEOUT 5
			FINALLY
				IF m.TableError = .T. AND i = 3
					IF MESSAGEBOX(;
							'Unable to copy the ' + ALLTRIM(CopyFiles.FILE) + ' table!' + CHR(13) + ;
							'Error message: ' + oErrors.MESSAGE + CHR(13) + CHR(13) + ;
							'Do you want to retry copying this table?' + CHR(13) + ;
							'If No, then Web Export will terminate and must be restarted.', MB_YESNO + MB_ICONEXCLAMATION, APPNAME_LOC) = 6
						i = 1
					ELSE
						CANCEL
					ENDIF
				ENDIF
				USE IN SELECT('DestinationTable')
				USE IN SELECT('SourceTable')
			ENDTRY
			IF m.TableError = .F.
				REPLACE CopyFiles.Copied WITH .T. IN CopyFiles
				EXIT
			ENDIF
		ENDFOR
		SELECT CopyFiles
	ENDSCAN

	* JUST FOR TESTING !!!
	***************************************************************
	BROWSE LAST FOR RIGHT(ALLTRIM(UPPER(CopyFiles.FILE)),3) = 'DBF'
	***************************************************************

	CLOSE DATABASES ALL
ELSE
	USE WebExportFiles
ENDIF

OPEN DATABASE (gcDefaultPath + '\data\PlanMgmt')
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform