Fix for CONPY-48:

According to PEP-249 parameters for cursor methods execute() and executemany() are passed as a sequence.
The current implementation accepted Tuple only, this fix also allows List as parameter.

Valid examples:

cursor.execute("SELECT %s", [1])
cursor.execute("SELECT %s", (1,))

cursor.executemany("INSERT INTO t1 VALUES (%s)", [[1],[2]])
cursor.executemany("INSERT INTO t1 VALUES (%s)", [(1,),(2,)])
cursor.executemany("INSERT INTO t1 VALUES (%s)", [[1],(2,)])
This commit is contained in:
Georg Richter
2020-04-03 18:36:54 +02:00
parent c96cb47825
commit 434a490539
3 changed files with 48 additions and 4 deletions

View File

@ -786,6 +786,22 @@ class TestCursor(unittest.TestCase):
self.assertEqual(row[0], 0)
del con
def test_conpy49(self):
con= create_connection()
cur=con.cursor()
cur.execute("select %s", [True])
row= cur.fetchone()
self.assertEqual(row[0], 1)
cur.execute("create temporary table t1 (a int)")
cur.executemany("insert into t1 values (%s)", [[1],(2,)])
cur.execute("select a from t1")
row= cur.fetchone()
self.assertEqual(row[0], 1)
row= cur.fetchone()
self.assertEqual(row[0], 2)
del con
if __name__ == '__main__':
unittest.main()