mirror of
https://github.com/mariadb-corporation/mariadb-connector-python.git
synced 2025-08-02 00:22:02 +00:00
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:
@ -236,6 +236,7 @@ typedef struct {
|
|||||||
void *buffer;
|
void *buffer;
|
||||||
unsigned char num[8];
|
unsigned char num[8];
|
||||||
MYSQL_TIME tm;
|
MYSQL_TIME tm;
|
||||||
|
uint8_t is_null;
|
||||||
} MrdbParamValue;
|
} MrdbParamValue;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -1298,11 +1298,12 @@ mariadb_param_to_bind(MrdbCursor *self,
|
|||||||
bind->u.indicator[0]= value->indicator;
|
bind->u.indicator[0]= value->indicator;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
value->is_null= value->value == NULL;
|
||||||
if (!value->value)
|
if (value->is_null)
|
||||||
{
|
{
|
||||||
bind->buffer_type= MYSQL_TYPE_NULL;
|
bind->is_null= (my_bool *)&value->is_null;
|
||||||
} else {
|
} else {
|
||||||
|
bind->is_null= NULL;
|
||||||
if (IS_NUM(bind->buffer_type))
|
if (IS_NUM(bind->buffer_type))
|
||||||
{
|
{
|
||||||
bind->buffer= value->num;
|
bind->buffer= value->num;
|
||||||
@ -1313,7 +1314,6 @@ mariadb_param_to_bind(MrdbCursor *self,
|
|||||||
if (_PyLong_Sign(value->value) < 0)
|
if (_PyLong_Sign(value->value) < 0)
|
||||||
is_negative= 1;
|
is_negative= 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
switch(bind->buffer_type)
|
switch(bind->buffer_type)
|
||||||
{
|
{
|
||||||
@ -1412,6 +1412,7 @@ mariadb_param_to_bind(MrdbCursor *self,
|
|||||||
default:
|
default:
|
||||||
rc= 1;
|
rc= 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
end:
|
end:
|
||||||
MARIADB_BLOCK_THREADS(self);
|
MARIADB_BLOCK_THREADS(self);
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -1163,6 +1163,20 @@ class TestCursor(unittest.TestCase):
|
|||||||
del cursor
|
del cursor
|
||||||
connection.close()
|
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):
|
def test_conpy91(self):
|
||||||
with create_connection() as connection:
|
with create_connection() as connection:
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
|
Reference in New Issue
Block a user