turbodbc: Invalid precision value when inserting long string on nvarchar(max) column (Microsoft Driver 13.1)
Hi. Im using:
- Ubuntu 16.04
- Python 3.6.4
- Microsoft Driver 13.1
- turbODBC 2.4.1
- Azure SQL Database
Im getting this exception when I try to insert a string of length 1600+ in a nvarchar(max) column. I already tried setting to True the limit_varchar_results_to_max parameter.
turbodbc_intern.Error: ODBC error
state: HY104
native error code: 0
message: [Microsoft][ODBC Driver 13 for SQL Server]Invalid precision value
Thanks.
About this issue
- Original URL
- State: open
- Created 9 years ago
- Reactions: 1
- Comments: 28 (3 by maintainers)
No, I am currently a bit under water with my day job. So I have to restrict my Open Source activity to there I am the main contributer.
Still, to make it clear, the Hypothesis I stated above turned out to be true. With that knowledge the change shouldn’t be to hard to implement.
Additional statement, the Invalid Precision behavior triggered earlier, i.e. with smaller strings, in turbodbc than in arrow-odbc. This hints at a Bug in the calculation of the column size of the relational type in turbodbc.
The largest Utf16 code point is 3 * 16 Bit integers. The largest Utf8 code point is 4 * 8 Bit integers.
The trying size for which the behavior triggers in turbodbc is consistent with mixing up and applying factor 4 instead of 3 for wide encodings.
Unlikely to contribute myself, but happy to drop the hint.
fetch_wchar_as_charmeans it will bind a narrow encoding as a C-Type even if the relational type indicates that this column is using a wide encoding.Speaking more of ODBC than
turbodbcin particular here:fetch_wchar_as_chartoFalseandprefer_unicodetoTrue.fetch_wchar_as_chartoTrueandprefer_unicodetoFalse.By default
turbodbcsets both toFalse. This meansturbodbcis asking the question “How is the text encoded in the database?” however the better question to ask is “What is the system encoding in the client system?”. For Linux the answer is usually UTF-8 and for Windows the answer is usually a local extended ASCII standard, which is different depending on the region. As time of this writing a UTF-8 local for Windows 11 can be enabled but is considered an experimental Beta.This would make fetching everything as wide characters which is always defined to be UTF-16 a way which works on every platform, if only all the drivers would stick to the standard. In practice Linux drivers tend to have poor implementations for wide encodings.
I have the same problem. @MathMagique, do you have some news about this error ?