Matt
Matt

Reputation: 1072

Inserts don't appear to be happening

I'm using gevent with gevent-mysql (I also used pymysql to the same effect). It does selects just fine but no matter what I do I can't get it to run an insert. I'm out of ideas.

conn = geventmysql.connect(host='localhost', port=3306, user='root', db='content')
cur = conn.cursor()
cur.execute("insert into placement (placement_name, some_id) values ('static', 1)")
cur.close()
conn.close()

Upvotes: 1

Views: 143

Answers (3)

Chris Morgan
Chris Morgan

Reputation: 2080

If you are using a transactional storage engine (like InnoDB), you should check the value of the autocommit variable: http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_autocommit

If it is 0, you need to commit your transactions, either using a built in commit() method or an execute("COMMIT") call.

Upvotes: 3

Brendan Long
Brendan Long

Reputation: 54302

In the Python DB API, everything is implicitly a transaction. If you close the connection without committing, it gets rolled back. Do this:

conn.commit()
cur.close()
conn.close()

Upvotes: 1

Hyperboreus
Hyperboreus

Reputation: 32449

If geventmysql works like the rest of the python DB APIs, you need to call commit in order to commit any changes to the database. Unless geventmysql

Upvotes: 2

Related Questions