Visitar URL original
Fail to make queries return empty strings instead of NULLs · Issue #454 · oracle/python-cx_Oracle · GitHub
The Wayback Machine - https://web.archive.org/web/20201123005653/https://github.com/oracle/python-cx_Oracle/issues/454
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to make queries return empty strings instead of NULLs #454

Open
bigfoxtail opened this issue Jun 20, 2020 · 2 comments
Open

Fail to make queries return empty strings instead of NULLs #454

bigfoxtail opened this issue Jun 20, 2020 · 2 comments
Labels

Comments

@bigfoxtail
Copy link

@bigfoxtail bigfoxtail commented Jun 20, 2020 •

use https://cx-oracle.readthedocs.io/en/latest/user_guide/sql_execution.html#changing-query-results-with-outconverters code

def OutConverter(value):
    if value is None:
        return ''
    return value

def OutputTypeHandler(cursor, name, defaultType, size, precision, scale):
    if defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR):
        return cursor.var(str, size, cur.arraysize, outconverter=OutConverter)

connection.outputtypehandler = OutputTypeHandler

But the query will still return a result of none.Is it my wrong way to use it or is it a bug?
thank you

@bigfoxtail bigfoxtail added the question label Jun 20, 2020
@anthony-tuininga
Copy link
Member

@anthony-tuininga anthony-tuininga commented Jun 25, 2020

I took a look and realized that the example provided in the documentation is inaccurate! We will have to adjust it and also make clear that the output type handler only handles values that are not null (or the value None). So right now there is no way to make queries return the empty string instead of None. I'll consider a way to deal with that in the future..

@anthony-tuininga
Copy link
Member

@anthony-tuininga anthony-tuininga commented Sep 15, 2020

One possible solution: add a convert_nulls parameter to cursor.var() which has a default value of False. When True, however, None would be passed through to the outconverter and inconverter functions. This retains the current behavior but gives the option of greater control for those (like you) who would prefer that. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.