anthony-tuininga/ceODBC

String data, right truncation

Opened this issue · 1 comments

EDIT: I created a new issue instead of commenting on a closed one...

EDIT: I'm running:

  • Python '3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]'
  • ceODBC 3.1

EDIT: Added ODBC trace:
SQL.LOG

Given this table declaration:

CREATE TABLE strings (
	id int NOT NULL,
	[data] nvarchar(400) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	CONSTRAINT PK__strings__3213E83FDE156BB0 PRIMARY KEY (id),
	CONSTRAINT UQ__strings__D9DE21E1EE0369BF UNIQUE ([data])
);

And the following Python code::

import ceODBC

dsn = "DRIVER={ODBC Driver 13 for SQL Server};SERVER=%s;DATABASE=%s;UID=%s;PWD=%s" % (
    server,
    database,
    uid,
    pwd,
)
db_connection = ceODBC.connect(dsn)
cursor = db_connection.cursor()
cursor.execute("INSERT INTO strings VALUES (1, ?)", "²")

I get the following error:

Traceback (most recent call last):
File "mini.py", line 13, in
cursor.execute("INSERT INTO strings VALUES (1, ?)", "²")
File "src\ceODBC\cursor.pyx", line 423, in ceODBC.driver.Cursor.execute
File "src\ceODBC\cursor.pyx", line 268, in ceODBC.driver.Cursor._execute
File "src\ceODBC\errors.pyx", line 31, in ceODBC.driver._check_stmt_error
File "src\ceODBC\errors.pyx", line 23, in ceODBC.driver._check_error
File "src\ceODBC\errors.pyx", line 67, in ceODBC.driver._raise_from_odbc
File "src\ceODBC\errors.pyx", line 83, in ceODBC.driver._raise_from_string
ceODBC.exceptions.DatabaseError: [Microsoft][ODBC Driver 13 for SQL Server]String data, right truncation

I don't have access to SQL Server, but it sounds like an encoding issue. Can you specify the use of UTF-8 in the connect string and does that resolve the issue?