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

Send PLP_UNKNOWN for VARBINARY(MAX) too #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gizmo93
Copy link

@gizmo93 gizmo93 commented Mar 15, 2022

Hey!
It seems like the same handling which is used for NVARCHAR(MAX) and VARCHAR(MAX) needs to be applied to VARBINARY(MAX).

Create a new table like this:

DROP TABLE IF EXISTS BulkInsertTest;
CREATE TABLE BulkInsertTest
(
Id INT NOT NULL PRIMARY KEY IDENTITY (1,1),
Bin VARBINARY(MAX) NULL,
)

data = [
        {'Bin': 'aaa'.encode('utf-8'),}
        for i in range(100_000)
    ]

with con2.cursor() as cursor:
    cursor.copy_to(
        table_or_view='BulkInsertTest',
        schema='dbo',
        columns=[
            pytds.Column('Bin', type=pytds.tds_types.VarBinaryMaxType(), flags=1),
        ],
        data=[
            tuple(el.values())
            for el in data
        ]
    )
    con2.commit()

Leads to:

pytds.tds_base.OperationalError: 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).

With the fix here it works.

(Sorry for the first attempt, i was already too tired when I undid the fix to test it ;))
Greetz
Danny

@takoau
Copy link
Contributor

takoau commented Dec 16, 2022

@gizmo93 this fix makes sense. Will find some time to test your case next week.

Copy link
Contributor

@takoau takoau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it makes sense not to send payload length for varbinary(max)

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

Successfully merging this pull request may close these issues.

3 participants