DBF to Mysql

DBF to Mysql

Postby jair » Fri May 13, 2022 12:18 pm

¡Buen día!
Tengo tablas dbf de más de una empresa y ahora quiero unirlas todas en una sola tabla en mysql además de crear la tabla donde esta tabla aún no existe en mysql. Otro detalle que no serán todos los campos existentes en la tabla dbf por eso aprovecho para eliminar campos innecesarios. Estoy intentando con el siguiente código:

Code: Select all  Expand view  RUN

#include "fivewin.ch"
#include "dbcombo.ch"
#include "dtpicker.ch"

function main()

local cBaseDir := "C:\fwh\samples\" , cTabela := "customer" , aStruct:={}


oCn   := FW_DemoDB(6)

if !oCn:TableExists( "
test000" )
   
   aStruct:={}
   aadd(  aStruct, {"
FIRST"   , "C", 20,  0})
   aadd(  aStruct, {"
CITY"    , "C", 30,  0})
   aadd(  aStruct, {"
STATE"   , "C",  2,  0})
   aadd(  aStruct, {"
ZIP"     , "D", 10,  0})
   aadd(  aStruct, {"
SALARY"  , "N",  9,  2})
   oCn:CreateTable( "
test000" ,aStruct , .T. )

endif

if oCn:TableExists( "
test000" )
      MsgWait("
Aguarde importando a tabela : "+cTabela, "Aguarde",2 )

      oRec := oCn:RowSet( "
select * from test000 "   )
      oDbf :=TDataBase():Open( nil, cBaseDir+cTabela, "
dbfcdx", .F. )  

      oCn:SetAutoCommit( .f. )
      While !oDbf:Eof()
          oRec:Append()
          oRec:FIRST   := oDbf:FIRST    
          oRec:CITY    := oDbf:CITY    
          oRec:STATE   := oDbf:STATE    
          oRec:ZIP     := oDbf:ZIP      
          oRec:SALARY  := oDbf:SALARY  
          oRec:Save()
          oDbf:Dbskip()
      enddo
      oCn:SetAutoCommit( .t. )
   

endif


xbrowser oCn:test000


oCn:DropTable( "
test000" )

XBROWSER oCn:ListTables TITLE "
SELECT TO VIEW"

return .t.


jair
 
Posts: 57
Joined: Sun Aug 27, 2017 7:18 pm

Re: DBF to Mysql

Postby nageswaragunupudi » Fri May 13, 2022 5:40 pm

If you are appending records from many DBF files into a single table.
You can also try:
Code: Select all  Expand view  RUN
USE CUSTOMER

if oCn:TableExists( "test000" )
   oCn:Insert( "test000", "FIRST,CITY,STATE,ZIP,SALARY", ;
           FW_DbfToArray( "FIRST,CITY,STATE,ZIP,SALARY" ) )
endif
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: DBF to Mysql

Postby nageswaragunupudi » Fri May 13, 2022 5:49 pm

If you are importing one single DBF into one table, you can also try:
Code: Select all  Expand view  RUN
oCn:ImportFromDBF( "customer.dbf", "test000", nil, nil, { ;
   {"FIRST"   , "C", 20,  0} ,'
   {"CITY"    , "C", 30,  0} ,;
   {"STATE"   , "C",  2,  0} ,;
   {"ZIP"     , "D", 10,  0} ,;
   {"SALARY"  , "N",  9,  2}  } )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: DBF to Mysql

Postby jair » Mon Jul 18, 2022 6:20 pm

Mui grato!
jair
 
Posts: 57
Joined: Sun Aug 27, 2017 7:18 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Otto and 39 guests