Konversi DBF ( tabel visual foxpro ) to MySql

Untuk mengkonversikan tabel DBF ( tabel visual foxpro ) ke Tabel MySql dapat dilakukan dengan source code di bawah ini :

NamaTabelDbf=ALLTRIM(thisform.text1.Value)
USE (NamaTabelDbf) ALIAS AliasTabel SHARED
NamaTabelMysql=RIGHT(NamaTabelDbf,LEN(NamaTabelDbf)-RAT(“\”,NamaTabeldbf))
NamaTabelMysql=LEFT(NamaTabelMysql,AT(“.”,NamaTabelMySql)-1)
JumFieldSumber=AFIELDS(FieldSumber,”AliasTabel”)
DIMENSION TypeSumber(JumFieldSumber)
MySqlCreate=”CREATE TABLE “+NamaTabelMysql+”(”
**********Konversi Tipe Data DBF ke MySQL*********************
FOR i=1 TO JumFieldSumber
LebarField=ALLTRIM(STR(fsize(FIELD(i))))
FieldSumber(i)=LOWER(FIELD(i))
DO CASE
CASE TYPE(FIELD(i))=”N” && Numeric
TypeSumber(i)=”INT(“+LebarField+”)”
CASE TYPE(FIELD(i))=”C” && Character
TypeSumber(i)=”VARCHAR(“+LebarField+”)”
CASE TYPE(FIELD(i))=”D” && Date
TypeSumber(i)=”DATE”
CASE TYPE(FIELD(i))=”L” && Logical
TypeSumber(i)=”CHAR (1)”
OTHERWISE
MESSAGEBOX(“Maaf…tipe data tidak kompatibel hanya tipe N,C,D,L”)
RETURN
ENDCASE
MySqlCreate=MysqlCreate+FieldSumber(i)+” “+TypeSumber(i)+” NOT NULL,”
ENDFOR
MySqlCreate=LEFT(MySqlCreate,LEN(MySqlCreate)-1)+”)”
StatusExec=SQLEXEC(KoneksiMySql,(MySqlCreate))
IF StatusExec <0
MESSAGEBOX(“Eksekusi Script Create Table ada kesalahan”)
RETURN
ENDIF
JumRekAlias=RECCOUNT(“AliasTabel”) && Hitung Jumlah Rekord DBF Sumber
DO WHILE ! EOF(“AliasTabel”)
MySQLInsert=”INSERT INTO “+NamaTabelMysql+”(”
**************************Membuat Perintah “INSERT INTO nama_tabel(Field1..FieldN)”
FOR j=1 TO JumFieldSumber
MySQLInsert=MySQLInsert+FieldSumber(j)+”,”
ENDFOR
MySqlInsert=LEFT(MySqlInsert,LEN(MySqlInsert)-1)+”) VALUES(”
FOR j=1 TO JumFieldSumber
IsiFieldDbf=&FieldSumber(j)
DO CASE
CASE VARTYPE(IsiFieldDbf)=”N”
IsiFieldDbf=ALLTRIM(STR(IsiFieldDbf))
CASE VARTYPE(IsiFieldDbf)=”C”
IsiFieldDbf=IsiFieldDbf
CASE VARTYPE(IsiFieldDbf)=”D”
IsiFieldDbf=TRANSFORM(DTOS(IsiFieldDbf),”;@r 9999-99-99″)
CASE VARTYPE(IsiFieldDbf)=”L”
IsiFieldDBF=IIF(IsiFieldDbf=.F.,”F”,”T”)
OTHERWISE
MESSAGEBOX(“Maaf…tipe data tidak kompatibel hanya tipe N,C,D,L”)
CLOSE DATABASES
RETURN
ENDCASE
MySQLInsert=MySQLInsert+'”‘+IsiFieldDbf+'”‘+”,”
ENDFOR
MySqlInsert=LEFT(MySqlInsert,LEN(MySqlInsert)-1)+”)”
thisform.edit1.Value=mysqlinsert
StatusExec=SQLEXEC(KoneksiMysql,(MySqlInsert)) && Eksekusi Perintah MySQL
IF StatusExec <0
MESSAGEBOX(“Eksekusi Script Insert ada kesalahan”)
CLOSE DATABASES
RETURN
ENDIF
SKIP IN (“AliasTabel”)
****************Progress Bar ********************************************
thisform.xpprogressbar1.curval=ROUND(recno(“AliasTabel”)/JumRekAlias,2)*100
ThisForm.lblpersen.caption=ALLTRIM(STR(ROUND(recno;
(“AliasTabel”)/JumRekAlias,2)*100))+”%”
ENDDO
CLOSE DATABASES

http://www.erlangga.net/forum/viewtopic.php?t=8&sid=5c5f23721a08fddd584520ddc31f1be2

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s