Skip to content

Commit d35d172

Browse files
committed
Fix for CONPY-61:
Fixed regression bug - When checking parameter types for execute many, we need to check if an indicator variable (or None) was passed.
1 parent 3028132 commit d35d172

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/mariadb_codecs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -946,13 +946,12 @@ mariadb_get_parameter_info(MrdbCursor *self,
946946
param->buffer_type= pinfo.type;
947947
bits= (uint32_t)pinfo.bits;
948948
}
949-
950-
for (i=0; i < self->array_size; i++)
949+
else for (i=0; i < self->array_size; i++)
951950
{
952951
if (mariadb_get_parameter(self, 1, i, column_nr, &paramvalue))
953952
return 1;
954953
memset(&pinfo, 0, sizeof(MrdbParamInfo));
955-
if (mariadb_get_column_info(paramvalue.value, &pinfo))
954+
if (mariadb_get_column_info(paramvalue.value, &pinfo) && !paramvalue.indicator)
956955
{
957956
mariadb_throw_exception(NULL, Mariadb_DataError, 1,
958957
"Invalid parameter type at row %d, column %d",
@@ -980,11 +979,12 @@ mariadb_get_parameter_info(MrdbCursor *self,
980979
else {
981980
/* except for NULL the parameter types must match */
982981
if (param->buffer_type != pinfo.type &&
983-
pinfo.type != MYSQL_TYPE_NULL)
982+
pinfo.type != MYSQL_TYPE_NULL &&
983+
!paramvalue.indicator)
984984
{
985985
if ((param->buffer_type == MYSQL_TYPE_TINY ||
986-
param->buffer_type == MYSQL_TYPE_SHORT ||
987-
param->buffer_type == MYSQL_TYPE_LONG) &&
986+
param->buffer_type == MYSQL_TYPE_SHORT ||
987+
param->buffer_type == MYSQL_TYPE_LONG) &&
988988
pinfo.type == MYSQL_TYPE_LONGLONG)
989989
break;
990990
mariadb_throw_exception(NULL, Mariadb_DataError, 1,

test/integration/test_cursor.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,14 @@ def test_indicator(self):
382382

383383
cursor = self.connection.cursor()
384384
cursor.execute("CREATE TEMPORARY TABLE ind1 (a int, b int default 2,c int)")
385-
vals = (mariadb.indicator_null, mariadb.indicator_default, 3)
386-
cursor.executemany("INSERT INTO ind1 VALUES (?,?,?)", [vals])
385+
vals = [(1,4,3),(mariadb.indicator_null, mariadb.indicator_default, 3)]
386+
cursor.executemany("INSERT INTO ind1 VALUES (?,?,?)", vals)
387387
cursor.execute("SELECT a, b, c FROM ind1")
388388
row = cursor.fetchone()
389+
self.assertEqual(row[0], 1)
390+
self.assertEqual(row[1], 4)
391+
self.assertEqual(row[2], 3)
392+
row = cursor.fetchone()
389393
self.assertEqual(row[0], None)
390394
self.assertEqual(row[1], 2)
391395
self.assertEqual(row[2], 3)
@@ -889,5 +893,30 @@ def test_conpy59(self):
889893
self.assertEqual(row[0], None)
890894
del con
891895

896+
def test_conpy61(self):
897+
con= create_connection()
898+
cursor=con.cursor()
899+
cursor.execute("CREATE TEMPORARY TABLE ind1 (a int, b int default 2,c int)")
900+
vals = [(1,4,3),(None, 2, 3)]
901+
cursor.executemany("INSERT INTO ind1 VALUES (?,?,?)", vals)
902+
cursor.execute("SELECT a, b, c FROM ind1")
903+
row= cursor.fetchone()
904+
self.assertEqual(row[0], 1)
905+
row= cursor.fetchone()
906+
self.assertEqual(row[0], None)
907+
cursor.execute("DELETE FROM ind1")
908+
vals=[(1,4,3), (mariadb.indicator_null, mariadb.indicator_default, None)]
909+
910+
cursor.executemany("INSERT INTO ind1 VALUES (?,?,?)", vals)
911+
cursor.execute("SELECT a, b, c FROM ind1")
912+
row= cursor.fetchone()
913+
self.assertEqual(row[0], 1)
914+
row= cursor.fetchone()
915+
self.assertEqual(row[0], None)
916+
self.assertEqual(row[1], 2)
917+
self.assertEqual(row[2], None)
918+
919+
del cursor
920+
892921
if __name__ == '__main__':
893922
unittest.main()

0 commit comments

Comments
 (0)