pypyodbc
pypyodbc copied to clipboard
cant truncate mssql table
Hi,
I'm hitting a problem when trying to truncate tables on an mssql server (2017 dev). I use python3.6 up to date with 4 weeks old pypi's pypyodbc on centos7.4 using the distro's freetds and odbc packages:
Here is some quick and dirty code:
conn = pypyodbc.connect('Driver={FreeTDS};TDS_Version=8.0;Server=%s;port=%u;uid=%s;pwd=%s;app=mchecker' % (
'192.168.1.32',
1433,
'sa',
'redactedpassword'
))
cursor = conn.cursor()
cursor.execute("use journaux")
cursor.execute("truncate table journaux.dbo.logs;")
And here is the error stack:
File "./marshall_sql_logs.py", line 146, in <module>
cursor.execute("truncate table journaux.dbo.logs;")
File "/home/work/.virtualenvs/multex/lib/python3.6/site-packages/pypyodbc.py", line 1626, in execute
self.execdirect(query_string)
File "/home/work/.virtualenvs/multex/lib/python3.6/site-packages/pypyodbc.py", line 1653, in execdirect
self._NumOfRows()
File "/home/work/.virtualenvs/multex/lib/python3.6/site-packages/pypyodbc.py", line 1817, in _NumOfRows
check_success(self, ret)
File "/home/work/.virtualenvs/multex/lib/python3.6/site-packages/pypyodbc.py", line 1007, in check_success
ctrl_err(SQL_HANDLE_STMT, ODBC_obj.stmt_h, ret, ODBC_obj.ansi)
File "/home/work/.virtualenvs/multex/lib/python3.6/site-packages/pypyodbc.py", line 985, in ctrl_err
raise Error(state,err_text)
pypyodbc.Error: ('HY010', '[HY010] [unixODBC][Driver Manager]Function sequence error')
I've tried a few tricks, but to no avail. I'm at a loss as to what goes wrong here, I can run the same query in smss (the ms sql console "gui") and it works flawlessly... On my centos client, from python, I can also dump the query in a text file and run it sucessfully via the tsql client using
os.system("tsql %logindetails% dumpedquery.txt")
but its a total kludge that I dont want to live with...