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

Problems with SQL for MS SQL 2012r2 and Linux Ubuntu 16.04 #68

Open
ProstakovAlexey opened this Issue Jan 5, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@ProstakovAlexey

ProstakovAlexey commented Jan 5, 2018

I found a problem with SQL query, I result the code below::

# -*- coding: utf-8 -*-
import pypyodbc
con_str = "DRIVER={FreeTDS}; SERVER=192.168.0.2; PORT=49223; DATABASE=dotProject2; UID=sa; PWD=111; TDS_Version=8.0; ClientCharset=UTF8; autocommit=False"
con = pypyodbc.connect(con_str)
cur = con.cursor()
-- request 1
cur.execute('SELECT id FROM Tasks WHERE name=? AND TopicId=?', ('Изменение в руководство пользователя АСП', 193))
print('1) good select type B by sql param:', cur.fetchone())
-- request 2
cur.execute('SELECT id FROM Tasks WHERE name=? AND TopicId=?', ('Изменение в руководство пользователя и хвост', 193))
-- request 3
cur.execute('SELECT id FROM Tasks WHERE name=? AND TopicId=?', ('Изменение в руководство пользователя АСП', 193))
print('2) bad select type B by sql param:', cur.fetchone())
con.close()

I sure, request 1 = request 2, and must have one result. But program print is:

1) good select type B by sql param: (70077,)
2) bad select type B by sql param: None

I look in SQL profiler and see for request 1:

declare @p1 int
set @p1=NULL
exec sp_prepexec @p1 output,N'@P1 NVARCHAR(255),@P2 INT',N'SELECT id FROM Tasks    WHERE name=@P1 AND TopicId=@P2',N'Изменение в руководство пользователя АСП',193
select @p1

after it is look it:

exec sp_execute 1,N'Изменение в руководство пользователя и хвост',193
exec sp_execute 1,N'Изменение в руководство пользователя АСПЀост',193

You can see, request 2 have error. Must have Изменение в руководство пользователя АСП, but have Изменение в руководство пользователя АСПЀост. I think this is the "tail" from the previous query. My system pypyodbc 1.3.5, Linux Ubuntu 16.04, python 3.5 and now I made update. I have server Ubuntu 14.04 with pypyodbc 1.3.3, python 3.3 - and see this problem too. When I rewrite program, for use pyodbc (4.0.17) - have not problem. In profiler I see::

declare @p1 int
set @p1=NULL
exec sp_prepexec @p1 output,N'@P1 NVARCHAR(40),@P2 INT',N'SELECT id FROM Tasks WHERE name=@P1 AND TopicId=@P2',N'Изменение в руководство пользователя АСП',193
select @p1
--
declare @p1 int
set @p1=NULL
exec sp_prepexec @p1 output,N'@P1 NVARCHAR(44),@P2 INT',N'SELECT id FROM Tasks WHERE name=@P1 AND TopicId=@P2',N'Изменение в руководство пользователя и хвост',193
select @p1
--
declare @p1 int
set @p1=NULL
exec sp_prepexec @p1 output,N'@P1 NVARCHAR(40),@P2 INT',N'SELECT id FROM Tasks WHERE name=@P1 AND TopicId=@P2',N'Изменение в руководство пользователя АСП',193
select @p1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment