我遇到了一个不合逻辑的问题。当我使用从cx_Oracle
创建的连接时,它按假定的方式工作。但是当我使用Django DB connections
时,它给出的结果却不是预期的。
import cx_Oracle
from django.db import connections
import pandas as pd
dsn_tns = cx_Oracle.makedsn('xx.x.xx.xxx', 'port', 'dbname')
cx_Oracle_conn = cx_Oracle.connect('user', 'pass', dsn_tns)
django_conn = connections["DB2"] # In django settings, I have a created "DB2" and passed the same parameters.
query = '''
SELECT (T1.ACCEPTED- T2.CANCELLED) AS "NET" FROM
(
SELECT ID, COUNT(1) AS ACCEPTED FROM ACCEPTED_TABLE
GROUP BY ID
) T1
LEFT JOIN
(SELECT ID, COUNT(1) AS CANCELLED FROM CANCELLED_TABLE
GROUP BY ID) T2
ON T1.ID=T2.ID
'''
df1 = pd.read_sql(query, cx_Oracle_conn) # Gives right result
df2 = pd.read_sql(query, django_conn) # Gives only count of T1.ACCEPTED(T2.CANCELLED having 0 count)
问题:
django.db.backends.oracle
如何工作?能详细解释吗?版本:
Django == 2.1.2
Python == 3.6.7
'ENGINE': 'django.db.backends.oracle' # As mentioned in django document in DB connections