Skip to content

Commit 6bbe026

Browse files
committed
Moved MemberDef properties
Mostly all properties moved to Python code
1 parent 1ab9f83 commit 6bbe026

File tree

2 files changed

+63
-91
lines changed

2 files changed

+63
-91
lines changed

mariadb/connections.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def cursor(self, cursorclass=mariadb.cursors.Cursor, **kwargs):
7676
Optional parameters:
7777
7878
- buffered= True
79-
By default the result will be unbuffered, which means before executing
79+
If set to False the result will be unbuffered, which means before executing
8080
another statement with the same connection the entire result set must be fetched.
8181
Please note that the default was False for MariaDB Connector/Python versions < 1.1.0.
8282
- dictionary= False
@@ -439,12 +439,59 @@ def character_set(self):
439439

440440
return _DEFAULT_CHARSET
441441

442+
@property
443+
def client_capabilities(self):
444+
"""Client capability flags."""
445+
446+
return self._mariadb_get_info(INFO.CLIENT_CAPABILITIES, int)
447+
448+
@property
449+
def server_capabilities(self):
450+
"""Server capability flags."""
451+
452+
return self._mariadb_get_info(INFO.SERVER_CAPABILITIES, int)
453+
@property
454+
def server_port(self):
455+
"""Database server TCP/IP port. This value will be 0 in case of a unix socket connection."""
456+
457+
return self._mariadb_get_info(INFO.PORT, int)
458+
459+
@property
460+
def unix_socket(self):
461+
"""Unix socket name."""
462+
463+
return self._mariadb_get_info(INFO.UNIX_SOCKET, str)
464+
465+
@property
466+
def server_name(self):
467+
"""Name or IP address of database server."""
468+
469+
return self._mariadb_get_info(INFO.HOST, str)
470+
442471
@property
443472
def collation(self):
444473
"""Client character set collation"""
445474

446475
return _DEFAULT_COLLATION
447476

477+
@property
478+
def server_info(self):
479+
"""Server version in alphanumerical format (str)"""
480+
481+
return self._mariadb_get_info(INFO.SERVER_VERSION, str)
482+
483+
@property
484+
def tls_cipher(self):
485+
"""TLS cipher suite if a secure connection is used."""
486+
487+
return self._mariadb_get_info(INFO.SSL_CIPHER, str)
488+
489+
@property
490+
def tls_version(self):
491+
"""TLS protocol version if a secure connection is used."""
492+
493+
return self._mariadb_get_info(INFO.TLS_VERSION, str)
494+
448495
@property
449496
def server_status(self):
450497
"""
@@ -453,6 +500,17 @@ def server_status(self):
453500

454501
return self._mariadb_get_info(INFO.SERVER_STATUS, int)
455502

503+
@property
504+
def server_version(self):
505+
"""
506+
Server version in numerical format.
507+
508+
The form of the version number is
509+
VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH
510+
"""
511+
512+
return self._mariadb_get_info(INFO.SERVER_VERSION_ID, int)
513+
456514
@property
457515
def server_version_info(self):
458516
"""

mariadb/mariadb_connection.c

