简体   繁体   中英

Flask-MySQLdb autocommit?

I've been searching and googling my question but couldn't find any answers.

Is there any way to set AUTOCOMMIT = True in Flask-MySQLdb?

And aside from my problem. What's the best way to use MySQL in Flask?

I like to keep my code as simple and short as possible, do I have to create a new cursor everytime I want to execute a query and then commit it?

Like:

cur = mysql.connection.cursor()
cur.execute('select x from y')
result = cur.fetchall()
cur.execute('insert into..')
mysql.connection.commit() # why do I have to do this :D

I like the PHP way very much:

sumthn = mysql_query('select foo from bar')

I know I can create a function that does that for me, but is there any better way?

can I find a better docs for flask-mysqldb? is there something better than flask-mysqldb?

you can set isolation level to 0 or to ISOLATION_LEVEL_AUTOCOMMIT

conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)

or refer to this website http://initd.org/psycopg/docs/connection.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM