Skip to content

Commit

Permalink
Fix for high unicode insertion, WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Kouznetsov committed Sep 10, 2019
1 parent e2e899f commit 606b4a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@ bool ExecuteMulti(Cursor* cur, PyObject* pSql, PyObject* paramArrayObj)
if (PyUnicode_Check(objCell))
{
const TextEnc& enc = cur->cnxn->sqlwchar_enc;
int cb = PyUnicode_GET_LENGTH(objCell);
int cb = PyUnicode_GET_DATA_SIZE(objCell) / 2;

PyObject* bytes = NULL;
const Py_UNICODE* source = PyUnicode_AS_UNICODE(objCell);
Expand Down
7 changes: 7 additions & 0 deletions tests2/sqlservertests.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,13 @@ def test_fast_executemany_to_datetime2(self):
self.cursor.executemany(sql, params)
self.assertEqual(self.cursor.execute("SELECT CAST(dt2 AS VARCHAR) FROM ##issue540").fetchval(), '2019-03-12 10:00:00.12')

def test_high_unicode(self):
v = "🎥"
self.cursor.fast_executemany = True
self.cursor.execute("CREATE TABLE test_high_unicode (col1 nvarchar(max) null)")
self.cursor.executemany("INSERT INTO test_high_unicode (col1) VALUES (?)", [[v,]])
self.assertEqual(self.cursor.execute("SELECT * FROM test_high_unicode").fetchone()[0].encode('utf-8'), v)

#
# binary
#
Expand Down
7 changes: 7 additions & 0 deletions tests3/sqlservertests.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ def test_fast_executemany_to_datetime2(self):
self.cursor.executemany(sql, params)
self.assertEqual(self.cursor.execute("SELECT CAST(dt2 AS VARCHAR) FROM ##issue540").fetchval(), '2019-03-12 10:00:00.12')

def test_high_unicode(self):
v = "🎥"
self.cursor.fast_executemany = True
self.cursor.execute("CREATE TABLE test_high_unicode (col1 nvarchar(max) null)")
self.cursor.executemany("INSERT INTO test_high_unicode (col1) VALUES (?)", [[v,]])
self.assertEqual(self.cursor.execute("SELECT * FROM test_high_unicode").fetchone()[0], v)

#
# binary
#
Expand Down

0 comments on commit 606b4a9

Please sign in to comment.