make a new file called fakedb.py
and copy some contents from psycopg1.py from psycopg2 package
class connection(_2connection):
"""psycopg 1.1.x connection."""
def cursor(self):
"""cursor() -> new psycopg 1.1.x compatible cursor object"""
return _2connection.cursor(self, cursor_factory=psycopg2.extras.DictCursor)
def autocommit(self, on_off=1):
"""autocommit(on_off=1) -> switch autocommit on (1) or off (0)"""
if on_off > 0:
self.set_isolation_level(_ext.ISOLATION_LEVEL_AUTOCOMMIT)
else:
self.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED)
the point is to specify cursor_factory as DictCursor..
now use this file with adbapi like
adbapi.ConnectionPool("fakedb", database="test",host='localhost',\
port=9000,user='mathgl')
本文介绍如何创建一个名为fakedb.py的文件,并从psycopg2包中复制部分内容来实现兼容psycopg1.1.x连接类的功能。具体包括自定义游标工厂为DictCursor及实现自动提交功能。
5080

被折叠的 条评论
为什么被折叠?



