SQL Update fails - pyodbc - informix
Updates to an 开发者_Python百科informix database via a python script using pyodbc are silently failing.
I am using the syntax as provided in the pyodbc wiki and tried manual commit as well as autocommit
cursor= conn.cursor()
cursor.execute("update eqpt set notes='BOB' where serialno='SAM'")
conn.commit()
conn.close()
I posted this question in the pyodbc group as well but unfortunately did not get an answer.
Two ideas:
Check how many records was changed (it is retured by
execute()
), and how many records should be changed (usingSELECT count(*) ... WHERE...
:cursor= conn.cursor() rs = c.execute("SELECT count(*) FROM eqpt WHERE serialno='SAM'") for txt in c.fetchall(): print('before %s' % (txt[0])) rows_affected = cursor.execute("update eqpt set notes='BOB' where serialno='SAM'") print('rows_affected: %d' % (rows_affected)) rs = c.execute("SELECT count(*) FROM eqpt WHERE serialno='SAM'") for txt in c.fetchall(): print('after %s' % (txt[0])) conn.commit() conn.close()
You can enable ODBC tracing and check what is returned by ODBC driver.
精彩评论