开发者

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:

  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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