Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FPT Repair
Message
De
09/05/2001 06:45:39
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
09/05/2001 03:22:09
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00505150
Message ID:
00505180
Vues:
22
>I have a table, which is part of a database container, that has a corrupt FPT file. I've tried FPTFIX.PRG, and although it reports that it's fixed the problem, it actually hasn't. When I try to pack/reindex the table, VFP still reports that the file is either missing or corrupt. Any suggestions ??!??!

Derek,
This is not a true repair but easy to apply (backup first!):
-open fpt with an hexeditor.
ie: do home()+'tools\hexedit\hexedit' with 'myfpt.fpt'
-You'll see an address column + columns 0-F
-From VFP command window multiply values at positions 0-3 with 6-7
ie:
if columns 0,1,2,3 on first row had :
00 00 00 EF && Call this lnNextFreeBlock
and columns 6,7 had (most likely as is here-00 40):
00 40 && Call this lnBlockSize

? 0x000000EF * 0x0040
-Read the file size displayed at top (lnFileSize)
-The value you have and size should match
-If they do not match get
? transform(ceiling(lnFileSize/lnBlockSize),'@0') && lnNextFreeBlock
Put this new value to positions 0,1,2,3
-Do above multiplication again and if file size you find is greater than what you read (lnFileSize) open the fpt with fopen(..,12) and set newsize with fchsize()

Now you can open table, select, replace, pack(not sure of pack:)

Below is code version of what I'm saying :
function RepairMemo
* RepairMemo
* Simply fixes next block pointer, blocksize and filesize
Lparameters tcMemoFilename
Local handle, lnFileSize, lnNextBlockPointer, lnBlockSize, lnFirstBlock, lnCalculatedFileSize

handle=fopen(tcMemoFilename,12) && Opened readwrite
lnFileSize = fseek(handle,0,2) && Get file size
With this
  * Read header info
  lnNextBlockPointer = ReadBytes(handle, 0,4,.T.) && Stored in left-to-right format
  lnBlockSize        = ReadBytes(handle, 6,2,.T.) && Stored in left-to-right format

  * Specific to me - no blocksize setting to something other than default 0x40
  If lnBlockSize # 0x40
    WriteBytes(handle, 6,2,0x40,.T.)
    lnBlockSize=0x40
  Endif
  *

  lnFirstBlock	   = ceiling(512/lnBlockSize) && Possible min lnNextblockpointer
  lnCalculatedFileSize = lnNextBlockPointer*lnBlockSize

  * Fix if needs repair
  If !(lnFileSize >= 512 ;
      and lnNextBlockPointer >= lnFirstBlock ;
      and lnCalculatedFileSize >= lnFileSize) && Memo needs repair
    lnNextBlockPointer = max(lnNextBlockPointer, lnFirstBlock)
    lnFileSize = lnNextBlockPointer * lnBlockSize
    WriteBytes(handle, 0,4,lnNextBlockPointer,.T.) && Fix next block pointer
    =fchsize(handle, lnFileSize) && Fix filesize
  Endif
Endwith
=fclose(handle)

Function WriteBytes
Lparameters tnHandle, tnPos, tnSize, tnNumber, tlLR
Local lcString, lnLowDword, lnHighDword,ix
lcString=''
If tlLR
	For ix=tnSize-1 to 0 step -1
		lcString=lcString+chr(tnNumber/256^ix%256)
	Endfor
Else
	For ix=0 to tnSize-1
		lcString=lcString+chr(tnNumber/256^ix%256)
	Endfor
Endif
=fseek(tnHandle, tnPos,0) && Go to pos
Return fwrite(tnHandle,lcString)

Function ReadBytes
Lparameters tnHandle, tnPos, tnSize, tlLR
Local lcString, lnRetValue,ix
=fseek(tnHandle, tnPos,0) && Go to pos
lcString = fread(tnHandle, tnSize) && Read tnSize bytes
lnRetValue = 0
For ix=0 to tnSize-1  && Convert to a number
	lnRetValue = lnRetValue + asc(substr(lcString,ix+1)) * ;
		iif(tlLR,256^(tnSize-1-ix),256^ix)
Endfor
Return int(lnRetValue)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform