Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to recover corrupted VFP table
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Divers
Thread ID:
00936240
Message ID:
00936252
Vues:
23
>Hi All
>Due to power shutdown one VFP7 table has been corrupted. I am unable to open it. I got the message 'Table has become corrupted and needs to be repaired before using it again.'
>The table size is 14,832 KB. Is there any simple way to repair it or any free utility.?
>Thanks in advance
>Zaheer

Zaheer,

Look in the download section, I think there's a couple of them.

Another thing to try is, if your table has memo fields (after a backup/copy of your table) is to repair the FPT. I think Viv Philips tested this once
usage : = FPT_Fix('C:\project\data\TableName.fpt')
*---------------------------------------------------------------------------
#include	"FoxPro.h"
#IFNDEF	TRUE
	#define	TRUE	.T.
	#define	FALSE	.F.

	#define	MAX_INTEGER	(0x7fffffff)
#endif

&& see http://www.e-bachmann.dk/computing/databases/xbase/fpt.html#FPT_STRUCT
function FPT_Fix(FileName)
	
	local fd, FileSize, BlockLen, NextBlock, hdrOnDisk, hdr
	
	fd = fopen(FileName, F_READWRITE_UNBUFF)
	
	do case
	case fd < 0
		wait window 'cannot open ' + FileName
		return FALSE
		
	otherwise
		FileSize = fseek(fd, 0, 2)
		=fseek(fd, 6, 0)
		BlockLen = fread(fd,2)
		BlockLen = CharToBinBE(BlockLen)
		=fseek(fd, 0, 0)
		hdrOnDisk = fread(fd, 4)
	
		NextBlock = ceiling(FileSize / BlockLen)
		hdr = BinToCharBE(NextBlock)
		
		do case
		case hdrOnDisk == hdr
			&& all ok
		
		otherwise
			assert FALSE message 'about to repair'
		 	=fseek(fd, 0, 0)
		 	=fwrite(fd, hdr)
		 endcase
	
		=fclose(fd)
	endcase
	
endfunc
*---------------------------------------------------------------------------
function CharToBinBE(s)	&& BigEndian
	local n
	n = ctobin(s)
	
	return n + iif(n<=0, 256^len(s)/2, -(256^len(s)/2))
endfunc
*---------------------------------------------------------------------------
function BinToCharBE(n, nBytes)	&& BigEndian

	nBytes = iif(empty(nBytes), 4, nBytes)
	
	return bintoc(n + iif(n<=0, 256^nBytes/2, -(256^nBytes/2)), nBytes)
	
endfunc
*---------------------------------------------------------------------------	
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform