Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant truncate mssql table #90

Open
caliloo opened this issue Dec 3, 2018 · 0 comments
Open

cant truncate mssql table #90

caliloo opened this issue Dec 3, 2018 · 0 comments

Comments

@caliloo
Copy link

caliloo commented Dec 3, 2018

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant