MySQL - No inserta datos MySQL Python

 
Vista:

No inserta datos MySQL Python

Publicado por juan pablo torres (2 intervenciones) el 03/09/2007 17:59:20
Prepare un script en python para grabar en una tabla en Mysql, que me reporta lo q grabo pero al consultarlo en la linea de comando de mysql dice q esta vacia la tabla y tambien me informa q esta vacia cuando corro otro script que lee lo q grabe, instale: Python 2.5.1, Wxpython 2.8.4.2_y_p25, Mysql 5.1, Mysql -python1.2.2win32_py2.5
que me falto? anexo el script.
import wx
import MySQLdb

from wxPython.wx import *
class CreaTablaFoliosClientes(wx.Frame):

def __init__(self, parent, id, title,
pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=wx.DEFAULT_FRAME_STYLE):

wx.Frame.__init__(self, parent, id, title, pos, size, style)
coleti=wx.Colour(234,255,244)
coltip=wx.Colour(255,239,191)

conn = MySQLdb.connect ( host = "localhost",
user = "root",
passwd = "toolsoft",
db = "puntodeventa")

cursor = conn.cursor ()

cursor.execute ("SELECT VERSION()")
row = cursor.fetchone ()
print "server version:", row[0]

cursor.execute ("DROP TABLE IF EXISTS tablas")
print "borre tablas"

cursor.execute ("CREATE TABLE tablas ( nom CHAR(15),val CHAR(20) ) ")
print "cree tablas"

cursor.execute ("INSERT INTO tablas (nom, val) VALUES ('foliosotro', '1')")
print "inserte foliosotros"

while (1):
row = cursor.fetchone ()
if row == None:
break
print "%s, %s" % (row[0], row[1])

print "Number of rows returned: %d" % cursor.rowcount

cursor.close ()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:No inserta datos MySQL Python

Publicado por joana (11 intervenciones) el 08/09/2007 10:28:17
Para que los cambios que hagas en python sean efectivos en tus tablas de MySQL despues de los executes que haces en python deberías poner la instruccion db.commit().

Espero haberte ayudado
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar