开发者

SQL Update fails - pyodbc - informix

开发者 https://www.devze.com 2023-04-07 10:59 出处:网络
Updates to an 开发者_Python百科informix database via a python script using pyodbc are silently failing.

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:

  1. Check how many records was changed (it is retured by execute()), and how many records should be changed (using SELECT 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() 
    
  2. You can enable ODBC tracing and check what is returned by ODBC driver.

0

精彩评论

暂无评论...
验证码 换一张
取 消