python - Function sequence error in PYODBC -
i using pyodbc
connect database , extract data it.
here code:
con = pyodbc.connect("driver={sql server};server= myserver;database= mydatabase;trusted_connection=true") cursor = con.cursor() sql_command = """ select rowid = isnull ( ( select top 1 rowid [mydatabase].[admin].[mytable] [queue] = ? , processed null ) ,-1 ) """ cursor.execute(sql_command, queuenumber) cursor.commit() con.commit() result_set = cursor.fetchall()
and got following error after run above code:
pyodbc.error: ('hy010', '[hy010] [microsoft][odbc sql server driver]function sequence error (0) (sqlfetch)')
may know caused such problem, , how can fix it?
thanks.
i believe problem strange commit
statements. need commit
when inserting or updating records not selecting.
cursor.execute(sql_command, queuenumber) result_set = cursor.fetchall()
also, in future when using commit,
both cursor.commit
, con.commit
same thing, need one.
finally, i'd used calling execute second arguement tuple:
cursor.execute(sql_command, (queuenumber,))
the way have works pyodbc
not db api standard.
Comments
Post a Comment