Skip to content

Commit

Permalink
Test for issue 506 (#518)
Browse files Browse the repository at this point in the history
* Fix double-decref on fast_executemany error return path. (#504)

* test for null termination fix (issue #506)
  • Loading branch information
gordthompson authored and mkleehammer committed Feb 2, 2019
1 parent 3cb443a commit 9597e6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1813,12 +1813,14 @@ bool ExecuteMulti(Cursor* cur, PyObject* pSql, PyObject* paramArrayObj)
// "schema change" or conversion error. Try again on next batch.
rowptr--;
Py_XDECREF(colseq);
colseq = 0;
// Finish this batch of rows and attempt to execute before starting another.
goto DoExecute;
}
}
rows_converted++;
Py_XDECREF(colseq);
colseq = 0;
r++;
if ( r >= rowcount )
{
Expand Down
20 changes: 20 additions & 0 deletions tests3/sqlservertests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,26 @@ def test_columns(self):
assert row.type_name == 'varchar'
assert row.column_size == 4, row.column_size

# <test null termination fix (issue #506)>
for i in range(8, 16):
table_name = 'pyodbc_89abcdef'[:i]

self.cursor.execute("""\
BEGIN TRY
DROP TABLE {0};
END TRY
BEGIN CATCH
END CATCH
CREATE TABLE {0} (id INT PRIMARY KEY);
""".format(table_name))

col_count = len([col.column_name for col in self.cursor.columns(table_name)])
# print('table [{}] ({} characters): {} columns{}'.format(table_name, i, col_count, ' <-' if col_count == 0 else ''))
self.assertEqual(col_count, 1)

self.cursor.execute("DROP TABLE {};".format(table_name))
# </test null termination fix (issue #506)>

def test_cancel(self):
# I'm not sure how to reliably cause a hang to cancel, so for now we'll settle with
# making sure SQLCancel is called correctly.
Expand Down

0 comments on commit 9597e6b

Please sign in to comment.