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

Table-Valued Parameters (TVPs) with fast_executemany #601

Closed
gordthompson opened this issue Aug 6, 2019 · 1 comment
Closed

Table-Valued Parameters (TVPs) with fast_executemany #601

gordthompson opened this issue Aug 6, 2019 · 1 comment

Comments

@gordthompson
Copy link
Collaborator

gordthompson commented Aug 6, 2019

Python version 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)]
pyodbc version 4.0.27
msodbcsql17.dll version 17.03.0001

Given the following database objects ...

/****** Object:  UserDefinedTableType [dbo].[intTable]    Script Date: 2019-08-06 08:04:34 ******/
CREATE TYPE [dbo].[intTable] AS TABLE(
    [c1] [int] NOT NULL,
    PRIMARY KEY CLUSTERED 
(
    [c1] ASC
)WITH (IGNORE_DUP_KEY = OFF)
)
GO
/****** Object:  StoredProcedure [dbo].[tvpTestProc]    Script Date: 2019-08-06 08:05:39 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[tvpTestProc] 
    @tbl intTable READONLY
AS
BEGIN
    SET NOCOUNT ON;
    INSERT INTO tvpTestTable (c1) SELECT c1 FROM @tbl;
END

GO

... the following code works fine:

crsr.execute("TRUNCATE TABLE tvpTestTable")
data = [([(1,), (2,)],) for i in range(3)]
sql = "{CALL tvpTestProc(?)}"
crsr.fast_executemany = False
crsr.executemany(sql, data)
print(crsr.execute("SELECT * FROM tvpTestTable").fetchall())
# [(1, 1), (2, 2), (3, 1), (4, 2), (5, 1), (6, 2)]

However, when I change fast_executemany to True then I get

pyodbc.ProgrammingError: ('Unknown object type list during describe', 'HY000')

I tried using both UseFMTONLY=Yes and UseFMTONLY=No and I got the same result.

SQL.LOG shows that SQLDescribeParam is successful ...

main            170c-1288	EXIT  SQLDescribeParam  with return code 0 (SQL_SUCCESS)
        HSTMT               0x006CAAB8
        UWORD                        1 
        SWORD *             0x020DDB4A (-153)
        SQLULEN *           0x020DDB4C (0)
        SWORD *             0x020DDB50 (0)
        SWORD *             0x0031F8F0 (1)

... but pyodbc appears to be unhappy with what it got back.

@v-chojas
Copy link
Contributor

v-chojas commented Aug 8, 2019

TVP is not currently supported with fast_executemany; a TVP is itself an array of parameters.

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

No branches or pull requests

2 participants