1

I'm having issues with pyodbc used with an Oracle DB. I can do select statements with results coming back, however when I try to update a record, the program seems to hang during the "conn.execute(query)" line with no error messages. I have to force quit the application.

Running a select statement retrieves the expected result. Updating that same record will hang. I've also used this definition on other applications with no issues on a MSSQL DB with selects and updates working properly. I've also checked that the user / pass do have read and write permissions

import pyodbc

def connect_odbc(conn_str, query, commit=False):
    """
    Returns result set from connection string.
    If commit is set to true, it will write to DB as well
    """
    if commit:
        conn = pyodbc.connect(conn_str)
        cursor = conn.cursor()
        cursor.execute(query)  ### <--- Program hangs here
        cursor.commit()
        cursor.close()
        return True
    else:
        conn = pyodbc.connect(conn_str)
        cursor = conn.cursor()
        cursor.execute(query)
        results = cursor.fetchall()
        cursor.close()

        return results

## Main Program ##
query = "select * from multishipdtl where cartonid = '100000000060506';"
queryupdate = "update multishipdtl set trackid='88888888' where cartonid = '100000000060506';"

conn_str = '''DSN=syntest;UID=userid;PWD=userpass'''
results = connect_odbc(conn_str, query)  ### This connects ok with expected results

connect_odbc(conn_str, queryupdate, commit=True)  ### Update statement hangs
Ray Chan
  • 35
  • 5

1 Answers1

0

If the program hangs when executing cursor.execute("UPDATE ..."), the first thing I'd check is if it's waiting for the database to respond: How do you show SQL executing on an Oracle database?

An ODBC trace log might be helpful too.

Nickolay
  • 31,095
  • 13
  • 107
  • 185