python - 弃用的 twisted.enterprise.util

标签 python mysql twisted

最近将 Twisted 从 11 更新到 12 版本。发现 twisted.enterprise.util 模块不存在了。

我曾经这样做过:

from twisted.enterprise import adbapi, util as dbutil

query = "select userid, password from user where username = %s" % (
      dbutil.quote(credentials.username, "char"))

现在我们需要用到什么第三方库?

最佳答案

正确的方法是使用“绑定(bind)参数”。这使 SQL 与 数据并删除由于错误引用而导致的整个错误类别。道路 使用绑定(bind)参数是将 SQL 字符串作为单独的参数传递 来自 SQL 数据。使用 DB-API 2.0,这意味着:

cursor.execute("SELECT foo FROM bar WHERE baz = ?", (3,))

使用 ADBAPI,它的意思非常相似:

connpool.runQuery("SELECT foo FROM bar WHERE baz = ?", (3,))

不同的数据库适配器对“?”使用不同的语法。部分。这 DB-API 2.0 模块的“paramstyle”属性告诉您什么语法 特定模块使用。请参阅 DB-API 2.0 PEP ( http://www.python.org/dev/peps/pep-0249/ ) 了解详情。

来源:http://twistedmatrix.com/pipermail/twisted-python/2009-March/019268.html

关于python - 弃用的 twisted.enterprise.util,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9705442/

相关文章:

python - 云计算:何时合理使用Docker?

python - 使用 Postgres 的 SQLAlchemy 中两个日期之间的平均天数

mysql - 我需要在结果集中打印变量

python - CentOS6下安装twis​​ted

python - 'METHODNAME' 作为客户端方法与扭曲的 irc _'METHODNAME'

python - 为什么数组的形状不正确?

python - 在 Python 中从非常大的文本文件中删除重复项的更快方法?

mysql - 如何找到该用户的mysqldump操作权限

mysql - 错误 1064 (42000) : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version

python - reactor.connectTCP 可以在 twisted python 中的 reactor.run 之后发生吗?