Skip to content

Commit

Permalink
Fix for CONPY-61:
Browse files Browse the repository at this point in the history
Fixed regression bug - When checking parameter types for execute many, we
need to check if an indicator variable (or None) was passed.
  • Loading branch information
9EOR9 committed May 5, 2020
1 parent 3028132 commit d35d172
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/mariadb_codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,13 +946,12 @@ mariadb_get_parameter_info(MrdbCursor *self,
param->buffer_type= pinfo.type;
bits= (uint32_t)pinfo.bits;
}

for (i=0; i < self->array_size; i++)
else for (i=0; i < self->array_size; i++)
{
if (mariadb_get_parameter(self, 1, i, column_nr, &paramvalue))
return 1;
memset(&pinfo, 0, sizeof(MrdbParamInfo));
if (mariadb_get_column_info(paramvalue.value, &pinfo))
if (mariadb_get_column_info(paramvalue.value, &pinfo) && !paramvalue.indicator)
{
mariadb_throw_exception(NULL, Mariadb_DataError, 1,
"Invalid parameter type at row %d, column %d",
Expand Down Expand Up @@ -980,11 +979,12 @@ mariadb_get_parameter_info(MrdbCursor *self,
else {
/* except for NULL the parameter types must match */
if (param->buffer_type != pinfo.type &&
pinfo.type != MYSQL_TYPE_NULL)
pinfo.type != MYSQL_TYPE_NULL &&
!paramvalue.indicator)
{
if ((param->buffer_type == MYSQL_TYPE_TINY ||
param->buffer_type == MYSQL_TYPE_SHORT ||
param->buffer_type == MYSQL_TYPE_LONG) &&
param->buffer_type == MYSQL_TYPE_SHORT ||
param->buffer_type == MYSQL_TYPE_LONG) &&
pinfo.type == MYSQL_TYPE_LONGLONG)
break;
mariadb_throw_exception(NULL, Mariadb_DataError, 1,
Expand Down
33 changes: 31 additions & 2 deletions test/integration/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,14 @@ def test_indicator(self):

cursor = self.connection.cursor()
cursor.execute("CREATE TEMPORARY TABLE ind1 (a int, b int default 2,c int)")
vals = (mariadb.indicator_null, mariadb.indicator_default, 3)
cursor.executemany("INSERT INTO ind1 VALUES (?,?,?)", [vals])
vals = [(1,4,3),(mariadb.indicator_null, mariadb.indicator_default, 3)]
cursor.executemany("INSERT INTO ind1 VALUES (?,?,?)", vals)
cursor.execute("SELECT a, b, c FROM ind1")
row = cursor.fetchone()
self.assertEqual(row[0], 1)
self.assertEqual(row[1], 4)
self.assertEqual(row[2], 3)
row = cursor.fetchone()
self.assertEqual(row[0], None)
self.assertEqual(row[1], 2)
self.assertEqual(row[2], 3)
Expand Down Expand Up @@ -889,5 +893,30 @@ def test_conpy59(self):
self.assertEqual(row[0], None)
del con

def test_conpy61(self):
con= create_connection()
cursor=con.cursor()
cursor.execute("CREATE TEMPORARY TABLE ind1 (a int, b int default 2,c int)")
vals = [(1,4,3),(None, 2, 3)]
cursor.executemany("INSERT INTO ind1 VALUES (?,?,?)", vals)
cursor.execute("SELECT a, b, c FROM ind1")
row= cursor.fetchone()
self.assertEqual(row[0], 1)
row= cursor.fetchone()
self.assertEqual(row[0], None)
cursor.execute("DELETE FROM ind1")
vals=[(1,4,3), (mariadb.indicator_null, mariadb.indicator_default, None)]

cursor.executemany("INSERT INTO ind1 VALUES (?,?,?)", vals)
cursor.execute("SELECT a, b, c FROM ind1")
row= cursor.fetchone()
self.assertEqual(row[0], 1)
row= cursor.fetchone()
self.assertEqual(row[0], None)
self.assertEqual(row[1], 2)
self.assertEqual(row[2], None)

del cursor

if __name__ == '__main__':
unittest.main()

0 comments on commit d35d172

Please sign in to comment.