Skip to content

Commit 396777d

Browse files
committed
Merge branch 'BUG19282158' into develop
2 parents 911b1d3 + 9b715b8 commit 396777d

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

lib/mysql/connector/protocol.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ def make_stmt_execute(self, statement_id, data=(), parameters=(),
620620
flags = 0
621621
if value is None:
622622
null_bitmap[(pos // 8)] |= 1 << (pos % 8)
623+
types.append(utils.int1store(FieldType.NULL) +
624+
utils.int1store(flags))
623625
continue
624626
elif pos in long_data_used:
625627
if long_data_used[pos][0]:

tests/test_bugs.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,3 +2755,42 @@ def test_duplicate_optionfiles(self):
27552755
]
27562756
self.assertRaises(ValueError, mysql.connector.connect,
27572757
option_files=files)
2758+
2759+
2760+
class BugOra19282158(tests.MySQLConnectorTests):
2761+
"""BUG#19282158: NULL values with prepared statements
2762+
"""
2763+
def setUp(self):
2764+
config = tests.get_mysql_config()
2765+
self.cnx = connection.MySQLConnection(**config)
2766+
self.cursor = self.cnx.cursor()
2767+
2768+
self.tbl = 'Bug19282158'
2769+
self.cursor.execute("DROP TABLE IF EXISTS %s" % self.tbl)
2770+
2771+
create = ('CREATE TABLE {0}(col1 INT NOT NULL, col2 INT NULL, '
2772+
'col3 VARCHAR(10), col4 DECIMAL(4,2) NULL, '
2773+
'col5 DATETIME NULL, col6 INT NOT NULL, col7 VARCHAR(10), '
2774+
'PRIMARY KEY(col1))'.format(self.tbl))
2775+
2776+
self.cursor.execute(create)
2777+
2778+
def tearDown(self):
2779+
self.cursor.execute("DROP TABLE IF EXISTS %s" % self.tbl)
2780+
self.cursor.close()
2781+
self.cnx.close()
2782+
2783+
def test_null(self):
2784+
cur = self.cnx.cursor(prepared=True)
2785+
sql = ("INSERT INTO {0}(col1, col2, col3, col4, col5, col6, col7) "
2786+
"VALUES (?, ?, ?, ?, ?, ?, ?)".format(self.tbl))
2787+
params = (100, None, 'foo', None, datetime(2014, 8, 4, 9, 11, 14),
2788+
10, 'bar')
2789+
exp = (100, None, bytearray(b'foo'), None,
2790+
datetime(2014, 8, 4, 9, 11, 14), 10, bytearray(b'bar'))
2791+
cur.execute(sql, params)
2792+
2793+
sql = "SELECT * FROM {0}".format(self.tbl)
2794+
cur.execute(sql)
2795+
self.assertEqual(exp, cur.fetchone())
2796+
cur.close()

tests/test_protocol.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,14 @@ def test_make_stmt_execute(self):
535535

536536
# Testing null bitmap
537537
data = (None, None)
538-
exp = bytearray(b'\x01\x00\x00\x00\x00\x01\x00\x00\x00\x03\x01')
538+
exp = bytearray(b'\x01\x00\x00\x00\x00\x01\x00\x00\x00\x03\x01\x06'
539+
b'\x00\x06\x00')
539540
res = self._protocol.make_stmt_execute(statement_id, data, (1, 2))
540541
self.assertEqual(exp, res)
541542

542543
data = (None, 'Ham')
543544
exp = bytearray(
544-
b'\x01\x00\x00\x00\x00\x01\x00\x00\x00\x01\x01\x0f\x00'
545+
b'\x01\x00\x00\x00\x00\x01\x00\x00\x00\x01\x01\x06\x00\x0f\x00'
545546
b'\x03\x48\x61\x6d'
546547
)
547548
res = self._protocol.make_stmt_execute(statement_id, data, (1, 2))

0 commit comments

Comments
 (0)