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

SQL Server TEXT columns read as nulls but work OK with pyodbc #272

Open
batterseapower opened this issue Jul 6, 2020 · 0 comments
Open

Comments

@batterseapower
Copy link

batterseapower commented Jul 6, 2020

This program fails with AssertionError: '\x00\x00\x00' but it should succeed.

import turbodbc
import pyodbc

cstring = 'DRIVER={SQL Server};SERVER=<redacted>;PORT=1433;DATABASE=<redacted>;UID=<redacted>;PWD=<redacted>;TDS_Version=7.1'
conn = turbodbc.connect(connection_string=cstring, turbodbc_options=turbodbc.make_options(prefer_unicode=True, autocommit=True)) # A
#conn = turbodbc.connect(connection_string=cstring, turbodbc_options=turbodbc.make_options(prefer_unicode=False, autocommit=True)) # B
#conn = pyodbc.connect(cstring) # C
cursor = conn.cursor()

cursor.execute('create table ##temp (foo text collate SQL_Latin1_General_CP1_CI_AS)')
try:
    cursor.execute("insert into ##temp (foo) values ('bar')")
    (x,), = cursor.execute('select foo from ##temp')
    assert x == 'bar', repr(x)
finally:
    cursor.execute('drop table ##temp')

Uncommenting line A and replacing with B doesn't change anything. Using pyodbc instead (C) does fix it. You can also fix it by changing the final SQL statement to select cast(foo as varchar(100)) from ##temp.

VARCHAR(MAX) behaves the same way as TEXT. I originally observed the problem with a non-temporary table so it's nothing to do with that -- it was just easier to demonstrate the issue with a temp table. Getting rid of the TDS_Version param also doesn't change anything.

Observed with turbodbc 3.3.0.

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