Error de harbour al crear tabla Mysql

Error de harbour al crear tabla Mysql

Postby J. Ernesto » Thu Aug 28, 2014 9:04 pm

Foro buenas tardes.

Estoy intentando hacer una rutna para pasar los dbfs a mysql, puedo crear la estructura de la tabla sql a partir de la estructura del dbf, en mysql la tabla se crea, pero harbour inmediatamente me arroja un error enb tiempo de ejecuciòn que no entiendo, el error esta em tdoqry.prg en el metodo loadquery en la linea:

::nRecCount := MySqlNumRows ( ::hResult )

Hasta aqui llego buscando cual es el error

Application Internal Error - D:\fwh_samples\_5\_dbf_2_sql\dbf_to_sql_h.exe
Terminated at: 2014.08.28 14:26:19
Unrecoverable error 6005: Exception error:

Exception Code:C0000005
Exception Address:687DC264
EAX:00000000 EBX:00645634 ECX:00000000 EDX:0283E26C
ESI:00000000 EDI:006357DD EBP:0018C428
CS:EIP:0023:687DC264 SS:ESP:002B:0018C420
DS:002B ES:002B FS:0053 GS:002B
Flags:00210246
CS:EIP: 8B 01 8B 51 04 C2 04 00 CC CC CC CC 8B 44 24 04
SS:ESP: 00504223 00000000 0018C444 004BC204 0000013A 00000035 00000000 00000000 00000000 0018C558 004B63AE 00000001 00634161 00000000 00632964 00645634
...
...

Called from MYSQLNUMROWS(0)
Called from TDOLPHINQRY:LOADQUERY(1245) in .\source\prg\tdolpqry.prg
Called from TDOLPHINQRY:NEW(310) in .\source\prg\tdolpqry.prg
Called from TDOLPHINSRV:QUERY(1867) in .\source\prg\tdolpsrv.prg
Called from CREAR_ESTRUCTURA_SQL(1524) in .\dbf_to_sql.prg
Called from CONVERTIR_DBF_TO_SQL(1418) in .\dbf_to_sql.prg
Called from (b)DBF_TO_SQL(1381) in .\dbf_to_sql.prg
...
...

Probe con habilitar y deshabilitar D_SetCaseSensitive ( .F. ) y .T.

Y este es parte del método en tdolqry.prg donde se produce el error señalado.
* -------------------------------------------------------------------------------------------------------------- *
METHOD LoadQuery ( lBuildData ) CLASS TDolphinQry
Local oServer := ::oServer
Local cQuery := ::cQuery
Local aField, nIdx, cCol
Local lCaseSen := D_SetCaseSensitive ()

DEFAULT lBuildData TO .T.

IF ::bOnLoadQuery != NIL ; EVAL ( ::bOnLoadQuery, Self ); ENDIF
IF ! oServer:SQLQuery ( cQuery ); Return ( NIL ) ; ENDIF
IF lBuildData ; ::BuildDatas () ; ENDIF && we need unlock current record locked

IF ::hResult != NIL
* MySqlFreeResult ( ::hResult ) && NOTE: Deprecated
::hResult = NIL
ENDIF

::hResult := MySqlStoreResult ( oServer:hMysql )
* ::hResult := MySqlUseResult ( oServer:hMysql )

IF ! ( ::hResult == NIL )
::aStructure := MySqlResultStructure ( ::hResult, lCaseSen, D_LogicalValue () )
::nRecCount := MySqlNumRows ( ::hResult ) && Aquí se produce el error
::nRecNo := MAX ( 1, ::nRecNo )
::nFCount := LEN ( ::aStructure )

IF ::nRecCount > 0; ::lEof := .F.; ::lBof := .T.
ELSE ; ::lEof := .T.; ::lBof := .T.
ENDIF

#ifdef USE_HASH
...
...

Esta es la estructura que se crea via còdigo fivewin

CREATE TABLE IF NOT EXISTS bitacora (
jep INTEGER ( 10 ) DEFAULT 0,
CODIGOE VARCHAR ( 6) DEFAULT '.',
CODIGO VARCHAR ( 6) DEFAULT '.',
S_BLOQUEO VARCHAR ( 15) DEFAULT '.',
NOMBRE VARCHAR ( 40) DEFAULT '.',
TERMINAL VARCHAR ( 8) DEFAULT '.',
PROCEDIMIE VARCHAR ( 20) DEFAULT '.',
F_ENTRO DATE DEFAULT '2014-08-24',
H_ENTRO VARCHAR ( 8) DEFAULT '.',
F_SALIO DATE DEFAULT '2014-08-24',
H_SALIO VARCHAR ( 8) DEFAULT '.',
APLICACION VARCHAR ( 20) DEFAULT '.',
CRUCE VARCHAR ( 1) DEFAULT '.',
PRIMARY KEY ( jep ) )
ENGINE = InnoDB;

y Este es parte del còdigo de la rutina aprg que estoy implementanddo
Code: Select all  Expand view

sLinea_1 := "CREATE TABLE IF NOT EXISTS `" + sFile_dbf_sql + "` ( " + CRLF
sLinea_1 += "jep INTEGER ( 10 ) DEFAULT 0"                        + cComa                                         && es un campo índice primary key  

