Added internal members for client and server capabilities to

MrdbConnection class.
This commit is contained in:
Georg Richter
2020-06-18 10:23:56 +02:00
parent 5fd14c9ce2
commit ea8354bb8b
4 changed files with 27 additions and 18 deletions

View File

@ -174,6 +174,10 @@ typedef struct {
uint8_t inuse;
uint8_t status;
struct timespec last_used;
/* capabilities */
unsigned long client_capabilities;
unsigned long server_capabilities;
unsigned long extended_server_capabilities;
} MrdbConnection;
typedef struct mrdb_pool{

View File

@ -837,11 +837,7 @@ mariadb_get_parameter(MrdbCursor *self,
{
PyObject *row= NULL,
*column= NULL;
ulong extended_server_capabilities= 0;
mariadb_get_infov(self->stmt->mysql,
MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES,
&extended_server_capabilities);
if (is_bulk)
{
/* check if row_nr and column_nr are in the range from
@ -892,7 +888,8 @@ mariadb_get_parameter(MrdbCursor *self,
/* check if an indicator was passed */
if (MrdbIndicator_Check(column))
{
if (!(extended_server_capabilities & (MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32)))
if (!(self->connection->extended_server_capabilities &
(MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32)))
{
mariadb_throw_exception(NULL, Mariadb_DataError, 0,
"MariaDB %s doesn't support indicator variables. "\
@ -904,7 +901,8 @@ mariadb_get_parameter(MrdbCursor *self,
param->value= NULL; /* you can't have both indicator and value */
} else if (column == Py_None) {
param->value= NULL;
if (extended_server_capabilities & (MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32))
if (self->connection->extended_server_capabilities &
(MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32))
{
param->indicator= STMT_INDICATOR_NULL;
}

View File

@ -252,6 +252,17 @@ PyMemberDef MrdbConnection_Members[] =
{NULL} /* always last */
};
static void MrdbConnection_GetCapabilities(MrdbConnection *self)
{
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_SERVER_CAPABILITIES,
&self->server_capabilities);
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES,
&self->extended_server_capabilities);
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_CLIENT_CAPABILITIES,
&self->client_capabilities);
}
static void
Mrdb_ConnAttrStr(MYSQL *mysql, PyObject **obj, enum mariadb_value attr)
{
@ -416,6 +427,8 @@ end:
/* set connection attributes */
MrdbConnection_SetAttributes(self);
/* get capabilities */
MrdbConnection_GetCapabilities(self);
return 0;
}
@ -1171,6 +1184,8 @@ PyObject *MrdbConnection_reconnect(MrdbConnection *self)
mariadb_throw_exception(self->mysql, NULL, 0, NULL);
return NULL;
}
/* get capabilities */
MrdbConnection_GetCapabilities(self);
Py_RETURN_NONE;
}
/* }}} */

View File

@ -722,21 +722,16 @@ PyObject *MrdbCursor_execute(MrdbCursor *self,
}
if (do_prepare)
{
ulong extended_server_capabilities= 0;
mysql_stmt_attr_set(self->stmt, STMT_ATTR_PREBIND_PARAMS, &self->param_count);
mysql_stmt_attr_set(self->stmt, STMT_ATTR_CB_USER_DATA, (void *)self);
mysql_stmt_bind_param(self->stmt, self->params);
mariadb_get_infov(self->stmt->mysql,
MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES,
&extended_server_capabilities);
Py_BEGIN_ALLOW_THREADS;
/* execute_direct was implemented together with bulk operations, so we need
to check if MARIADB_CLIENT_STMT_BULK_OPERATIONS is set in extended server
capabilities */
if (!(extended_server_capabilities & (MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32)))
if (!(self->connection->extended_server_capabilities &
(MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32)))
{
rc= mysql_stmt_prepare(self->stmt, self->parser->statement.str,
(unsigned long)self->parser->statement.length);
@ -1270,7 +1265,6 @@ MrdbCursor_executemany(MrdbCursor *self,
uint8_t do_prepare= 1;
char errmsg[128];
MARIADB_CHECK_STMT(self);
unsigned long extended_server_capabilities= 0;
if (PyErr_Occurred())
{
@ -1324,10 +1318,8 @@ MrdbCursor_executemany(MrdbCursor *self,
/* If the server doesn't support bulk execution (< 10.2.6),
we need to call a fallback routine */
mariadb_get_infov(self->stmt->mysql,
MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES,
&extended_server_capabilities);
if (!(extended_server_capabilities & (MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32)))
if (!(self->connection->extended_server_capabilities &
(MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32)))
{
if (MrdbCursor_executemany_fallback(self, self->parser->statement.str,
self->parser->statement.length))