Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Corrupted Tables
Message
De
08/05/2007 08:23:06
 
 
À
08/05/2007 08:05:37
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 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01223322
Message ID:
01223329
Vues:
23
This message has been marked as the solution to the initial question of the thread.
>I'm sure everyone has an answer for this, but I am looking for the FREE fix to this problem.
>
>I have some tables, as we all do, that are now corrupted and I really need to recover them.....any suggestions???

I wrote this program a long time ago (1993) but it does work with VFP 9 tables when you have corrupted header data. Good luck!
***********************************************************
*  Program Name:  FIXRECNT.PRG
*        Author:  Tom Bellmer
*       Purpose:  Write correct RECCOUNT() value to header
* Last Modified:  08/11/1993
*         Usage:  DO fixrecnt WITH <dbf name> OR
*                 =fixrecnt(<dbf name>)
*       Returns:  nothing
***********************************************************

PARAMETERS lcfname
PRIVATE ALL LIKE l*


  *-- Open the file with unbuffered read/write access
lnhandle = FOPEN(lcfname,12)	

  *-- Test for possible file opening error
IF lnhandle  = -1	 
	WAIT WINDOW "Error: "+STR(FERROR(),2)
	RETURN
ENDIF

  *-- Read the first 12 characters of the header
lchdrinfo  =FREAD(lnhandle,12)  

  *-- Calculate the header length 
lnhdrsize  = INT(ASC(SUBSTR(lchdrinfo,09,01))         + ;
                 ASC(SUBSTR(lchdrinfo,10,01)) * 256)
  *-- Calculate the record length
lnreclngth = INT(ASC(SUBSTR(lchdrinfo,11,01))         + ;
			     ASC(SUBSTR(lchdrinfo,12,01)) * 256)

  *-- lafsize[2] contains the file size in bytes
=ADIR(lafsize,lcfname)			
  *-- Calculate the number of records
lnreccnt   = INT((lafsize[2] - lnhdrsize) / lnreclngth)

lcfirst8   = LEFT(lchdrinfo,4) + SPACE(4)
FOR lni = 3 TO 0 STEP -1
      *-- Replace characters from left to right starting
      *-- at 8 and going to 5 (RECCOUNT() area)
	lcfirst8 = STUFF(lcfirst8,lni+5,1, ;
	           CHR(INT(lnreccnt / 256^lni)))
	  *-- Perform modulus division and use the remainder
	  *-- as the remaining record count in the next pass
	  *-- of the FOR ... NEXT loop.
	lnreccnt = lnreccnt % 256^lni
NEXT

  *-- Go to top of the file.
=FSEEK(lnhandle,0,0)
  *-- Write 1st 8 positions back to the header record.
=FWRITE(lnhandle,m.lcfirst8)
  *-- Close the file
=FCLOSE(lnhandle)
RETURN

* EOF fixrecnt.prg
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform