Closed stelo-lg closed 7 months ago
Try using
cursor.setinputsizes([None, (pyodbc.SQL_WVARCHAR, 50, 0)])
before you call .execute()
Thank you very much. This solved my problem.
However, I observed another odd behaviour. This works for the given example query. But if my query looks like this, I get the same error message again:
query = """IF NOT EXISTS
(SELECT designation FROM test_table WHERE designation = ?)
BEGIN
INSERT INTO test_table (designation, label) VALUES (?, ?)
END"""
Do you have any idea why that might be?
You need to set the type for the appropriate parameter(s). See the documentation for setinputsizes.
In that case you would need to use an extra None
to modify the third parameter instead of the second
cursor.setinputsizes([None, None, (pyodbc.SQL_WVARCHAR, 50, 0)])
Environment
Issue
I am using pyodbc to write into an always encrypted database.
If I want to write a NULL value into an encrypted column it is not working:
Both columns are encrypted. The error message I get for the column I am trying to insert NULL/None is:
It is working fine if I execute a similar parameterized statement in the SQL Management Studio and insert a NULL.
Is this a bug or am I doing something wrong? It seems like it is encrypting the None to a varchar(1) string. How can i prevent this?