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

Comments

@bigfoxtail
Copy link

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

@anthony-tuininga
Copy link
Member

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

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
Development

No branches or pull requests

2 participants