Error con funcion ImportFromDBF

Error con funcion ImportFromDBF

Postby Compuin » Mon Nov 13, 2017 6:42 pm

Hola foro

Tengo un error al tratar de usar la ImportFromDBF....estoy usando las dbf del directorio samples con este codigo. Puse las tablas en un array

Code: Select all  Expand view
#include "FiveWin.ch"

//----------------------------------------------------------------//

   REQUEST DBFCDX

   function Main()
   local cHost      := "localhost"
   local cUser      := "root"
   local cPassword  := "1234"
   local oCn,nSecs, uRet, cTable, aTables
   local cDb        := "fwh"

   ? "Connect to Server"
   FWCONNECT oCn HOST cHost USER cUser PASSWORD cPassword
       if oCn == nil
        ? "Connect Fail"
    return nil
        else
    endif
   
   if oCn != nil

      ? "Selecting database " + cDB, "Create if new"
      if Empty( oCn:ListDbs( cDb ) )
         oCn:CreateDB( cDb, "latin1" )
      endif
      oCn:SelectDB( cDB )
      ? "Connected to " + oCn:CurrentDB()
     
      aTables := HB_dirScan( ".\", "*.dbf", "A" )

     XBrowse( aTables )

      for each cTable in  aTables //{ "
customer.dbf", "states.dbf" }
         if ! oCn:TableExists( cFileNoExt( cTable ) )
            ? "
Importing " + cTable
            nSecs := Seconds()
            uRet := oCn:ImportFromDBF( cTable )

            nSecs := Seconds() - nSecs
            ? uret
            ? "
Imported in ", nSecs, "Seconds"
         endif
      next

   endif
   
       ? "
IMPORTACION FINALIZADA"
           
       oCn:Close()

    return nil
    //----------------------------------------------------------------//



Aca el error

Application
===========
Path and name: C:\fwh\samples\mysql01.exe (32 bits)
Size: 3,906,560 bytes
Compiler version: Harbour 3.2.0dev (r1603082110)
FiveWin version: FWH 17.01
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows version: 6.1, Build 7601 Service Pack 1

Time from start: 0 hours 0 mins 3 secs
Error occurred at: 11/13/17, 13:37:16
Error description: Error BASE/1108 Argument error: AT
Args:
[ 1] = C :
[ 2] = A { ... } length: 5

Stack Calls
===========
Called from: => AT( 0 )
Called from: .\source\function\FILENAME.PRG => CFILENOPATH( 48 )
Called from: .\source\function\FILENAME.PRG => CFILENOEXT( 68 )


Algun advise ?
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Error con funcion ImportFromDBF

Postby Compuin » Wed Nov 15, 2017 5:11 pm

Algun advise ?
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Error con funcion ImportFromDBF

Postby nageswaragunupudi » Sun Nov 19, 2017 3:37 pm

Please see your code
Code: Select all  Expand view
          uRet := oCn:ImportFromDBF( cTable )
 

Here cTable is not dbf name, it is an array
Modify this line as:
Code: Select all  Expand view
          uRet := oCn:ImportFromDBF( cTable[ 1 ] )
 
Regards

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

Re: Error con funcion ImportFromDBF

Postby Compuin » Sun Nov 19, 2017 4:46 pm

nageswaragunupudi wrote:Please see your code
Code: Select all  Expand view
          uRet := oCn:ImportFromDBF( cTable )
 

Here cTable is not dbf name, it is an array
Modify this line as:
Code: Select all  Expand view
          uRet := oCn:ImportFromDBF( cTable[ 1 ] )
 


With the change before....the error persist

Application
===========
Path and name: C:\fwh\samples\export.exe (32 bits)
Size: 3,975,168 bytes
Compiler version: Harbour 3.2.0dev (r1705200225)
FiveWin version: FWH 17.05
C compiler version: Borland/Embarcadero C++ 7.3 (32-bit)
Windows version: 6.1, Build 7601 Service Pack 1

Time from start: 0 hours 0 mins 7 secs
Error occurred at: 11/19/17, 11:45:48
Error description: Error BASE/1108 Argument error: AT
Args:
[ 1] = C :
[ 2] = A { ... } length: 5

Stack Calls
===========
Called from: => AT( 0 )
Called from: .\source\function\FILENAME.PRG => CFILENOPATH( 48 )
Called from: .\source\function\FILENAME.PRG => CFILENOEXT( 68 )
Called from: export.prg => MAIN( 36 )
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Error con funcion ImportFromDBF

Postby nageswaragunupudi » Sun Nov 19, 2017 5:37 pm

Modify this line also
Code: Select all  Expand view
      if ! oCn:TableExists( cFileNoExt( cTable ) )
 

as
Code: Select all  Expand view
      if ! oCn:TableExists( cFileNoExt( cTable[ 1 ] ) )
 
Regards

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

Re: Error con funcion ImportFromDBF

Postby Compuin » Sun Nov 19, 2017 5:42 pm

nageswaragunupudi wrote:Modify this line also
Code: Select all  Expand view
      if ! oCn:TableExists( cFileNoExt( cTable ) )
 

as
Code: Select all  Expand view
      if ! oCn:TableExists( cFileNoExt( cTable[ 1 ] ) )
 


Hello,

It's work like this

Code: Select all  Expand view
      if ! oCn:TableExists( cFileNoExt( cTable[ 1 ] ) )
         ? "Importing " + cTable[ 1 ]


But it is adding me a ID field in the imported table which I don't want it

Image

How could avoid this ?
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Error con funcion ImportFromDBF

Postby nageswaragunupudi » Sun Nov 19, 2017 5:54 pm

ImportFromDBF( cDbfName, nil, nil, nil, nil, .F. ) // 5th param .F. suppresses creation of AutoInc field ID

BUT
In that case you will be creating all tables in MySql without PrimaryKey and that is VERY DANGEROUS.
Regards

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

Re: Error con funcion ImportFromDBF

Postby Compuin » Sun Nov 19, 2017 6:13 pm

nageswaragunupudi wrote:ImportFromDBF( cDbfName, nil, nil, nil, nil, .F. ) // 5th param .F. suppresses creation of AutoInc field ID

BUT
In that case you will be creating all tables in MySql without PrimaryKey and that is VERY DANGEROUS.


Thanks a lot
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Error con funcion ImportFromDBF

Postby Compuin » Sun Nov 19, 2017 7:07 pm

Is there a way to export Index files too ?
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Error con funcion ImportFromDBF

Postby goosfancito » Sun Dec 03, 2017 12:24 am

creo, a mi parecer, que estan en SET DBF y tienen que estar en SET MYSQL.

Yo lo que haria seria exportar de DBF a TXT separando con punto y coma los valores de los campos
y luego hacer una rutina, analizada antes, y comenzar a "crear" en mysql.
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: Error con funcion ImportFromDBF

Postby Compuin » Sun Dec 03, 2017 12:25 am

goosfancito wrote:creo, a mi parecer, que estan en SET DBF y tienen que estar en SET MYSQL.

Yo lo que haria seria exportar de DBF a TXT separando con punto y coma los valores de los campos
y luego hacer una rutina, analizada antes, y comenzar a "crear" en mysql.



Muchas gracias
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 12 guests