This read-write attribute specifies a method to call for each row that
is retrieved from the database. Ordinarily a tuple is returned for
each row but if this attribute is set, the method is called with the
tuple that would normally be returned, and the result of the method is
returned instead.
老问题,但添加一些与Python配方相关的有用链接
根据
cx_Oracle
文档:cx_Oracle - Python Interface for Oracle Database还指向GitHub存储库以获取许多有用的sample示例。请检查GenericRowFactory.py。
谷歌:这个PPT可以进一步帮助:[PDF]CON6543 Python and Oracle Database - RainFocus
配方
Django数据库后台为Oracle under the hood使用的是cx_Oracle。在早期的版本(Django 1.11-)中,他们编写了^{} ,还将cx_Oracle的数字数据类型转换为相关的Python数据,并将字符串转换为unicode。
如果您安装了Django,请按以下方式检查base.py:
可以从
$DJANGO_DIR/db/backends/oracle/base.py
中借用_rowfactory()
,并可以在decoratornaming
下面应用,使其返回namedtuple
,而不是简单的tuple
。mybase.py版
用作:
甲骨文.py
现在,不要在用户脚本中导入cx_oracle导入oracle:
用户.py
试试看!!
非常简短的版本:
在Python 3.7.0和cx上测试Oracle 7.1.2
您可以重写游标的
rowfactory
方法。每次执行查询时都需要这样做。这是标准查询的结果,一个元组。
返回命名元组:
返回词典:
阿默里·福盖特·德·阿尔克的功劳: http://sourceforge.net/p/cx-oracle/mailman/message/27145597
相关问题 更多 >
编程相关推荐