zillow / ctds

Python DB-API 2.0 library for MS SQL Server
MIT License
83 stars 12 forks source link

nvarchar(max)/varchar(max) #13

Closed IliaLukin closed 6 years ago

IliaLukin commented 6 years ago

ctds.connect.bulk_insert not support new mssql types nvarchar(max)/varchar(max). It raise exception like "_tds.ProgrammingError: While reading current row from host, a premature end-of-message was encountered--an incoming data stream was interrupted when the server expected to see more data. The host program may have terminated. Ensure that you are using a supported client application programming interface (API)."

joshuahlang commented 6 years ago

I believe this is caused by some defect in the bcp implementation in FreeTDS when dealing with columns of VARCHAR(MAX) size. Internally FreeTDS queries the column metadata from the server prior to sending client data during the bulk insert process. When the server returns the column type as BIGVARCHRTYPE (as it is called in the TDS documentation; TDS type is 0xa7), which is the case with VARCHAR(MAX), FreeTDS doesn't seem to handle it properly. I haven't dug too deeply past that, but in my experience, the support for (N)VARCHAR(MAX) types in FreeTDS is somewhat buggy, or at least was in past versions. Hence why ctds uses the (N)TEXT type internally for large strings.

joshuahlang commented 6 years ago

https://github.com/FreeTDS/freetds/issues/192

IliaLukin commented 6 years ago

Hi! I want to thank you for work! I changed locale code in src/tds/data.c and it work's fine. I'm waiting for realese official version freetds.