如何在池连接中动态更改游标类型?

时间:2019-06-04 12:47:54

标签: mysql database cursor connection-pooling pymysql

在创建具有静态配置的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 )

0 个答案:

没有答案