Fix for CONPY-191:

When connected to a database server which doesn't support bulk
execution, we need to set bind.is_null instead of changing the buffer
type to MYSQL_TYPE_NULL. This will keep the original buffer type.
This commit is contained in:
Georg Richter
2022-02-08 22:30:30 +01:00
parent 7b63daa9c1
commit 4855a7b21d
3 changed files with 115 additions and 99 deletions

View File

@ -236,6 +236,7 @@ typedef struct {
void *buffer;
unsigned char num[8];
MYSQL_TIME tm;
uint8_t is_null;
} MrdbParamValue;
typedef struct {

View File

@ -1298,11 +1298,12 @@ mariadb_param_to_bind(MrdbCursor *self,
bind->u.indicator[0]= value->indicator;
goto end;
}
if (!value->value)
value->is_null= value->value == NULL;
if (value->is_null)
{
bind->buffer_type= MYSQL_TYPE_NULL;
bind->is_null= (my_bool *)&value->is_null;
} else {
bind->is_null= NULL;
if (IS_NUM(bind->buffer_type))
{
bind->buffer= value->num;
@ -1313,7 +1314,6 @@ mariadb_param_to_bind(MrdbCursor *self,
if (_PyLong_Sign(value->value) < 0)
is_negative= 1;
}
}
switch(bind->buffer_type)
{
@ -1412,6 +1412,7 @@ mariadb_param_to_bind(MrdbCursor *self,
default:
rc= 1;
}
}
end:
MARIADB_BLOCK_THREADS(self);
return rc;

View File

@ -1163,6 +1163,20 @@ class TestCursor(unittest.TestCase):
del cursor
connection.close()
def test_conpy191(self):
connection= create_connection()
cursor= connection.cursor()
cursor.execute("create temporary table t1 (a int, b int, c int)")
data= [(None,1,1),(2,None,2),(3,3,None)]
cursor.executemany("INSERT INTO t1 VALUES (?,?,?)", data);
cursor.execute("SELECT a,b,c FROM t1")
result= cursor.fetchall()
self.assertEqual(data, result)
del cursor
connection.close()
def test_conpy91(self):
with create_connection() as connection:
with connection.cursor() as cursor: