mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.92k stars 563 forks source link

Tracing works for some programs but not others #944

Closed idontgetoutmuch closed 3 years ago

idontgetoutmuch commented 3 years ago

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:

Issue

I have

import pyodbc

conn = pyodbc.connect(DSN='Laetitia')

conn.setencoding(encoding='utf8')

cursor = conn.cursor()
result = cursor.execute("SELECT COUNT(*) FROM production_xxxxxx")

for row in cursor.fetchall():
    print(row)

And my odbci.ini file is

[ODBC Data Sources]
Laetitia = Hand Built

[ODBC]
Trace        = 1
TraceFile    = /Users/dom/Library/Containers/com.microsoft.Excel/Data/logs/odbctrace.log
Debug        = 1
DebugFile    = /Users/dom/Library/Containers/com.microsoft.Excel/Data/logs/odbcdebug.log
TraceLibrary = 

[Laetitia]
Driver      = /Library/ODBC/psqlodbc/lib/psqlodbcw.so
Description = Laetitia from slack
Servername  = 127.0.0.1
Port        = 5432
Database    = oildb
Username    = dom
Password    = dom

If I use iodbctest "DSN=Laetitia" then I get a trace file as expected but when I use the above python I see nothing.

v-chojas commented 3 years ago

Are you mixing driver managers? Which one is pyODBC loading? It is usually built to link with unixODBC, not iODBC.

idontgetoutmuch commented 3 years ago

Good point - I will look - but it shouldn't matter should it? The odbc.ini file is the same irrespective of which driver manager gets used?

UPDATE: It is being built using unixODBC. Does unixODBC not do tracing?

v-chojas commented 3 years ago

Where it looks for odbc.ini and odbcinst.ini depends what the driver manager was built with. For unixODBC you can run odbcinst -j to find out. The unixODBC tracing options are in odbcinst.ini. See documentation here https://github.com/mkleehammer/pyodbc/wiki/Troubleshooting-%E2%80%93-Generating-an-ODBC-trace-log

idontgetoutmuch commented 3 years ago

👍