question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pyodbc.cursor.columns doesn't always return table column information

See original GitHub issue

Please first make sure you have looked at:

Environment

To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:

  • Python: 3.7
  • pyodbc: 4.0.25
  • OS: Docker python:3.7 i.e. Debian 9 (Docker running on MacOS Mojave)
  • DB: Netsuite (some Oracle SQL database flavour)
  • driver: Netsuite ODBC driver Linux64bit 7.2.0.0050

Issue

I can execute queries against database and get data very reliably. Also getting column description using Cursor.description works fine. The problem is that with Cursor.columns sometimes I get data and sometimes not. When data is available is fully correct. I haven’t been able to draw any specific pattern when it works and when not.

“expected behavior” crsr.columns(table=‘<table_name>’) should return always the column description for the given table

“observed behavior”. crsr.columns(table=‘<table_name>’) sometimes iterator is empty i.e. no data for table columns is available

Simple test code:

def get_table_cols():
    crsr = cnxn.cursor()
    col_count = {}
    for table_name in ['ACCOUNTS', 'COUNTRIES', 'TRANSACTION_LINES', 'SUBSIDIARIES']:
        cols = crsr.columns(table=table_name)
        col_count.update({table_name: len(list(cols))})
    print(col_count)


def loop():
    for x in range(6):
        get_table_cols()


loop()

Output:

{'ACCOUNTS': 33, 'COUNTRIES': 0, 'TRANSACTION_LINES': 157, 'SUBSIDIARIES': 61}
{'ACCOUNTS': 0, 'COUNTRIES': 0, 'TRANSACTION_LINES': 157, 'SUBSIDIARIES': 61}
{'ACCOUNTS': 0, 'COUNTRIES': 0, 'TRANSACTION_LINES': 157, 'SUBSIDIARIES': 0}
{'ACCOUNTS': 0, 'COUNTRIES': 0, 'TRANSACTION_LINES': 157, 'SUBSIDIARIES': 0}
{'ACCOUNTS': 0, 'COUNTRIES': 0, 'TRANSACTION_LINES': 157, 'SUBSIDIARIES': 0}
{'ACCOUNTS': 0, 'COUNTRIES': 0, 'TRANSACTION_LINES': 157, 'SUBSIDIARIES': 0}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mkleehammercommented, Feb 2, 2019

This seems to be the same as #506 which is fixed in master but not yet released. If I had put that together I would have closed #506 as a duplicate, but since I posted to patch against it I will close this as a duplicate. If master doesn’t fix it, please reopen this, but I’m pretty sure it will.

1reaction
RaiKoHoffcommented, Jan 17, 2019

Attachment: Zip of ODBC Trace files (SUCCESS log (v.4.0.24) and FAIL log (v.4.0.25). Only difference for creating logs: pyodbc.pyd exchanged (v.4.0.24 - v.4.0.25). sql_logs.zip

Read more comments on GitHub >

github_iconTop Results From Across the Web

Select column names in a table using PyODBC - Stack Overflow
execute("SELECT * FROM table WHERE 1=2"); print cursor.fetchone() #Returns "None". Anyway, the cursor.columns function looks like the preferred ...
Read more >
pyodbc - GettingStarted.wiki - Google Code
Select Basics. All SQL statements are executed using the cursor.execute function. If the statement returns rows, such as a select statement, you can...
Read more >
The cursor class — Psycopg 2.9.5 documentation
It is a sequence of Column instances, each one describing one result column in order. The attribute is None for operations that do...
Read more >
Using Pandas with the Python PYODBC Package - YouTube
Pandas is a popular library for transforming and calculating large amounts of data, additionally, it is used heavily as a place to dump...
Read more >
Step 3: Proof of concept connecting to SQL using pyodbc
It's good to always specify ENCRYPT=yes on the client side to avoid MITM attacks. cnxn = pyodbc.connect('DRIVER={ODBC Driver 18 for SQL ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found