0% found this document useful (0 votes)
528 views2 pages

VFP to MySQL Data Upload Script

This document provides instructions to upload data from a Visual FoxPro database to a MySQL database. It opens the VFP database, gets a list of tables, then loops through each table selecting all records, inserting them into the MySQL version of the table, and updating the cursor. It uses Paul McNett's makeupdatable function to make the cursors updatable for the remote MySQL database.

Uploaded by

Chadwick Elliott
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
528 views2 pages

VFP to MySQL Data Upload Script

This document provides instructions to upload data from a Visual FoxPro database to a MySQL database. It opens the VFP database, gets a list of tables, then loops through each table selecting all records, inserting them into the MySQL version of the table, and updating the cursor. It uses Paul McNett's makeupdatable function to make the cursors updatable for the remote MySQL database.

Uploaded by

Chadwick Elliott
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

* Program: VFP2MySQL_Data_Upload.prg * Author: Michael J.

Babcock, MCP * Date: 08-25-08 * Purpose: To upload the VFP data to the MySQL database. * Preconds: You might have to make sure the PK fields are NOT set to autoinc rement when this is run. Double-check that. * Comments: If you make any mods/improvements, please update the ProFox down loads page so we all benefit. Cheers! LOCAL liHandle as Integer, lcConnection as String, lcDBC as String, lcSQL as Str ing, lcTable as String, loRec as String, ; llSuccess as Logical, lcMsg as String LOCAL ARRAY laTables[1], laError[1] CLOSE DATABASES ALL SQLDISCONNECT(0) lcConnection = [DRIVER={MySQL ODBC 3.51 Driver};SERVER=your-server-here;UID=root ;PWD=password;DATABASE=yourdb;option=131609] lcDBC = [c:\yourdatapath\[Link]] SET PROCEDURE TO [Link] && this is Paul McNett's jewel for easily mak ing cursors updatable for remote dbms liHandle = SQLSTRINGCONNECT(lcConnection) IF liHandle > 0 THEN OPEN DATABASE (lcDBC) NOUPDATE ADBOBJECTS(laTables,"TABLE") FOR EACH lcTable IN laTables WAIT WINDOW NOWAIT "Copying " + lcTable USE (lcTable) IN 0 ALIAS VFPData lcSQL = [select * from ] + lcTable + [ where 1=0] IF SQLEXEC(liHandle,lcSQL,lcTable) = 1 THEN && got the cursor... now make it updatable IF makeupdatable(lcTable) THEN * Now cycle through the vfp data and insert into MySQL recordset SELECT VFPData SCAN WAIT WINDOW NOWAIT "Copying " + lcTable + " (" + TRANSFORM(RECNO()) + " of " + TRANSFORM(RECCOUNT()) + ")" SCATTER MEMO NAME loRec INSERT INTO (lcTable) FROM NAME loRec ENDSCAN * Now update the cursor llSuccess = TABLEUPDATE(2,.T.,lcTable) IF NOT llSuccess THEN AERROR(laError) lcMsg = laError(2) SET STEP on MESSAGEBOX("Unable to save changes to " + lcTable + CHR(13) + CHR(13) + TRANSFORM(lcMsg),16,"Problem") ENDIF ENDIF ELSE MESSAGEBOX("Problem getting cursor " + lcTable,16,"Probl em") ENDIF * close table/cursor USE IN (SELECT("VFPData"))

USE IN (SELECT(lcTable)) ENDFOR ELSE MESSAGEBOX("Problem getting handle",16,"Problem") ENDIF && liHandle > 0

You might also like