Page 1 of 1

Migrando de ubna base MariaDB a Otra

Posted: Mon Apr 10, 2023 5:55 pm
by jorge_rivero
Hola Gente, un saludos para todos.
Tengo el siguiente problema:
tengo una base A con la tabla PACIENTES
y otra base B con una tabla PACIENTES
La base A tiene 95 mil registros, y estoy cargando en un array y luego lo migro a la base B, funciona genial, hasta la insercion del registro nro. 27876
y me parece que es por el siguiente problema, que no se como solucionarlo:
El campo apellido que tiene que migrar es: P'CONNOR
Tiene un apostrofe en el apellido, quizas eso es el problema
El error es este:
Error executing Query INSERT INTO
B.pacientes(Codigo,Apellido,Nombre,FechaNac,Activo)
VALUE('27876','P'CONNOR','MARIANA D.D.','1967/02/20',1): You
have an error in your SQL syntax; check the manual that corresponds
to your MariaDB server version for the right syntax to use near
'CONNOR','MARIANA D.D.','1967/02/20',1)' at line 1
la migracion la hago asi:

My_SQL_Connect()
My_SQL_Database_Connect( "A" )
oQuery:=oServer:QUERY("SELECT * FROM hiscli.pacientes")
IF oQuery:NetErr()
MsgInfo("MariaDB SQL SELECT error: " + oQuery:Error())
RELEASE WINDOW ALL
RETURN NIL
ENDIF
Fin := oQuery:LASTREC()
aDatos_origen := ARRAY(Fin,4)
FOR i:=1 TO Fin //27876
oRow := oQuery:GETROW(i)
aDatos_origen[1] := ALLTRIM(oRow:FIELDGET(1)) //Apellido
aDatos_origen[2] := ALLTRIM(oRow:FIELDGET(2)) //Nombre
Nac := oRow:FIELDGET(5) //FechaNac
aDatos_origen[3] := CTOD(RIGHT(Nac,4)+'/'+SUBSTR(Nac,4,2)+'/'+LEFT(NAC,2))
aDatos_origen[4] := oRow:FIELDGET(11) //CodUnico
oQuery:Skip(1)
NEXT
oQuery:Destroy()
My_SQL_Database_Connect( "B" )
FOR i:=1 TO Fin
cDatos1 := aDatos_origen[4]
cDatos2 := aDatos_origen[1]
cDatos3 := aDatos_origen[2]
cDatos4 := DTOC(aDatos_origen[3])
cQuery := "INSERT INTO consultorio.pacientes(Codigo,Apellido,Nombre,FechaNac,Activo) "+;
"VALUES ( '"+STR(cDatos1)+"','"+cDatos2+"','"+cDatos3+"','"+cDatos4+"',1)"
oQuery := oServer:Query( cQuery )
IF oServer:NetErr()
MsgInfo( "Error executing Query "+cQuery+": "+oServer:ERROR() )
EXIT
ENDIF
NEXT
oQuery:Destroy()
QUIT
RETURN NIL
**********

Re: Migrando de ubna base MariaDB a Otra

Posted: Mon Apr 10, 2023 6:09 pm
by dragancesu

Re: Migrando de ubna base MariaDB a Otra

Posted: Mon Apr 10, 2023 6:36 pm
by jorge_rivero
Lei la pagina que enviaste, pero me da error en la sintaxis en la programacion, tendria que definir las variables de otra forma??
por que a leer de la base principal la recibe bien
pero al insertar me da error (la variable que posee:P'CONNOR, me da error
no se como solucionarlo

Re: Migrando de ubna base MariaDB a Otra

Posted: Mon Apr 10, 2023 8:29 pm
by jorge_rivero
Gracias a Todos
Ya lo solucione:
FOR i:=1 TO Fin
cDatos1 := aDatos_origen[4]
cDatos2 := aDatos_origen[1]
cDatos3 := aDatos_origen[2]
cDatos4 := DTOC(aDatos_origen[3])
nx := AT("'",cDatos2)
nz := AT("'",cDatos3)
IF nx>0
cDatos2 := SUBSTR(cDatos2,1,AT("'",cDatos2)-1)+"\'"+;
RIGHT(cDatos2,LEN(cDatos2)-RAT("'",cDatos2)-1)
ENDIF
IF nz>0
cDatos3 := SUBSTR(cDatos3,1,AT("'",cDatos3)-1)+"\'"+;
RIGHT(cDatos3,LEN(cDatos3)-RAT("'",cDatos3)-1)
ENDIF
cQuery := "INSERT INTO consultorio.pacientes(Codigo,Apellido,Nombre,FechaNac,Activo) "+;
"VALUES ( '"+STR(cDatos1)+"','"+cDatos2+"','"+cDatos3+"','"+cDatos4+"',1)"
oQuery := oServer:Query( cQuery )
SETPROPERTY('sino','LB_CONTADOR','Value',++nCounter)
DOMETHOD( 'sino','LB_CONTADOR','Redraw' )
IF oServer:NetErr()
MsgInfo( "Error executing Query "+cQuery+": "+oServer:ERROR() )
EXIT
ENDIF
DO EVENTS
NEXT

Re: Migrando de ubna base MariaDB a Otra

Posted: Mon Apr 10, 2023 9:44 pm
by jorge.posadas
Jorge

Intenta con esto
INSERT INTO TABLA_A
(
NUMERO_PACIENTE
COLUMNA_1
, COLUMNA_2
, COLUMNA_3
::
::
)

SELECT
NUMERO_PACIENTE
COLUMNA_1
, COLUMNA_2
, COLUMNA_3
::

FROM TABLA_B
WHERE NUMERO_PACIENTE NOT IN (SELECT NUMERO_PACIENTE
FROM TABLA_A)

Re: Migrando de ubna base MariaDB a Otra

Posted: Mon Apr 10, 2023 9:53 pm
by jorge.posadas
Jorge

O intenta de esta forma, el REPLACE dejara en un espacio en blanco TODO apostrofe que ecuentre en la columna NOMBRE_PACIENTE de TABLA_B

INSERT INTO TABLA_A
(
NUMERO_PACIENTE
COLUMNA_1
, COLUMNA_2
, COLUMNA_3
, NOMBRE_PACIENTE
::
)

SELECT
NUMERO_PACIENTE
COLUMNA_1
, COLUMNA_2
, COLUMNA_3
, REPLACE(NOMBRE_PACIENTE, 'ยด', ' ')
::

FROM TABLA_B
WHERE NUMERO_PACIENTE NOT IN (SELECT NUMERO_PACIENTE
FROM TABLA_A)