Skip to content

Commit

Permalink
Fix for issue 617 (#623)
Browse files Browse the repository at this point in the history
* Merging updates. (#1)

Merging updates.

* fix for smalldatetime issue

* Fixed a bad merge

* Fix for inserting high unicode chars

* merge with main branch

* Fix for function sequence error

* reverted unnecessary file changes

* removed obsolete include

* fix for 540

* fix for TVP type mismatch issue

* Combined the IFs

* Fix for high unicode insertion, WIP

* Fix python2 high unicode insertion

* Renamed a table to t1
  • Loading branch information
v-makouz authored and mkleehammer committed Oct 10, 2019
1 parent be667ab commit 969ea2c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1910,12 +1910,11 @@ bool ExecuteMulti(Cursor* cur, PyObject* pSql, PyObject* paramArrayObj)
{
PyObject* objCell = pInfo->cell;

#if PY_MAJOR_VERSION >= 3
// If the object is Unicode it needs to be converted into bytes before it can be used by SQLPutData
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 All @@ -1941,7 +1940,6 @@ bool ExecuteMulti(Cursor* cur, PyObject* pSql, PyObject* paramArrayObj)
objCell = bytes;
}
}
#endif

szLastFunction = "SQLPutData";
if (PyBytes_Check(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 = u"🎥"
self.cursor.fast_executemany = True
self.cursor.execute("CREATE TABLE t1 (col1 nvarchar(max) null)")
self.cursor.executemany("INSERT INTO t1 (col1) VALUES (?)", [[v,]])
self.assertEqual(self.cursor.execute("SELECT * FROM t1").fetchone()[0], 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 t1 (col1 nvarchar(max) null)")
self.cursor.executemany("INSERT INTO t1 (col1) VALUES (?)", [[v,]])
self.assertEqual(self.cursor.execute("SELECT * FROM t1").fetchone()[0], v)

#
# binary
#
Expand Down

0 comments on commit 969ea2c

Please sign in to comment.