Converting Visual Fox DBF to SQL

13
Converting Visual Fox DBF to SQL Tags: Visual Fox, DBF, SQL, MySQL, Converter Guide

description

Converting Visual Fox DBF to SQL. Tags: Visual Fox, DBF, SQL, MySQL, Converter Guide. What this is about:. Slides here will show you how to convert Visual Fox DBF database file into MySQL Knowledge required: PHP, MySQL - PowerPoint PPT Presentation

Transcript of Converting Visual Fox DBF to SQL

Page 1: Converting Visual Fox DBF to SQL

Converting Visual Fox DBF to SQL

Tags: Visual Fox, DBF, SQL, MySQL, Converter

Guide

Page 2: Converting Visual Fox DBF to SQL

What this is about:

• Slides here will show you how to convert Visual Fox DBF database file into MySQL

• Knowledge required: PHP, MySQL• There are commercial (and may be free) tools

available, so my solution works fine for me and maybe you will be able to find right application

• Script designed is universal (It automatically crease right table structure).

• Software and products used are free and highly common

Page 3: Converting Visual Fox DBF to SQL

Limitations

• Please, extra check for your requirements. For example, I do not know about existence of calculated and what is more important pre-defined values in Visual Fox, so my script simply copy row by row without any clever mine inside

• It’s better to create table structure yourself rather than rely on automatic creation (thought it is convenient when you do not care about space and you need to convert a lot of files)

• Please, feel free to use presentation/code but without any warranties.

Page 4: Converting Visual Fox DBF to SQL

My system

• I run this script as a web page (Apache + MySQL + PHP)

• Database that I used has Cyrillic encoding, so “iconv” converted to UTF-8

• My system is Windows 7 (this is important, as under Linux you will need another PHP libraries).

Page 5: Converting Visual Fox DBF to SQL

Why SQL

• Fast• SQL Language (creating complex select queries

with parameters, functions, etc.)• Especially for my task: Possibility to perform

fast joins as raw database that I investigate had structure unknown to me and I need to make filters/joins/multiple selects to test my assumptions.

Page 7: Converting Visual Fox DBF to SQL

dBase

• Luckily the tool to read dbf files is build into PHP - http://www.php.net/manual/en/intro.dbase.php

• But before usage you need to install it.

Page 8: Converting Visual Fox DBF to SQL

Warning about DBF usage

• There is no support for indexes or memo fields. There is no support for locking, too. Two concurrent web server processes modifying the same dBase file will very likely ruin your database.

• We recommend that you do not use dBase files as your production database. Choose any real SQL server instead; » MySQL or » Postgres are common choices with PHP. dBase support is here to allow you to import and export data to and from your web database, because the file format is commonly understood by Windows spreadsheets and organizers.

Page 9: Converting Visual Fox DBF to SQL

Installation

• To run dbase function, you need to add line extension=php_dbase.dllto your php.ini and restart apache. • But it’s common (was my case and I saw similar problems

at forums) that your system has not required php_dbase.dllIn this case you can

– Recompile your PHP and reinstall it. This is recommended (http://www.php.net/manual/en/dbase.installation.php)

– Or download required library already compiled. (http://downloads.php.net/pierre/). It’s fast, but be careful with your PHP version and type (Thread safe vs. Non Thread Save)

Page 10: Converting Visual Fox DBF to SQL

Script algorithm

• Open DBF database and get table structure• Create dynamic query to create table• Connect to MySQL server• Run query to Create table• Open DBF rows– For each row: Do inserting into MySQL

Page 11: Converting Visual Fox DBF to SQL

Script problems

• When auto table creation is used, I add 20 bytes to the length of each column and declare them as varchar. If you need, you can write function that will distinguish INT, DATE, etc. with right column length.

• I do not handle possible errors

Page 12: Converting Visual Fox DBF to SQL

Script benefits

• Auto table creation• Handling empty columns. I faced that number

of columns in row can be less that needed, as some are regarded as empty or pre-set.

• It’s free and easy to work with

Page 13: Converting Visual Fox DBF to SQL

Finish

• Code and this presentation is available • http://tigrantsat.me/randd/dbftomysql/

• Thank you.