How to Retrieve Records That Were Previously Zapped
ID: Q135905
|
The information in this article applies to:
-
Microsoft Visual FoxPro for Windows, version 3.0
-
Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, 2.5b, 2.6, 2.6a
-
Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a
SUMMARY
Sometimes, FoxPro's ZAP command can be reversed and all the records
retrieved by using low-level file I/O. This method works only if the data
was not overwritten by other files. The approximate number of records to be
retrieved is also important.
MORE INFORMATIONStep-by-Step Example
- Open a program file called Lowlevel.prg and type the following function:
FUNCTION UNZAP
PARAMETER Y
IF Y>0 .AND. USED()
IF RECCOUNT()=0
FILENAME=DBF()
USE
HANDLE=FOPEN(FILENAME,2)
IF HANDLE>0
BYTE=FREAD(HANDLE,32)
BKUP_BYTE=BYTE
FIELD_SIZE=ASC(SUBSTR(BYTE,11,1))+(ASC(SUBSTR(BYTE,12,1))*256)
FILE_SIZE=FSEEK(HANDLE,0,2)
BYTE8=CHR(INT(Y/(256*256*256)))
BYTE7=CHR(INT(Y/(256*256)))
BYTE6=CHR(INT(Y/256))
BYTE5=CHR(MOD(Y,256))
BYTE=SUBSTR(BYTE,1,4)+BYTE5+BYTE6+BYTE7+BYTE8+SUBSTR(BYTE,9)
=FSEEK(HANDLE,0)
=FWRITE(HANDLE,BYTE)
=FCHSIZE(HANDLE,FILE_SIZE+(FIELD_SIZE*Y))
=FCLOSE(HANDLE)
ENDIF
USE &FILENAME
ENDIF
ENDIF
- Save and close Lowlevel.prg.
- Back up the table you are going to experiment on to protect against
corruption.
- Test the function by zapping the back-up of the table and then using
unzap() to retrieve the records. The following example uses the
Foxuser.dbf table:
- In the Command window, type:
SET PROCEDURE TO LOWLEVEL.PRG
SET RESOURCE OFF
USE FOXUSER
- Take note of how many records are in the foxuser file. For this
example, assume there are 50 records.
- In the Command window, type:
ZAP
=UNZAP(50)
- Note that all of the records have been retrieved.
- It is possible to use UNZAP() to retrieve more records than actually
existed, especially if you didn't know how many records to retrieve.
After using UNZAP(), you should browse the table to make sure only valid
records have been retrieved. Invalid records will immediately be
apparent by the incomprehensible data in all the fields. Locate the last
valid record and repeat step 4.c. using the correct number of records.
- If the Foxuser.dbf table is corrupt, delete the file. FoxPro will
recreate a new one.
Additional query words:
VFoxWin FoxWin FoxDos
Keywords :
Version :
Platform :
Issue type :
|