Skip to content

Commit

Permalink
Moved MemberDef properties
Browse files Browse the repository at this point in the history
Mostly all properties moved to Python code
  • Loading branch information
9EOR9 committed Aug 16, 2021
1 parent 1ab9f83 commit 6bbe026
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 91 deletions.
60 changes: 59 additions & 1 deletion mariadb/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def cursor(self, cursorclass=mariadb.cursors.Cursor, **kwargs):
Optional parameters:
- buffered= True
By default the result will be unbuffered, which means before executing
If set to False the result will be unbuffered, which means before executing
another statement with the same connection the entire result set must be fetched.
Please note that the default was False for MariaDB Connector/Python versions < 1.1.0.
- dictionary= False
Expand Down Expand Up @@ -439,12 +439,59 @@ def character_set(self):

return _DEFAULT_CHARSET

@property
def client_capabilities(self):
"""Client capability flags."""

return self._mariadb_get_info(INFO.CLIENT_CAPABILITIES, int)

@property
def server_capabilities(self):
"""Server capability flags."""

return self._mariadb_get_info(INFO.SERVER_CAPABILITIES, int)
@property
def server_port(self):
"""Database server TCP/IP port. This value will be 0 in case of a unix socket connection."""

return self._mariadb_get_info(INFO.PORT, int)

@property
def unix_socket(self):
"""Unix socket name."""

return self._mariadb_get_info(INFO.UNIX_SOCKET, str)

@property
def server_name(self):
"""Name or IP address of database server."""

return self._mariadb_get_info(INFO.HOST, str)

@property
def collation(self):
"""Client character set collation"""

return _DEFAULT_COLLATION

@property
def server_info(self):
"""Server version in alphanumerical format (str)"""

return self._mariadb_get_info(INFO.SERVER_VERSION, str)

@property
def tls_cipher(self):
"""TLS cipher suite if a secure connection is used."""

return self._mariadb_get_info(INFO.SSL_CIPHER, str)

@property
def tls_version(self):
"""TLS protocol version if a secure connection is used."""

return self._mariadb_get_info(INFO.TLS_VERSION, str)

@property
def server_status(self):
"""
Expand All @@ -453,6 +500,17 @@ def server_status(self):

return self._mariadb_get_info(INFO.SERVER_STATUS, int)

@property
def server_version(self):
"""
Server version in numerical format.
The form of the version number is
VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH
"""

return self._mariadb_get_info(INFO.SERVER_VERSION_ID, int)

@property
def server_version_info(self):
"""
Expand Down
94 changes: 4 additions & 90 deletions mariadb/mariadb_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,100 +150,24 @@ MrdbConnection_Methods[] =
static struct
PyMemberDef MrdbConnection_Members[] =
{
{"character_set",
T_STRING,
offsetof(MrdbConnection, charset),
{"connection_id",
T_LONG,
offsetof(MrdbConnection, thread_id),
READONLY,
"Client character set"},
"Id of current connection."},
{"converter",
T_OBJECT,
offsetof(MrdbConnection, converter),
READONLY,
"Conversion dictionary"},
{"connection_id",
T_ULONG,
offsetof(MrdbConnection, thread_id),
READONLY,
"Id of current connection"},
{"collation",
T_STRING,
offsetof(MrdbConnection, collation),
READONLY,
"Client character set collation"},
{"dsn",
T_OBJECT,
offsetof(MrdbConnection, dsn),
READONLY,
"Data source name (dsn)"},
{"server_port",
T_INT,
offsetof(MrdbConnection, port),
READONLY,
"Database server TCP/IP port. This value will be 0 in case of a unix socket connection"},
{"server_version",
T_ULONG,
offsetof(MrdbConnection, server_version),
READONLY,
"Server version in numerical format:\n\nThe form of the version number is VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH"},
{"server_info",
T_STRING,
offsetof(MrdbConnection, server_info),
READONLY,
"Server info"},
{"unix_socket",
T_STRING,
offsetof(MrdbConnection, unix_socket),
READONLY,
"Unix socket name"},
{"server_name",
T_STRING,
offsetof(MrdbConnection, host),
READONLY,
"Name or address of database server"},
{"tls_cipher",
T_STRING,
offsetof(MrdbConnection, tls_cipher),
READONLY,
"TLS cipher suite used by connection"},
{"tls_version",
T_STRING,
offsetof(MrdbConnection, tls_version),
READONLY,
"TLS protocol version used by connection"},
{"client_capabilities",
T_ULONG,
offsetof(MrdbConnection, client_capabilities),
READONLY,
"Client capabilities"},
{"server_capabilities",
T_ULONG,
offsetof(MrdbConnection, server_capabilities),
READONLY,
"Server capabilities"},
{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);
}

void MrdbConnection_SetAttributes(MrdbConnection *self)
{
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_HOST, &self->host);
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_SSL_CIPHER, &self->tls_cipher);
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_TLS_VERSION, &self->tls_version);
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_UNIX_SOCKET, &self->unix_socket);
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_PORT, &self->port);
self->charset= mariadb_default_charset;
self->collation= mariadb_default_collation;
}

static int
MrdbConnection_Initialize(MrdbConnection *self,
PyObject *args,
Expand Down Expand Up @@ -402,10 +326,6 @@ MrdbConnection_Initialize(MrdbConnection *self,

self->thread_id= mysql_thread_id(self->mysql);

/* CONPY-129: server_version_info */
self->server_version= mysql_get_server_version(self->mysql);
self->server_info= mysql_get_server_info(self->mysql);

has_error= 0;
end:
Py_END_ALLOW_THREADS;
Expand All @@ -419,11 +339,6 @@ MrdbConnection_Initialize(MrdbConnection *self,
if (PyErr_Occurred())
return -1;

/* set connection attributes */
MrdbConnection_SetAttributes(self);
/* get capabilities */
MrdbConnection_GetCapabilities(self);

return 0;
}

Expand Down Expand Up @@ -740,7 +655,6 @@ PyObject *MrdbConnection_reconnect(MrdbConnection *self)
}
/* get capabilities */
self->thread_id= mysql_thread_id(self->mysql);
MrdbConnection_GetCapabilities(self);
Py_RETURN_NONE;
}
/* }}} */
Expand Down

0 comments on commit 6bbe026

Please sign in to comment.