oracle / python-cx_Oracle

Python interface to Oracle Database now superseded by python-oracledb
https://oracle.github.io/python-cx_Oracle
Other
889 stars 361 forks source link

Different RAW query results from django.db.connection and cx_Oracle #587

Closed jam21 closed 3 years ago

jam21 commented 3 years ago

I executed the following query from my Django project shell. from django.db import connection balance_query = "some sql query here" with connection.cursor() as cur: cur.execute(balance_query) balance_data = cur.fetchall() print(balance_date)

Then I get result after print as (1, 'F', 77259668) (9, 'R', '24153')

The bold value is wrong

But When I execute same query with following code import cx_Oracle dsn_tns = cx_Oracle.makedsn('host', 'post', service_name='name') conn = cx_Oracle.connect(user=r'user', password='pwd', dsn=dsn_tns) c = conn.cursor() c.execute(balance_query) for r in c: print(r) Then it shows correct values which are following

(1, 'F', '77244730') (9, 'R', '24153')

Only one value is differentiating which I marked bold and italic Backend. DB is Oracle and I am using same instance with same credentials for both connections. It is only happening for one user, for all other users query gives same result with cx_oracle and django.connection.cursor

jam21 commented 3 years ago

I do not know what was the issue but we fixed it making changes in my SQL query I replaced if trunc(p_order_date) < '11-FEB-2021' then ......... ......... endif with if trunc(p_order_date) < to_date('11-FEB-2021','DD-MON-RRRR') then ............. ............. endif and it fixed now

intgr commented 3 years ago

This is unrelated to cx_Oracle, but Django's own logic. Django executes in every database connection:

ALTER SESSION SET
    NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
    NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'

This issue can be closed.

anthony-tuininga commented 3 years ago

Ok. Thanks for following up!