When inserting a sequence of Integers using .executemany(), ctds assumes the wrong data type, if the first integer is small.
Example:
CREATE TABLE TestTable
(
Number INT NULL,
)
with ctds.connect('server', database='database') as con:
with con.cursor() as cursor:
data = [(1,), (30000,), (0, )]
query = 'INSERT INTO TestTable (Number) VALUES (:0)'
cursor.executemany(query, data)
con.commit()
leads to" _tds.DataError: Error converting data type smallint to tinyint.".
The reason is the created INSERT Statement, which assumes datatype tinyint for this column, as we can see in SQL Server Profiler:
exec sp_executesql N'INSERT INTO TestTable (Number) VALUES (@param0)',N'@param0 TINYINT',1
go
exec sp_executesql N'INSERT INTO TestTable (Number) VALUES (@param0)',N'@param0 TINYINT',30000
go
System Specs:
When inserting a sequence of Integers using .executemany(), ctds assumes the wrong data type, if the first integer is small.
Example:
leads to" _tds.DataError: Error converting data type smallint to tinyint.".
The reason is the created INSERT Statement, which assumes datatype tinyint for this column, as we can see in SQL Server Profiler: