[Python-es] Insertar datos mysql

G V nadaird en gmail.com
Mie Ago 7 12:39:04 CEST 2013


Creo que la solución que buscas está en
https://github.com/farcepest/MySQLdb1/blob/master/doc/user_guide.rst#some-examples

pero a grandes rasgos estas intentando hacer la sustitucion a mano dentro
del propio string


2013/8/6 Alfredo Riguetti <alfredo.riguetti en ptravel.com.uy>

> Hola a Todos
> Necesito que alguien me ayude con esto. tengo que ingresar unos datos del
> cliente a una base y si les pongo los datos a mano en el insert lo hace
> perfecto pero si lo quiero hacer con variabnles no lo hace alguien me puede
> ayudar copio el codigo, seguro algo esta mal escrito o algo asi.
>
> ahora deje solo los datos para la cedula para probar pero nada ...
>
> def OnClickAceptar(self,event):
>
>         dtcedula = self.TextoCedulaCli.GetValue()
>         nombres = self.TextoNombresCli.GetValue(**)
>         apellidos = self.TextoApellidosCli.**GetValue()
>         direccion = self.TextoDireccionCli.**GetValue()
>         email = self.TextoCorreo.GetValue()
>         telefonocelular = self.TextoTelefonoCeluar.**GetValue()
>         telefonoparticular = self.TextoTelefonoParticular.**GetValue()
>
>
>
>         # Open database connection
>         db = MySQLdb.connect("localhost","**root","miyaguiAdminaya2010","*
> *cambio")
>
>         # prepare a cursor object using cursor() method
>         cursor = db.cursor()
>
>         # Prepare SQL query to INSERT a record into the database.
>
>         print dtcedula
>         sql = """INSERT INTO clientes(cedula) VALUES ('%s') % dtcedula"""
>
>
>         try:
>                  # Execute the SQL command
>                  cursor.execute(sql)
>                  # Commit your changes in the database
>                  db.commit()
>         except:
>                  #Rollback in case there is any error
>                  db.rollback()
>
>                  # disconnect from server
>                  db.close()
>
> ______________________________**_________________
> Python-es mailing list
> Python-es en python.org
> http://mail.python.org/**mailman/listinfo/python-es<http://mail.python.org/mailman/listinfo/python-es>
> FAQ: http://python-es-faq.wikidot.**com/<http://python-es-faq.wikidot.com/>
>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20130807/91a996fc/attachment.html>


Más información sobre la lista de distribución Python-es