David Woods wrote:
Glad you got it solved.
db.autocommit(1)
Also works for me, as does including c.execute("COMMIT") following queries
that change the data.David
I personally use SqlAlchemy for most of my database access. I've heard good things about DeJaVu too. Either way, it's definitely a more "pythonic" way of interacting with databases. This is definitely OT though.
Mike
···
-----Original Message-----
From: wxpython-users-bounces+dwoods=wcer.wisc.edu@lists.wxwidgets.or
g [mailto:wxpython-users-bounces+dwoods=wcer.wisc.edu@lists.wxwi
dgets.org] On Behalf Of Tanay Shah
Sent: Thursday, April 02, 2009 9:10 AM
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Cannot insert into DatabaseProblem Solved!
Just had to include cursor.execute('set autocommit=1') before executing any other insert, update or delete query.
On Thu, Apr 2, 2009 at 7:27 PM, johnf <jfabiani@yolo.com> wrote:
On Thursday 02 April 2009 06:45:25 am Tanay Shah wrote:
def OnBtSaveButton(self, event):
Name = self.ConName.GetValue()
Number = self.Number.GetValue()
if Name and Number :
##db=pdo.connect("Module=MySQLdb;User=root;Passwd=root;DB=smscentral")
## if db.active:
## strInsert = "INSERT INTO contacts(Name,Number)
VALUES('"+str(Name)+"','"+str(Number)+"')"
## try:
## db.execute(strInsert)
## except:
## print 'Error Insert'
## finally:
## db.close()
## self.Destroy()
db=MySQLdb.connect(host='localhost', user='root' , passwd='root', db='smscentral')
c=db.cursor()
strI = "INSERT INTO contacts(Name,Number) VALUES('"+str(Name)+"','"+str(Number)+"')"
c.execute("""INSERT INTO contacts(Name,Number)
VALUES('TAN','99999999')""")
c.close()
db.close()
self.Destroy()
You did not show the table structure so it not possible to determine if you have a data type issue. Also it is best to allow python to handle the parameters as follows:
c.execute("INSERT INTO contacts(Name,Number) VALUES('%s','%s')" %
(Name,Number))You also might want to check out www.dabodev.com. Dabo was designed to do what you are trying to do.
--
John Fabiani