Hola de nuevo, estoy haciendo mis primeras practicas, conectandome a mysql y hasta ahora si he podido realizar la conexion. Pero quisiera saber como se maneja el retorno, por ejemplo el codigo '001' si existe y deseo llenar los cuadros de texto de un formulario. Pero si no existe preguntar si desea ingresarlo como nuevo. El codigo siguiente no da problema pero no se, como trabajar el objeto oQuery en los dos casos expuestos, que devuelve. Gracias por todo y saludos.
cCodigo=pro_aaa.txtcodigo.value
oQuery:=oServer:Query("SELECT * FROM proveedor WHERE CODIGO ='&cCodigo'")
If oQuery:NetErr()
Msginfo("Error en la consulta: "+oQuery:Error())
Release Window ALL
Quit
Endif
Como se maneja el retorno de la clase TMySQLServer()
Moderator: Rathinagiri
Re: Como se maneja el retorno de la clase TMySQLServer()
Byrpa yo lo manejo asi
fQuery:= oServer:Query( "Select nombre,direccion1,rfc,codigo From Cliente WHERE clave = " + str(altacuentasg.text_5.value) )
If fQuery:NetErr()
MsgStop(fQuery:Error())
return
endif
if fQuery:LastRec() = 0 ** si existe me regresa 1 o la cantidad de "registros" en la consulta
MsgInfo('El cliente no existe','Mensaje del Sistema')
altacuentasg.text_5.setfocus
return
endif
Saludos, espero que te sea de ayuda
fQuery:= oServer:Query( "Select nombre,direccion1,rfc,codigo From Cliente WHERE clave = " + str(altacuentasg.text_5.value) )
If fQuery:NetErr()
MsgStop(fQuery:Error())
return
endif
if fQuery:LastRec() = 0 ** si existe me regresa 1 o la cantidad de "registros" en la consulta
MsgInfo('El cliente no existe','Mensaje del Sistema')
altacuentasg.text_5.setfocus
return
endif
Saludos, espero que te sea de ayuda
Re: Como se maneja el retorno de la clase TMySQLServer()
Muchas gracias por tu ayuda. Una última, ¿si existe como saco el registro 1 del oQuery, para pasarlo a las variables?
Re: Como se maneja el retorno de la clase TMySQLServer()
Byrpa espero te sirva este pequeño ejemplo, estoy pasando un sistemas de dbf a mysql, asi que si puedo ayudarte con mucho gusto
bQuery:= oServer:Query( "Select clave,nombre,direccion1,ciudad,codigo,estado,rfc,telefono1,telefono2,fax,respon,email,honor_imp,minimo_imp,honor_exp,minimo_exp,complemento,franjaa,no_int,no_ext,pais From Cliente where clave = " + aValue[1] )
If bQuery:NetErr()
MsgStop ( bQuery:Error() )
Return
Endif
if bQuery:LastRec() > 0
oRow := bQuery:GetRow(1)
mcve:=alltrim(str(oRow:fieldGet("clave")))
altacliente.text_1.value:=oRow:fieldGet("clave")
altacliente.text_2.value:=oRow:fieldGet("nombre")
altacliente.text_3.value:=oRow:fieldGet("direccion1")
altacliente.text_4.value:=oRow:fieldGet("ciudad")
altacliente.text_5.value:=oRow:fieldGet("codigo")
altacliente.text_6.value:=oRow:fieldGet("rfc")
altacliente.text_7.value:=oRow:fieldGet("telefono1")
altacliente.text_8.value:=oRow:fieldGet("telefono2")
altacliente.text_9.value:=oRow:fieldGet("fax")
altacliente.text_10.value:=oRow:fieldGet("respon")
altacliente.text_11.value:=oRow:fieldGet("email")
altacliente.text_12.value:=oRow:fieldGet("complemento")
altacliente.text_13.value:=oRow:fieldGet("franjaa")
altacliente.text_14.value:=oRow:fieldGet("honor_imp")
altacliente.text_15.value:=oRow:fieldGet("minimo_imp")
altacliente.text_16.value:=oRow:fieldGet("honor_exp")
altacliente.text_17.value:=oRow:fieldGet("minimo_exp")
altacliente.text_18.value:=oRow:fieldGet("estado")
altacliente.text_19.value:=oRow:fieldGet("no_int")
altacliente.text_20.value:=oRow:fieldGet("no_ext")
altacliente.text_21.value:=oRow:fieldGet("pais")
altacliente.text_1.enabled:=.f.
endif
bQuery:Destroy()
saludos
bQuery:= oServer:Query( "Select clave,nombre,direccion1,ciudad,codigo,estado,rfc,telefono1,telefono2,fax,respon,email,honor_imp,minimo_imp,honor_exp,minimo_exp,complemento,franjaa,no_int,no_ext,pais From Cliente where clave = " + aValue[1] )
If bQuery:NetErr()
MsgStop ( bQuery:Error() )
Return
Endif
if bQuery:LastRec() > 0
oRow := bQuery:GetRow(1)
mcve:=alltrim(str(oRow:fieldGet("clave")))
altacliente.text_1.value:=oRow:fieldGet("clave")
altacliente.text_2.value:=oRow:fieldGet("nombre")
altacliente.text_3.value:=oRow:fieldGet("direccion1")
altacliente.text_4.value:=oRow:fieldGet("ciudad")
altacliente.text_5.value:=oRow:fieldGet("codigo")
altacliente.text_6.value:=oRow:fieldGet("rfc")
altacliente.text_7.value:=oRow:fieldGet("telefono1")
altacliente.text_8.value:=oRow:fieldGet("telefono2")
altacliente.text_9.value:=oRow:fieldGet("fax")
altacliente.text_10.value:=oRow:fieldGet("respon")
altacliente.text_11.value:=oRow:fieldGet("email")
altacliente.text_12.value:=oRow:fieldGet("complemento")
altacliente.text_13.value:=oRow:fieldGet("franjaa")
altacliente.text_14.value:=oRow:fieldGet("honor_imp")
altacliente.text_15.value:=oRow:fieldGet("minimo_imp")
altacliente.text_16.value:=oRow:fieldGet("honor_exp")
altacliente.text_17.value:=oRow:fieldGet("minimo_exp")
altacliente.text_18.value:=oRow:fieldGet("estado")
altacliente.text_19.value:=oRow:fieldGet("no_int")
altacliente.text_20.value:=oRow:fieldGet("no_ext")
altacliente.text_21.value:=oRow:fieldGet("pais")
altacliente.text_1.enabled:=.f.
endif
bQuery:Destroy()
saludos
Re: Como se maneja el retorno de la clase TMySQLServer()
Gracias de nuevo MartinGz por echarme la manita. Bendiciones y Feliz Año. Saludos.
Re: Como se maneja el retorno de la clase TMySQLServer()
Hola, tambien se puede abreviar asi:
bQuery:= oServer:Query( "Select clave,nombre,direccion1,ciudad,codigo,estado,rfc,telefono1,telefono2,fax,respon,email,honor_imp,minimo_imp,honor_exp,minimo_exp,complemento,franjaa,no_int,no_ext,pais From Cliente where clave = " + aValue[1] )
If bQuery:NetErr()
MsgStop ( bQuery:Error() )
Return
Endif
if bQuery:LastRec() > 0
bQuery:Gotop()
mcve:=alltrim(str(bQuery:clave))
altacliente.text_1.value:=bQuery:clave
altacliente.text_2.value:=bQuery:nombre
altacliente.text_3.value:=bQuery:direccion1
altacliente.text_4.value:=bQuery:ciudad
altacliente.text_5.value:=bQuery:codigo
altacliente.text_6.value:=bQuery:rfc
altacliente.text_7.value:=bQuery:telefono1
altacliente.text_8.value:=bQuery:telefono2
altacliente.text_9.value:=bQuery:fax
altacliente.text_10.value:=bQuery:respon
altacliente.text_11.value:=bQuery:email
altacliente.text_12.value:=bQuery:complemento
altacliente.text_13.value:=bQuery:franjaa
altacliente.text_14.value:=bQuery:honor_imp
altacliente.text_15.value:=bQuery:minimo_imp
altacliente.text_16.value:=bQuery:honor_exp
altacliente.text_17.value:=bQuery:minimo_exp
altacliente.text_18.value:=bQuery:estado
altacliente.text_19.value:=bQuery:no_int
altacliente.text_20.value:=bQuery:no_ext
altacliente.text_21.value:=bQuery:pais
altacliente.text_1.enabled:=.f.
endif
bQuery:Destroy()
saludos a todos
bQuery:= oServer:Query( "Select clave,nombre,direccion1,ciudad,codigo,estado,rfc,telefono1,telefono2,fax,respon,email,honor_imp,minimo_imp,honor_exp,minimo_exp,complemento,franjaa,no_int,no_ext,pais From Cliente where clave = " + aValue[1] )
If bQuery:NetErr()
MsgStop ( bQuery:Error() )
Return
Endif
if bQuery:LastRec() > 0
bQuery:Gotop()
mcve:=alltrim(str(bQuery:clave))
altacliente.text_1.value:=bQuery:clave
altacliente.text_2.value:=bQuery:nombre
altacliente.text_3.value:=bQuery:direccion1
altacliente.text_4.value:=bQuery:ciudad
altacliente.text_5.value:=bQuery:codigo
altacliente.text_6.value:=bQuery:rfc
altacliente.text_7.value:=bQuery:telefono1
altacliente.text_8.value:=bQuery:telefono2
altacliente.text_9.value:=bQuery:fax
altacliente.text_10.value:=bQuery:respon
altacliente.text_11.value:=bQuery:email
altacliente.text_12.value:=bQuery:complemento
altacliente.text_13.value:=bQuery:franjaa
altacliente.text_14.value:=bQuery:honor_imp
altacliente.text_15.value:=bQuery:minimo_imp
altacliente.text_16.value:=bQuery:honor_exp
altacliente.text_17.value:=bQuery:minimo_exp
altacliente.text_18.value:=bQuery:estado
altacliente.text_19.value:=bQuery:no_int
altacliente.text_20.value:=bQuery:no_ext
altacliente.text_21.value:=bQuery:pais
altacliente.text_1.enabled:=.f.
endif
bQuery:Destroy()
saludos a todos