Function sequence error (0) (SQLFetch) - SQL, Pyodbc

若如初见. 提交于 2019-12-13 02:35:27

问题


for _item in file_list:
    for col in cursor.execute("select column1,column2 from tbl"):
        if _item[0]==col.column1:
            #I also tried using a different cursor, still doesn't work
            var1 = cursor.execute("select column2 from tbl where column1=?", _item[0])
            for i in var1: var2 = i[0]
            try:
                cursor3.execute("insert into tbl(column2,column1,column3,column4) values (?,?,?,?)", (var1, _item[0],_item[1],_item[2]))
                cursor3.commit() 
            except IOError as error:
                print error

What i am trying to do is compare the values in a list and the ones from column1, if they match, get the value from column2 on the same row, then add a new line with the value from column2 but different values for the remaining ones.

But unfortunately it doesen't work the way i did it, when running the code above python throws the error:

Error: ('HY010', '[HY010] [Microsoft][ODBC Driver Manager] Function sequence error (0) (SQLFetch)')

In line:

for columnrow in cursor.execute("select column1,column2 from tbl")

回答1:


What you're doing is fine and should work per @ScottMorken's comment to this answer.


Old answer:
You need to retrieve the results of the query using, for example, .fetchall()
So instead of that line you could do:

for columnrow in cursor.execute("select column1,column2 from tbl").fetchall():
    ...


来源:https://stackoverflow.com/questions/18215392/function-sequence-error-0-sqlfetch-sql-pyodbc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!