FOR i := 1 TO nCampos_dbf                                                                                         && son los campos que tiene la base de datos dbf
 lOk := .F.
     
 IF oRecord_dbf:fieldtype ( i ) = "C"; sLinea_2 := "VARCHAR ( " + ALLTRIM ( STR ( aEstructura_dbf [ i, 3 ] ) ) + ") DEFAULT '.'"; lOk := .T.; ENDIF
 IF oRecord_dbf:fieldtype ( i ) = "D"; sLinea_2 := "DATE DEFAULT '2014-08-24'"                                                  ; lOk := .T.; ENDIF
     
 IF oRecord_dbf:fieldtype ( i ) = "N"
  lOK := .T.
 
  IF aEstructura_dbf [ I, 4 ] > 0; sLinea_2 := "DECIMAL ( " + ALLTRIM ( STR ( aEstructura_dbf [ i, 3 ] ) ) + "," + ALLTRIM ( STR ( aEstructura_dbf [ i, 4 ] ) ) + " ) DEFAULT 0" && hay decimales
  ELSE                           ; sLinea_2 := "INTEGER ( " + ALLTRIM ( STR ( aEstructura_dbf [ i, 3 ] ) )                                                      + " ) DEFAULT 0"
  ENDIF
 ENDIF
     
 IF oRecord_dbf:fieldtype ( i ) = "L"; sLinea_2 := "VARCHAR (   1 ) DEFAULT ' '"; lOK := .T.; ENDIF               && t / f para sql
 IF oRecord_dbf:fieldtype ( i ) = "M"; sLinea_2 := "VARCHAR ( 500 ) DEFAULT '.'"; lOk := .T.; ENDIF               && ?? dbería ser del tipo BLOB o ????
 
 IF lOk  
  sLinea_1 += oRecord_dbf:fieldname ( i ) + " " + sLinea_2 + cComa
 ENDIF

 oMeter:Set ( i )                                                                                                 && Contador barra meter
 SysRefresh ()    
NEXT i                                                                                                            && Toda la estructura DEL DBF    

sLinea_1 += "PRIMARY KEY ( jep ) ) " + CRLF
sLinea_1 += "ENGINE = " + sMotor && + "; DEFAULT CHARSET = latin1;"

sFile_txt := "_estructura_sql_" + sFile_dbf_sql + ".txt"

IF FILE ( sFile_txt ); ERASE sFile_txt; ENDIF

NDOSNUME := FCREATE ( sFile_txt, 2 )                                                                              && FO_READ := 0, FO_WRITE := 1, READWRITE := 2
FWRITE      ( NDOSNUME, sLinea_1 )
FCLOSE      ( NDOSNUME )

MsgInfo_Voice ( "Creado un archivo txt con la estructura de la tabla " + sFile_dbf_sql, "", "0" )  
MsgInfo ( sLinea_1, "sQuery" )

MsgInfo_Voice ( "Creando la tabla " + sFile_dbf_sql, "", "0" )

IF oQuery := oServer:Query ( sLinea_1 )                                                                           && ! oServer:lError
 MsgInfo_Voice ( "Estructura dbf convertida a sql", "", "0" )

ELSE
       MsgInfo_Voice ( "Error al crear la estructura de la tabla sql", "Crear estructura SQL"                     , "1" )
       MsgInfo       ( hb_dumpvar ( oErr )                           , "Error al intentar la conexión al Servidor" )
       MsgStop ( oErr:Description                                    , "Error de Conexión" ) && ShowError ( oErr )
       Return ( NIL )
ENDIF
 
Return ( .T. )                                                                                                    e
* --------------------------------------------------------------------------------------------------------------- *


Señores, cual puede ser el error que tengo hasta aquì

Saludos
J. Ernesto Pinto Q.
Fivewin 1905 + BCC++ 700 + Harbour 3.20 + LopeEdit 5.8 + UEstudio 26.0
jepsys@hotmail.com, jepsys@gmail.com, jepsys@yahoo.com
User avatar
J. Ernesto
 
Posts: 152
Joined: Tue Feb 03, 2009 10:08 pm
Location: Bogotá D.C. Colombia

Re: Error de harbour al crear tabla Mysql

Postby carlos vargas » Thu Aug 28, 2014 10:26 pm

yo tome esta utilidad que existe en hbmysql de harbour y la he modificado a mi gusto para que use tdolphin en lugar de tmysql.
me ha funcionado bien por meses.
http://castillolawyers.no-ip.info/owncloud/public.php?service=files&t=4bddfdd1f8a8851f5f0aa4eb25b5c393
dentro esta un archivo uptable.cmd el cual utilizo para automatizar un poco la cosa
dbf2mysql -h 192.168.1.10 -u myusuario -p myclave -d MYBASEDEDATOS -t %1 -f %1.dbf -c

aca lo modifican, reemplazando el ip del servidor, el usuario, la contraseña, la base de datos
yo lo uso asi
call uptable.cmd CONTROL

donde TEST es la tabla dbf ( TEST.DBF ), tener cuidado con los nombre mayúsculas y minúsculas en servidores linux.
ya que
call uptable.cmd TEST
es diferente de
call uptable.cmd test
ya que en el primer caso crearia en mysql una tabla llamada TEST y el segundo caso una tabla llamada test.

recordar que la base de datos debe estar creada previamente.
ademas, al final de cada tabla agrego un campo llamado MY_RECNO de tipo entero y autoincremental, lo cual me sirve para identificar cada fila de datos.
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua


Return to FiveWin para Harbour/xHarbour

Who is online

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