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

Ctds assumes wrong datatypes on cursor.executemany() #43

Closed
gizmo93 opened this issue Oct 31, 2018 · 1 comment
Closed

Ctds assumes wrong datatypes on cursor.executemany() #43

gizmo93 opened this issue Oct 31, 2018 · 1 comment

Comments

@gizmo93
Copy link

gizmo93 commented Oct 31, 2018

System Specs:

  • Python 3.5.4 64-Bit
  • SQL Server 2017
  • Freetds 1.00.80
  • Ctds 1.8.0

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
@joshuahlang
Copy link
Collaborator

Fixed in 1.9.0

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