Skip to content

Commit

Permalink
CONPY-218: Allow None as data parameter
Browse files Browse the repository at this point in the history
Allow None as data parameter for cursors execute()
method.
Kudos to  Luciano Barcaro for providing a fix.
  • Loading branch information
9EOR9 committed Jul 21, 2022
1 parent bd84da3 commit 205b9c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mariadb/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ def execute(self, statement: str, data: Sequence =(), buffered=None):

self._description= None

# CONPY-218: Allow None as replacement for empty tuple
data= data or ()

if len(data):
self._data= data
else:
Expand Down
18 changes: 18 additions & 0 deletions testing/test/integration/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,24 @@ def test_conpy213(self):
del cursor
del connection

def test_conpy218(self):
conn= create_connection()
cursor= conn.cursor()
cursor.execute("SELECT 1", None)
row= cursor.fetchone()
self.assertEqual(row[0], 1)
cursor.execute("SELECT 2", ())
row= cursor.fetchone()
self.assertEqual(row[0], 2)
cursor.execute("SELECT 3", [])
row= cursor.fetchone()
self.assertEqual(row[0], 3)
cursor.execute("SELECT 4", {})
row= cursor.fetchone()
self.assertEqual(row[0], 4)
del cursor
del conn

def test_conpy91(self):
with create_connection() as connection:
with connection.cursor() as cursor:
Expand Down

0 comments on commit 205b9c2

Please sign in to comment.