我想在postgresql-9.3db中插入数据, 我使用的是Python-2.7和psycopg2api。在
到目前为止,我在很多模块中使用它,并在一些操作之后执行commit()
。
因为有很多commit()
位置,我不想在所有提交中添加测试模式,
因此,我认为最好的方法是将测试模式案例中的提交重定向到void函数:
#create connection
connection = psycopg2.connect(host=db_host, database=db_name, user=db_user, password=db_pwd,)
#in test_mode disable commit functionality
def void():
print("No commit,this is a test mode")
if settings.test_mode:
connection.commit=void
但我得到的是这个
^{pr2}$欢迎任何建议!在
可以用代理类包装connection对象:
不过,如果能避免在代码中到处使用提交,那会更好。在
您可以使用
ROLLBACK
相关问题 更多 >
编程相关推荐