Skip to content

Connection messages lost in presence of preceding result set #9

@craigahobbs

Description

@craigahobbs

Run the following code and notice the output:

import ctds

connection = ctds.connect(
    'localhost',
    user='sa',
    password='password',
    database='Mortgage'
)
with connection.cursor() as cursor:
    cursor.execute('''\
SELECT N'Before';

DECLARE @Cmd NVARCHAR(MAX);
SET @Cmd = N'RAISERROR(@Msg,@Severity,10) WITH NOWAIT;';
EXEC sp_executesql @Cmd,
                   N'@Msg NVARCHAR(MAX),@Severity INT',
                   N'Hello!,'
                   0;

SELECT N'After';
''')
    for message in connection.messages:
        print('=== msg ===', message['description'])
    while cursor.description:
        row = cursor.fetchone()
        if row:
            print('=== row ===', row[0])
        else:
            print('=== row === weird, null row in result set???')
        cursor.nextset()

Actual output:

=== row === Before
=== row === weird, null row in result set???
=== row === After

Expected output:

=== msg === Hello!
=== row === Before
=== row === After

Notice the message is lost in the actual case and also the unexpected null row. If you comment out the "Before" select you get the message and you don't get the unexpected null row.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions