-
Notifications
You must be signed in to change notification settings - Fork 93
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
- What versions are you using?
>>> import oracledb
>>> oracledb.__version__
'1.3.2'
Give your database version.
Oracle 19c
Also run Python and show the output of:
>>> import sys
>>> import platform
>>>
>>> print("platform.platform:", platform.platform())
platform.platform: Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.28
>>> print("sys.maxsize > 2**32:", sys.maxsize > 2**32)
sys.maxsize > 2**32: True
>>> print("platform.python_version:", platform.python_version())
platform.python_version: 3.11.4
And:
>>> import oracledb
>>> oracledb.__version__
'1.3.2'
-->
- Is it an error or a hang or a crash?
Error
- What error(s) or behavior you are seeing?
Using a null bind variable in this statementAND NVL(:l_sysdate, SYSDATE) >= foo.c1 doesn't appear to work by default.
It seems the only way to make it work is by calling cur.setinputsizes(l_sysdate=oracledb.Date) in advance.
I tried doing this from both sqlplus and sqldeveloper, where it seems to work fine without having to specify any date data type.
Database setup:
create table foo (c1 date);
insert into foo values (sysdate - 1/24);
commit;
select * from foo;
select sysdate, c1 from foo;
2023-09-07 08:43:44 2023-09-07 07:38:16
Python:
cur = conn.cursor()
l_sysdate = None
# Here we try using NVL(:l_sysdate, SYSDATE) which returns nothing
result = cur.execute(
'''
SELECT COUNT(1)
FROM foo
WHERE 1=1
AND NVL(:l_sysdate, SYSDATE) >= foo.c1
''',
dict(
l_sysdate=None
)
).fetchone()
# This should be 1, but it is 0
assert result[0] == 0
# But NVL(NULL, SYSDATE) works as expected
result = cur.execute(
'''
SELECT COUNT(1)
FROM foo
WHERE 1=1
AND NVL(NULL, SYSDATE) >= foo.c1
''',
).fetchone()
# This is correctly 1
assert result[0] == 1
## Work around
# Calling this seems to fix it
cur.setinputsizes(l_sysdate=oracledb.Date)
result = cur.execute(
'''
SELECT COUNT(1)
FROM foo
WHERE 1=1
AND NVL(:l_sysdate, SYSDATE) >= foo.c1
''',
dict(
l_sysdate=None
)
).fetchone()
# It works now
assert result[0] == 1
It works fine when I use sqlplus or sqldeveloper. I don't need to specify any date datatype for it to work.
Use a gist for long screen output and logs: see https://gist.github.com/
-->
- Does your application call init_oracle_client()?
Yes
This tells us whether you are using the python-oracledb Thin or Thick mode.
Thick
- Include a runnable Python script that shows the problem.
See above
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested