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

All-caps columns can't be found #23

Open
qguv opened this issue May 29, 2015 · 2 comments
Open

All-caps columns can't be found #23

qguv opened this issue May 29, 2015 · 2 comments

Comments

@qguv
Copy link

qguv commented May 29, 2015

When working with a MS SQL 2008 database through ODBC, all-caps column names in a row must be accessed in lowercase to yield the correct information.

for row in cur.execute("select * from TOTAL_DETAIL where IDENTIFIER = ?", (id, )):
    print(row["PRODUCT"]) # None
    print(row["product"]) # the correct product name

If this is a quirk of ODBC, a possible solution (if it doesn't cause other problems) would be to .lower() all keys before searching the Row-internal dictionary.

@braian87b
Copy link
Collaborator

Hi, dict keys are case sensitive natively in language... not as the column names / table names / db names in sql server... to achieve a pseudo-case-insensitiviness lib has done .lower() to all names.

import pypyodbc; pypyodbc.lowercase = True # (Default behaviour)

In that way you will have to specify everywhere (and get used to) use lowercased names everywhere in your app (recommended)

import pypyodbc; pypyodbc.lowercase = False

you will have to write names using the ExAcT case in names.

Will be a good idea to replace the native use of dict in lib to use a case-insensitive dict, like this one:
https://gist.github.com/babakness/3901174
but there are others available also ...

https://www.python.org/dev/peps/pep-0455/
http://stackoverflow.com/a/2082169
http://stackoverflow.com/a/3296782

@VishalK-NewcrestImage
Copy link

VishalK-NewcrestImage commented Feb 6, 2020

YoU SaVeD mY DaY. ✌️

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

No branches or pull requests

3 participants