Lucas Kauffman
Lucas Kauffman

Reputation: 6891

Python mysqldb returns inserted row but mysql returns an emptyset

I use mysqldb to insert a row:

 def insertNewLog(self,uid,beginDate,endDate,logs):
        qry1 = """INSERT INTO logs (owner,createDate,endDate,log) VALUES (%s,%s,%s,%s); """ 
        cursor = self.db.cursor()
        beginDate = int(time.mktime( beginDate.timetuple() ))
        endDate = int(time.mktime( endDate.timetuple()))
        print beginDate
        print endDate 
        cursor.execute(qry1,(uid,beginDate,endDate,logs),)
        print "inserted normally"
        print "Number of rows inserted: %d" % cursor.rowcount

I get this output:

1337720045
1337740625
inserted normally
Number of rows inserted: 1

However when I do a select on my database in mysql shell I get 'empty set'. I check my mysql logs and there is nothing reported in there. I'm a bit baffled.

Upvotes: 0

Views: 510

Answers (1)

mata
mata

Reputation: 69042

you should probably call commit() on your db connection. otherwise the insert is rolled back.

Upvotes: 5

Related Questions