fromdjango.dbimportconnection, transaction
def my_custom_sql():
from django.db import connection, transaction
cursor = connection.cursor()
# Data modifying operation - commit required
cursor.execute("UPDATE bar SET foo = 1 WHERE baz = %s", [self.baz])
transaction.commit_unless_managed()
# Data retrieval operation - no commit required
cursor.execute("SELECT foo FROM bar WHERE baz = %s", [self.baz])
row = cursor.fetchone()
return row
connection.cursor() 得到数据库游标对象
transaction.commit_unless_managed() 提交所作的修改
分享到:
2012-06-20 16:30
浏览 838
分类:数据库
评论