Python: Python 3.11.6 (tags/v3.11.6:8b6ee5b, Oct 2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)] on win32
pyodbc: 5.0.1
OS: Windows 11
DB: SQL Server
driver: MSODBCSQL17.dll
Issue
Attempting to retrieve the message when using executemany. Using a single execution, I am able to output the messages, but I have not determined how to invoke the SQLGetDiagRec when using executemany.
The sample procedure shows the INFO messages when I also do a raiserror but if the raiserror is not present I am unable to output the print message(s).
Repro
'''
use tempdb
go
drop table if exists t
go
drop procedure if exists spTest
go
create table t
(
id int,
id2 int
)
go
create procedure spTest
@id int,
@id2 int
as
begin
insert into t values (@id, @id2)
print 'In the procedure'
-- raiserror('Bob', 16, 1) -- If I add this then I get all the print messages
end
go
Issue
Attempting to retrieve the message when using executemany. Using a single execution, I am able to output the messages, but I have not determined how to invoke the SQLGetDiagRec when using executemany.
The sample procedure shows the INFO messages when I also do a raiserror but if the raiserror is not present I am unable to output the print message(s).
Repro
''' use tempdb go
drop table if exists t go drop procedure if exists spTest go
create table t ( id int, id2 int ) go
create procedure spTest @id int, @id2 int as begin insert into t values (@id, @id2) print 'In the procedure' -- raiserror('Bob', 16, 1) -- If I add this then I get all the print messages end go
'''
import pyodbc
connection_string = ''' DRIVER={ODBC Driver 17 for SQL Server}; SERVER=localhost; DATABASE=tempdb; UID=sa; PWD=xxxxxxxxxxx; '''
Creates the connection
conn = pyodbc.connect(connection_string) conn.autocommit = False
cursor = conn.cursor() params = [(i,i) for i in range(10)] cursor.fast_executemany = True
cursor.executemany("{call spTest(?, ?)}", params)
This works but the ExecuteMany I am unable to get the calls to SQLGetDiagRec for messages
cursor.execute("{call spTest(1, 2)}")
print(cursor.rowcount) print(cursor.messages)
while(cursor.nextset()): print(cursor.messages)
cursor.commit() # Does not show any information message here either but this can have them cursor.close()