Page 1 of 1

Error con funcion ImportFromDBF

PostPosted: Mon Nov 13, 2017 6:42 pm
by Compuin
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 ?

Re: Error con funcion ImportFromDBF

PostPosted: Wed Nov 15, 2017 5:11 pm
by Compuin
Algun advise ?

Re: Error con funcion ImportFromDBF

PostPosted: Sun Nov 19, 2017 3:37 pm
by nageswaragunupudi
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 ] )
 

Re: Error con funcion ImportFromDBF

PostPosted: Sun Nov 19, 2017 4:46 pm
by Compuin
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 )

Re: Error con funcion ImportFromDBF

PostPosted: Sun Nov 19, 2017 5:37 pm
by nageswaragunupudi
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 ] ) )
 

Re: Error con funcion ImportFromDBF

PostPosted: Sun Nov 19, 2017 5:42 pm
by Compuin
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 ?

Re: Error con funcion ImportFromDBF

PostPosted: Sun Nov 19, 2017 5:54 pm
by nageswaragunupudi
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.

Re: Error con funcion ImportFromDBF

PostPosted: Sun Nov 19, 2017 6:13 pm
by Compuin
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

Re: Error con funcion ImportFromDBF

PostPosted: Sun Nov 19, 2017 7:07 pm
by Compuin
Is there a way to export Index files too ?

Re: Error con funcion ImportFromDBF

PostPosted: Sun Dec 03, 2017 12:24 am
by goosfancito
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.

Re: Error con funcion ImportFromDBF

PostPosted: Sun Dec 03, 2017 12:25 am
by Compuin
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