Question

I've been tasked with converting FoxPro databases to MySQL and I need to know how to export the structure/indexes of a FoxPro database to Excel. Is this possible to export that type of information from FoxPro?

I know there are tools out there that do this kind of conversion for you but that has been rejected due to our budget. We were hoping to create a specialized conversion script that will automatically convert all our containers and dbfs.

Thank you in advance.

Was it helpful?

Solution

If you look at the download area at Leafe.com there are various free tools to migrate data from VFP into MySQL.

There is a data upload program, and a couple of tools to create MySQL CREATE TABLE scripts from the currently selected alias in Visual FoxPro.

Alternatively if you want to pursue the Excel route manually then ...

If you have a table MYTABLE.DBF with the following structure:

Structure for table:          C:\TEMP\MYTABLE.DBF
Number of data records:       0       
Date of last update:          01/05/2014
Code Page:                    1252    
 Field  Field Name            Type                        Width      Dec    Index   Collate     Nulls       Next       Step
     1  FIRSTNAME             Character                      20                                    No
     2  LASTNAME              Character                      20                                    No
     3  AGE                   Numeric                         3                                    No
     4  ID                    Integer (AutoInc)               4               Asc   Machine        No          1          1
** Total **                                                  48

Then you can dump the structure to another DBF via the VFP Command Window like this:

cd \temp
use mytable
copy structure extended to mytablestruct.dbf

You can then open the table that contains structure info and dump it to XLS format:

use mytablestruct
copy to struct.xls type xl5

In Excel that will look like:

enter image description here

With regard to indexes you would have to code a small routine like this:

    Create Cursor indexinfo (idxname C(254), idxtype c(254), idxkey c(254), ;
        idxfilter c(254), idxorder c(254), idxcoll c(254))
    Use mytable In 0
    Select mytable
    lnTags = ATagInfo(laTemp)
    For i = 1 to lnTags
        Insert into indexinfo values (laTemp[i, 1], laTemp[i, 2], laTemp[i, 3], laTemp[i, 4], laTemp[i, 5], laTemp[i, 6])
    EndFor
    Select indexinfo
    Copy To indexinfo.xls type xl5

Opening the resultant indexinfo.xls:

enter image description here

OTHER TIPS

You can do it from FoxPro, and there is no need to export the info to Excel, Foxpro is capabale of recreating your databases/tables/indexes in MySQL, and upload the records.

I have developed a tool that can upload any FoxPro table to MySQL, just using FoxPro commands.

Check gendbc.prg in the tools folder and adapt it to your needs.

You will have to do some field type conversions for MySQL. Also if you are going to upload your data, there are some caveats with dates/datetimes:

Replace empty VFP date fields with '0000-00-00' in MySQL, and '0000-00-00 00:00:00' for empty datetimes.

Some useful commands are AFIELDS, ATAGINFO

All good points... Additionally with VFP, you can do with the menu at "Tools" --> "Wizards" --> "Upsizing". You will need to make a connection to the database and it will walk you through most of the stuff.

You can upsize an entire database, or just individual tables during the wizard process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top