Python MySql 连接器预备声明和字典类

2024-09-30 22:18:28 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使我的光标成为一个预先准备好的语句和一个字典。 我有以下内容。在

 cursor(cursor_class = MySQLCursorPrepared)
 prints <class 'mysql.connector.cursor.MySQLCursorPrepared'>
 cursor(dictionary = True)
 prints <class 'mysql.connector.cursor.MySQLCursorDict'>

所以我用字典重写准备好的语句。我正在使用python3的mysql连接器。在

我试过了

^{pr2}$

那个错误

Cursor not available with given criteria: dictionary, prepared

有趣的是

cursor(cursor_class = MySQLCursorPrepared,dictionary = True)

我没有错误,但数据不是字典型的。在


Tags: trueconnectordictionary字典错误mysql语句prints
2条回答

我也有同样的问题。准备好的和字典不在一起。在

我报告了错误:https://bugs.mysql.com/bug.php?id=92700

现在我们等待;)

这种天真的解决方法似乎对我有效-如果我禁用SSL,我可以在“strace”输出中看到,多个相同的查询只被发送到服务器一次,而且当我迭代光标的行时,我肯定会得到字典:

from mysql.connector.cursor import MySQLCursorDict, MySQLCursorPrepared

class PreparedDictionaryCursor(MySQLCursorDict, MySQLCursorPrepared):

    pass

相关问题 更多 >