Lines changed: 4 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -150,100 +150,24 @@ MrdbConnection_Methods[] =
150150
static struct
151151
PyMemberDef MrdbConnection_Members[] =
152152
{
153-
{"character_set",
154-
T_STRING,
155-
offsetof(MrdbConnection, charset),
153+
{"connection_id",
154+
T_LONG,
155+
offsetof(MrdbConnection, thread_id),
156156
READONLY,
157-
"Client character set"},
157+
"Id of current connection."},
158158
{"converter",
159159
T_OBJECT,
160160
offsetof(MrdbConnection, converter),
161161
READONLY,
162162
"Conversion dictionary"},
163-
{"connection_id",
164-
T_ULONG,
165-
offsetof(MrdbConnection, thread_id),
166-
READONLY,
167-
"Id of current connection"},
168-
{"collation",
169-
T_STRING,
170-
offsetof(MrdbConnection, collation),
171-
READONLY,
172-
"Client character set collation"},
173163
{"dsn",
174164
T_OBJECT,
175165
offsetof(MrdbConnection, dsn),
176166
READONLY,
177167
"Data source name (dsn)"},
178-
{"server_port",
179-
T_INT,
180-
offsetof(MrdbConnection, port),
181-
READONLY,
182-
"Database server TCP/IP port. This value will be 0 in case of a unix socket connection"},
183-
{"server_version",
184-
T_ULONG,
185-
offsetof(MrdbConnection, server_version),
186-
READONLY,
187-
"Server version in numerical format:\n\nThe form of the version number is VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH"},
188-
{"server_info",
189-
T_STRING,
190-
offsetof(MrdbConnection, server_info),
191-
READONLY,
192-
"Server info"},
193-
{"unix_socket",
194-
T_STRING,
195-
offsetof(MrdbConnection, unix_socket),
196-
READONLY,
197-
"Unix socket name"},
198-
{"server_name",
199-
T_STRING,
200-
offsetof(MrdbConnection, host),
201-
READONLY,
202-
"Name or address of database server"},
203-
{"tls_cipher",
204-
T_STRING,
205-
offsetof(MrdbConnection, tls_cipher),
206-
READONLY,
207-
"TLS cipher suite used by connection"},
208-
{"tls_version",
209-
T_STRING,
210-
offsetof(MrdbConnection, tls_version),
211-
READONLY,
212-
"TLS protocol version used by connection"},
213-
{"client_capabilities",
214-
T_ULONG,
215-
offsetof(MrdbConnection, client_capabilities),
216-
READONLY,
217-
"Client capabilities"},
218-
{"server_capabilities",
219-
T_ULONG,
220-
offsetof(MrdbConnection, server_capabilities),
221-
READONLY,
222-
"Server capabilities"},
223168
{NULL} /* always last */
224169
};
225170

226-
static void MrdbConnection_GetCapabilities(MrdbConnection *self)
227-
{
228-
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_SERVER_CAPABILITIES,
229-
&self->server_capabilities);
230-
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES,
231-
&self->extended_server_capabilities);
232-
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_CLIENT_CAPABILITIES,
233-
&self->client_capabilities);
234-
}
235-
236-
void MrdbConnection_SetAttributes(MrdbConnection *self)
237-
{
238-
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_HOST, &self->host);
239-
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_SSL_CIPHER, &self->tls_cipher);
240-
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_TLS_VERSION, &self->tls_version);
241-
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_UNIX_SOCKET, &self->unix_socket);
242-
mariadb_get_infov(self->mysql, MARIADB_CONNECTION_PORT, &self->port);
243-
self->charset= mariadb_default_charset;
244-
self->collation= mariadb_default_collation;
245-
}
246-
247171
static int
248172
MrdbConnection_Initialize(MrdbConnection *self,
249173
PyObject *args,
@@ -402,10 +326,6 @@ MrdbConnection_Initialize(MrdbConnection *self,
402326

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

405-
/* CONPY-129: server_version_info */
406-
self->server_version= mysql_get_server_version(self->mysql);
407-
self->server_info= mysql_get_server_info(self->mysql);
408-
409329
has_error= 0;
410330
end:
411331
Py_END_ALLOW_THREADS;
@@ -419,11 +339,6 @@ MrdbConnection_Initialize(MrdbConnection *self,
419339
if (PyErr_Occurred())
420340
return -1;
421341

422-
/* set connection attributes */
423-
MrdbConnection_SetAttributes(self);
424-
/* get capabilities */
425-
MrdbConnection_GetCapabilities(self);
426-
427342
return 0;
428343
}
429344

@@ -740,7 +655,6 @@ PyObject *MrdbConnection_reconnect(MrdbConnection *self)
740655
}
741656
/* get capabilities */
742657
self->thread_id= mysql_thread_id(self->mysql);
743-
MrdbConnection_GetCapabilities(self);
744658
Py_RETURN_NONE;
745659
}
746660
/* }}} */

0 commit comments

Comments
 (0)