Skip to content

Commit 37ea27c

Browse files
committed
Fix for CONPY-224:
If a bulk operation is executed and the statement doesn't need to be reprepared, only array size has to be updated, since setting the number of parameters (STMT_ATTR_PREBIND_PARAMS) will reset the statement in Connector/C.
1 parent cb238ce commit 37ea27c

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

mariadb/mariadb_cursor.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,10 +1168,13 @@ MrdbCursor_execute_bulk(MrdbCursor *self)
11681168

11691169
/* If the server doesn't support bulk execution (< 10.2.6),
11701170
we need to call a fallback routine */
1171+
if (self->reprepare)
1172+
{
1173+
mysql_stmt_attr_set(self->stmt, STMT_ATTR_PREBIND_PARAMS, &self->parseinfo.paramcount);
1174+
mysql_stmt_attr_set(self->stmt, STMT_ATTR_CB_USER_DATA, (void *)self);
1175+
mysql_stmt_attr_set(self->stmt, STMT_ATTR_CB_PARAM, mariadb_param_update);
1176+
}
11711177
mysql_stmt_attr_set(self->stmt, STMT_ATTR_ARRAY_SIZE, &self->array_size);
1172-
mysql_stmt_attr_set(self->stmt, STMT_ATTR_PREBIND_PARAMS, &self->parseinfo.paramcount);
1173-
mysql_stmt_attr_set(self->stmt, STMT_ATTR_CB_USER_DATA, (void *)self);
1174-
mysql_stmt_attr_set(self->stmt, STMT_ATTR_CB_PARAM, mariadb_param_update);
11751178

11761179
mysql_stmt_bind_param(self->stmt, self->params);
11771180

testing/test/integration/test_cursor.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,39 @@ def test_conpy222(self):
14321432
except Exception:
14331433
pass
14341434

1435+
def test_conpy_224(self):
1436+
1437+
if is_maxscale():
1438+
self.skipTest("MAXSCALE doesn't support BULK yet")
1439+
1440+
cursor = self.connection.cursor()
1441+
1442+
cursor.execute("CREATE TEMPORARY TABLE test_inserttuple ("
1443+
"id int, name varchar(64), "
1444+
"city varchar(64))")
1445+
1446+
params = ((1, u"Jack", u"Boston"),
1447+
(2, u"Martin", u"Ohio"),
1448+
(3, u"James", u"Washington"),
1449+
(4, u"Rasmus", u"Helsinki"),
1450+
(5, u"Andrey", u"Sofia"))
1451+
1452+
cursor.executemany("INSERT INTO test_inserttuple VALUES (?,?,?)",
1453+
params)
1454+
1455+
cursor.executemany("INSERT INTO test_inserttuple VALUES (?,?,?)",
1456+
params)
1457+
1458+
cursor = self.connection.cursor()
1459+
1460+
cursor.execute("SELECT name FROM test_inserttuple ORDER BY id DESC")
1461+
1462+
row = cursor.fetchone()
1463+
1464+
self.assertEqual("Andrey", row[0])
1465+
1466+
del cursor
1467+
14351468
def test_conpy91(self):
14361469
with create_connection() as connection:
14371470
with connection.cursor() as cursor:

0 commit comments

Comments
 (0)