You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found when passing long strings (~2000+) to a stored procedure in MS SQL Server, where the parameter is set as varchar(max), that turbodbc reports a HY104, Invalid precision value error.
This doesn't happen with pyodbc, nor does it happen with turbodbc when the parameter is constructed as part of the SQL string; only when it is provided separately.
Strangely I also found that if the string was something like 'a'*3000 no such error occurred yet 'a123456...' as in the code below does result in error.
The example code shows:
pyodbc with string passed as parameter, works fine
turbodbc with string passed as parameter, doesn't work
pyodbc with string as part of sql text, works fine
turbodbc with string as part of sql text, works fine
from turbodbc import connect as turbo_connect
from pyodbc import connect as pyodbc_connect
turbo_db_conn = turbo_connect(...)
pyodbc_db_conn = pyodbc_connect(...)
pyodbc_cursor = pyodbc_db_conn.cursor()
turbo_cursor = turbo_db_conn.cursor()
my_str = 'a'
for i in range(3000):
my_str += str(i)
params = (my_str,)
sql_with_param = """EXEC [schema].SelectByFirstName @fname=? -- varchar(max)"""
sql_full = f'EXEC [schema].SelectByFirstName @fname=\'{my_str}\' -- varchar(max)'
print('Trying pyodbc - with params') # WORKS
try:
pyodbc_cursor.execute(sql_with_param, params)
print(pyodbc_cursor.fetchall())
except Exception as e:
print(e)
print('Trying turbodbc - with params') # DOESN'T WORK - HY104 / Invalid precision value
try:
turbo_cursor.execute(sql_with_param, params)
print(turbo_cursor.fetchall())
except Exception as e:
print(e)
print('Trying pyodbc - without params') # WORKS
try:
pyodbc_cursor.execute(sql_full)
print(pyodbc_cursor.fetchall())
except Exception as e:
print(e)
print('Trying turbodbc - without params') # WORKS
try:
turbo_cursor.execute(sql_full)
print(turbo_cursor.fetchall())
except Exception as e:
print(e)
I've found when passing long strings (~2000+) to a stored procedure in MS SQL Server, where the parameter is set as varchar(max), that turbodbc reports a HY104, Invalid precision value error.
This doesn't happen with pyodbc, nor does it happen with turbodbc when the parameter is constructed as part of the SQL string; only when it is provided separately.
Strangely I also found that if the string was something like 'a'*3000 no such error occurred yet 'a123456...' as in the code below does result in error.
The example code shows:
pyodbc with string passed as parameter, works fine
turbodbc with string passed as parameter, doesn't work
pyodbc with string as part of sql text, works fine
turbodbc with string as part of sql text, works fine
SQL used for setup:
This is using ODBC Driver 17 for SQL Server and the full error message is:
The text was updated successfully, but these errors were encountered: