How to Retrieve Records That Were Previously Zapped

Last reviewed: August 30, 1995
Article 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 INFORMATION

Step-by-Step Example

  1. 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
    
    

  2. Save and close Lowlevel.prg.

  3. Back up the table you are going to experiment on to protect against corruption.

  4. 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:

    a. In the Command window, type:

          SET PROCEDURE TO LOWLEVEL.PRG
          SET RESOURCE OFF
          USE FOXUSER
    

    b. Take note of how many records are in the foxuser file. For this

          example, assume there are 50 records.
    

    c. In the Command window, type:

          ZAP
          =UNZAP(50)
    

    d. Note that all of the records have been retrieved.

  5. 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.

  6. If the Foxuser.dbf table is corrupt, delete the file. FoxPro will recreate a new one.


Additional reference words: 2.00 2.50 2.50a 2.50b 2.60 2.60a 3.00 VFoxWin
FoxWin FoxDos
KBCategory: kbprg kbcode
KBSubcategory: FxprgTable


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 30, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.