在创建具有静态配置的pooledDB连接之后,我需要动态地将游标类型更改为MySQLdb.cursors.DictCursor。下面是我的代码。
conn_pool = PooledDB(creator=MySQLdb,
host=config["host"],
user=config["user"],
password=config["password"],
database=config["database"],
autocommit=True,
charset="utf8",
cursorclass=MySQLdb.cursors.Cursor,
blocking=True,
maxcached=int(config["maxcached"]),
ping=1,
maxconnections=int(config["maxconnections"]))
def func1:
my_con = conn_pool.connection()
my_cur = my_con.cursor()
my_cur.execute( sql, args )
def func2:
#In this function I have a need of DictCursor
my_con = conn_pool.connection()
my_cur = my_con.cursor()
my_cur.execute( sql, args )