mirror of
https://github.com/mariadb-corporation/mariadb-connector-python.git
synced 2025-07-28 06:40:03 +00:00
Removed converter from C Code
This commit is contained in:
@ -189,13 +189,7 @@ typedef struct {
|
||||
uint8_t status;
|
||||
uint8_t asynchronous;
|
||||
struct timespec last_used;
|
||||
/* capabilities */
|
||||
// unsigned long client_capabilities;
|
||||
// unsigned long server_capabilities;
|
||||
unsigned long extended_server_capabilities;
|
||||
PyThreadState *thread_state;
|
||||
PyObject *converter;
|
||||
// unsigned long server_version;
|
||||
unsigned long thread_id;
|
||||
char *server_info;
|
||||
} MrdbConnection;
|
||||
|
@ -41,28 +41,6 @@ int codecs_datetime_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *ma_convert_value(MrdbCursor *self,
|
||||
enum enum_field_types type,
|
||||
PyObject *value)
|
||||
{
|
||||
PyObject *key= PyLong_FromLongLong(type);
|
||||
PyObject *func;
|
||||
PyObject *new_value= NULL;
|
||||
|
||||
if (!self->connection->converter || value == Py_None)
|
||||
return NULL;
|
||||
|
||||
if ((func= PyDict_GetItem(self->connection->converter, key)) &&
|
||||
PyCallable_Check(func))
|
||||
{
|
||||
PyObject *arglist= PyTuple_New(1);
|
||||
PyTuple_SetItem(arglist, 0, value);
|
||||
new_value= PyObject_CallObject(func, arglist);
|
||||
}
|
||||
return new_value;
|
||||
}
|
||||
|
||||
|
||||
enum enum_extended_field_type mariadb_extended_field_type(const MYSQL_FIELD *field)
|
||||
{
|
||||
#if MARIADB_PACKAGE_VERSION_ID > 30107
|
||||
@ -563,21 +541,7 @@ field_fetch_fromtext(MrdbCursor *self, char *data, unsigned int column)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* check if values need to be converted */
|
||||
if (self->connection->converter)
|
||||
{
|
||||
PyObject *val;
|
||||
enum enum_field_types type;
|
||||
|
||||
if (ext_type == EXT_TYPE_JSON)
|
||||
type= MYSQL_TYPE_JSON;
|
||||
else
|
||||
type= self->fields[column].type;
|
||||
|
||||
if ((val= ma_convert_value(self, type, self->values[column])))
|
||||
self->values[column]= val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* field_fetch_callback
|
||||
This function was previously registered with mysql_stmt_attr_set and
|
||||
@ -808,22 +772,7 @@ field_fetch_callback(void *data, unsigned int column, unsigned char **row)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* check if values need to be converted */
|
||||
if (self->connection->converter)
|
||||
{
|
||||
PyObject *val;
|
||||
enum enum_field_types type;
|
||||
|
||||
if (ext_type == EXT_TYPE_JSON)
|
||||
type= MYSQL_TYPE_JSON;
|
||||
else
|
||||
type= self->fields[column].type;
|
||||
|
||||
if ((val= ma_convert_value(self, type, self->values[column])))
|
||||
self->values[column]= val;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
mariadb_get_column_info
|
||||
This function analyzes the Python object and calculates the corresponding
|
||||
|
@ -39,7 +39,6 @@ char *dsn_keys[]= {
|
||||
"client_flag", "pool_name", "pool_size",
|
||||
"pool_reset_connection", "plugin_dir",
|
||||
"username", "db", "passwd",
|
||||
"converter", "asynchronous",
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -155,11 +154,6 @@ PyMemberDef MrdbConnection_Members[] =
|
||||
offsetof(MrdbConnection, thread_id),
|
||||
READONLY,
|
||||
"Id of current connection."},
|
||||
{"converter",
|
||||
T_OBJECT,
|
||||
offsetof(MrdbConnection, converter),
|
||||
READONLY,
|
||||
"Conversion dictionary"},
|
||||
{"dsn",
|
||||
T_OBJECT,
|
||||
offsetof(MrdbConnection, dsn),
|
||||
@ -188,11 +182,9 @@ MrdbConnection_Initialize(MrdbConnection *self,
|
||||
unsigned int local_infile= 0xFF;
|
||||
unsigned int connect_timeout=0, read_timeout=0, write_timeout=0,
|
||||
compress= 0, ssl_verify_cert= 0;
|
||||
PyObject *converter= NULL;
|
||||
PyObject *asynchronous= NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, dsnargs,
|
||||
"|zzzzziziiibbzzzzzzzzzzibizibzzzzO!OO!:connect",
|
||||
"|zzzzziziiibbzzzzzzzzzzibizibzzzz:connect",
|
||||
dsn_keys,
|
||||
&dsn, &host, &user, &password, &schema, &port, &socket,
|
||||
&connect_timeout, &read_timeout, &write_timeout,
|
||||
@ -203,10 +195,7 @@ MrdbConnection_Initialize(MrdbConnection *self,
|
||||
&ssl_verify_cert, &ssl_enforce,
|
||||
&client_flags, &pool_name, &pool_size,
|
||||
&reset_session, &plugin_dir,
|
||||
&user, &schema, &password,
|
||||
&PyBool_Type,
|
||||
&converter,
|
||||
&PyBool_Type, &asynchronous))
|
||||
&user, &schema, &password))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -225,13 +214,6 @@ MrdbConnection_Initialize(MrdbConnection *self,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (converter)
|
||||
Py_INCREF(converter);
|
||||
else
|
||||
if (!(converter= PyDict_New()))
|
||||
return 1;
|
||||
self->converter= converter;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
if (mysql_options(self->mysql, MYSQL_SET_CHARSET_NAME, mariadb_default_charset))
|
||||
goto end;
|
||||
@ -347,8 +329,6 @@ static int MrdbConnection_traverse(
|
||||
visitproc visit,
|
||||
void *arg)
|
||||
{
|
||||
if (self->converter)
|
||||
return visit(self->converter, arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -483,9 +463,6 @@ PyObject *MrdbConnection_close(MrdbConnection *self)
|
||||
/* Todo: check if all the cursor stuff is deleted (when using prepared
|
||||
statements this should be handled in mysql_close) */
|
||||
|
||||
Py_XDECREF(self->converter);
|
||||
self->converter= NULL;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
mysql_close(self->mysql);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
@ -637,6 +637,10 @@ static int Mrdb_execute_direct(MrdbCursor *self,
|
||||
int rc;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
long ext_caps;
|
||||
|
||||
mariadb_get_infov(self->connection->mysql,
|
||||
MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES, &ext_caps);
|
||||
|
||||
/* clear pending result sets */
|
||||
MrdbCursor_clear_result(self);
|
||||
@ -651,7 +655,7 @@ static int Mrdb_execute_direct(MrdbCursor *self,
|
||||
/* 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 (!(self->connection->extended_server_capabilities &
|
||||
if (!(ext_caps &
|
||||
(MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32)))
|
||||
{
|
||||
if (!(rc= mysql_stmt_prepare(self->stmt, statement, (unsigned long)statement_len)))
|
||||
|
Reference in New Issue
Block a user