Skip to content

Commit 3f95456

Browse files
committed
CONPY-117: Added converter support
The connect() method now accepts an addtional parameter converter which points to a dictionary, containing one or more conversions. A conversion must be specified in the form {FIELD_TYOE : conversion_function}
1 parent 5d4a8d5 commit 3f95456

26 files changed

+12274
-302
lines changed

doc/source/connection.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Connection constructors
3131
- **prefetch_size** (integer): The number of rows prefetched. This option will be ignored, if *cursor_type* is not `CURSOR_TYPE_READ_ONLY`
3232
- **buffered** (bool): When set to `True` the entire result set from a SELECT/SHOW statement will be stored in client memory
3333
- **prepared** (bool): When set to `True` cursor will remain in prepared state after the first :func:`~cursor.execute` method was called. Further calls to *execute()* method will ignore the sql statement.
34-
.. versionadded:: 1.0.1
3534
- **binary** (bool): When set to `True` cursor will be executed using the MariaDB client/server binary protocol.
35+
.. versionadded:: 1.0.1
3636

3737
:return: Returns a cursor object or raises an exception if an error occured.
3838

@@ -48,7 +48,6 @@ Connection constructors
4848
:param branch_qualifier: Branch qualifier which represents a local transaction identifier. The maximum length of the branch qualifier is limited to 64 characters.
4949
:type branch_qualifier: string
5050

51-
5251
------------------
5352
Connection methods
5453
------------------

doc/source/module.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ The mariadb module supports the standard defined by DB API 2.0 (PEP-249).
4545
- **ssl_crlpath** (string): Defines a path to a PEM file that should contain one or more revoked X509 certificates to use for TLS. This option requires that you use the absolute path, not a relative path.
4646
- **ssl_verify_cert** (bool): Enables server certificate verification.
4747
- **ssl** (bool): Always use a secure TLS connection
48-
.. versionadded:: 1.0.1
4948
- **autocommit** (bool or None): Specifies the autocommit settings: None will use the server default. True will enable autocommit, False will disable it (default).
49+
.. versionadded:: 1.0.1
50+
- **converter** (dict): Specifies a conversion dictionary, where keys are FIELD_TYPE values and values are conversion functions.
51+
.. versionadded:: 1.0.3
5052

5153

5254
:return: Returns a connection or raises an error if the connection between client and server couldn't be established.

doc/source/pool.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ The ConnectionPool class
1919
In case that pool doesn't have a free slot or is not configured a PoolError
2020
exception will be raised.
2121

22-
.. versionadded:: 1.0.1
2322
.. method:: close()
2423

2524
Closes the pool and all connection inside the pool.
25+
.. versionadded:: 1.0.1
2626

2727
.. method:: get_connection()
2828

docs/_sources/connection.rst.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Connection constructors
3131
- **prefetch_size** (integer): The number of rows prefetched. This option will be ignored, if *cursor_type* is not `CURSOR_TYPE_READ_ONLY`
3232
- **buffered** (bool): When set to `True` the entire result set from a SELECT/SHOW statement will be stored in client memory
3333
- **prepared** (bool): When set to `True` cursor will remain in prepared state after the first :func:`~cursor.execute` method was called. Further calls to *execute()* method will ignore the sql statement.
34+
- **binary** (bool): When set to `True` cursor will be executed using the MariaDB client/server binary protocol.
35+
.. versionadded:: 1.0.1
3436

3537
:return: Returns a cursor object or raises an exception if an error occured.
3638

@@ -46,7 +48,6 @@ Connection constructors
4648
:param branch_qualifier: Branch qualifier which represents a local transaction identifier. The maximum length of the branch qualifier is limited to 64 characters.
4749
:type branch_qualifier: string
4850

49-
5051
------------------
5152
Connection methods
5253
------------------

docs/_sources/index.rst.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ client library for client server communication.
2020
connection
2121
cursor
2222
pool
23+
extension
2324
license
2425
release
2526

docs/_sources/module.rst.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ The mariadb module supports the standard defined by DB API 2.0 (PEP-249).
2020

2121
The supported connection keywords are:
2222

23-
- **user** (string): The username used to authenticate with the database server, defaults to current user
24-
- **pasword** (string): The password of the given user
23+
- **user**, **username** (string): The username used to authenticate with the database server, defaults to current user
24+
- **password**, **passwd** (string): The password of the given user
2525
- **host** (string): The host name or IP address of the database server
26-
- **database** (string): The database (schema) name to used when connecting with the database server
26+
- **database**, **db** (string): The database (schema) name to used when connecting with the database server
2727
- **unix_socket** (string): The location of the unix socket file to use instead of using an IP port to connect. If socket authentication is enabled, this can also be used in place of a password.
2828
- **port** (integer): The port number of the database server. If not specified the default value (=3306) will be used.
2929
- **connect_timeout** (integer): The connect timeout in seconds
@@ -35,25 +35,27 @@ The mariadb module supports the standard defined by DB API 2.0 (PEP-249).
3535
be used
3636
- **init_command** (string): Specifies one or more commands to execute when connecting and reconnecting to the database server.
3737
- **default_file** (string): Read options from the specified option file. If the file is an empty string, default configuration file(s) will be used
38-
- **default_group** (string): -- Read options from the specified group
38+
- **default_group** (string): Read options from the specified group
3939
- **ssl_key** (string): Defines a path to a private key file to use for TLS. This option
4040
requires that you use the absolute path, not a relative path. The specified key must be in PEM format
4141
- **ssl_cert** (string): Defines a path to the X509 certificate file to use for TLS. This option requires that you use the absolute path, not a relative path. The X609 certificate must be in PEM format.
4242
- **ssl_ca** (string): Defines a path to a PEM file that should contain one or more X509 certificates for trusted Certificate Authorities (CAs) to use for TLS. This option requires that you use the absolute path, not a relative path.
4343
- **ssl_capath** (string): Defines a path to a directory that contains one or more PEM files that contains one X509 certificate for a trusted Certificate Authority (CA)
4444
- **ssl_cipher** (string): Defines a list of permitted cipher suites to use for TLS
45-
- **ssl_crl_path** (string): Defines a path to a PEM file that should contain one or more revoked X509 certificates to use for TLS. This option requires that you use the absolute path, not a relative path.
46-
- **ssl_verify_server_cert** (bool): Enables server certificate verification.
47-
- **ssl_enforce** (bool): Always use a secure TLS connection
45+
- **ssl_crlpath** (string): Defines a path to a PEM file that should contain one or more revoked X509 certificates to use for TLS. This option requires that you use the absolute path, not a relative path.
46+
- **ssl_verify_cert** (bool): Enables server certificate verification.
47+
- **ssl** (bool): Always use a secure TLS connection
48+
- **autocommit** (bool or None): Specifies the autocommit settings: None will use the server default. True will enable autocommit, False will disable it (default).
49+
.. versionadded:: 1.0.1
50+
- **converter** (dict): Specifies a conversion dictionary, where keys are FIELD_TYPE values and values are conversion functions.
51+
.. versionadded:: 1.0.3
4852

4953

5054
:return: Returns a connection or raises an error if the connection between client and server couldn't be established.
5155

5256
:rtype: mariadb.connection object
5357

5458

55-
:Example:
56-
5759
The connection parameters have to be provided as a set of keyword arguments::
5860

5961
import mariadb

docs/_sources/pool.rst.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,25 @@ The ConnectionPool class
1919
In case that pool doesn't have a free slot or is not configured a PoolError
2020
exception will be raised.
2121

22+
.. method:: close()
23+
24+
Closes the pool and all connection inside the pool.
25+
.. versionadded:: 1.0.1
26+
2227
.. method:: get_connection()
2328

2429
Returns a connection from the connection pool or raises a PoolError if no
2530
connection is available.
2631

2732
.. method:: set_config(\*\*kwargs)
2833

29-
Sets the connection configuration for the connection pool.
34+
Sets the connection configuration for the connection pool. For valid connection
35+
arguments see :func:`mariadb.connect` method.
36+
37+
.. note::
38+
39+
This method doesn't create connections in the pool. To fill the pool one has to use
40+
the :func:`add_connection` ḿethod.
3041

3142
.. data:: max_size
3243

docs/_sources/release.rst.txt

Lines changed: 16 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,21 @@
1-
.. _release_notes:
1+
Release history
2+
===============
23

3-
Release notes
4-
=============
4+
Stable releases (GA)
5+
--------------------
56

6-
.. sectionauthor:: Georg Richter <georg@mariadb.com>
7+
MariaDB Connector/Python 1.0.0
8+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79

8-
MariaDB Connector/Python 0.9.59 beta
9-
------------------------------------
10-
Release date: May 26th 2020
10+
Release date: June 24th 2020
1111

1212
Notable Updates:
13-
14-
- CONPY-64: Fixed crash when a connection was established without parameters
15-
- CONPY-66: Fixed windows build
16-
- CONPY-62: Fixed String to Decimal conversion (binary protocol)
17-
- CONPY-63: Implemented version and version_info for module
18-
19-
MariaDB Connector/Python 0.9.58 beta
20-
------------------------------------
21-
Release date: May 6th 2020
22-
23-
Notable Updates:
24-
25-
- CONPY-62: When using binary protocol (which is forced when using a placeholder), the type NEW_DECIMAL was ignored and internally converted as string instead of Decimal
26-
- CONPY-61: Fixed bug in execute_many when using NULL values or indicator variables
27-
- CONPY-59: Fixed bug when converting invalid date "0000-00-00". Instead of raising an exception it will be converted to None value.
28-
- CONPY-58: Fixed parameter error when using paramstyle PyFormat.
29-
30-
MariaDB Connector/Python 0.9.57 beta
31-
------------------------------------
32-
Release date: April 15th 2020
33-
34-
Notable Updates:
35-
36-
- Build: Posix builds don't link statically against Connector/C anymore.
37-
- CONPY-53: Allow empty parameter sequence in execute() method
38-
- CONPY-56: Support dictionary option in cursor: Added anoptional boolean parameter 'dictionary' for cursor class. When dictionary parameter was set to true, the fetch operations will return rows from result set as Dict.
39-
- CONPY-55: Fixed memory leak when opening/closing cursor.
40-
41-
MariaDB Connector/Python 0.9.56 beta
42-
------------------------------------
43-
Release date: April 6th 2020
44-
45-
Notable Updates:
46-
47-
- CONPY-46: Implemented __enter__() and __exit__() methods for with statement (PEP-343). These methods are available now for connection and cursor class.
48-
- CONPY-47: When sending parameters PyBool_Type wasn't supported. In case a boolean type (True/False) will be provided as a parameter, it will be converted to a tinyint (MYSQL_TYPE_TINY).
49-
- CONPY-48: Accept List of parameters for execute() method
50-
- CONPY-49: Added support for Decimal type When retrieving data with column type MYSQL_TYPE_NEWDECIMAL Connector/Python now loads the decimal module and converts data from string into Pythons decimal.Decimal type. Wnen sending a decimal.Decimal parameter, value will be converted to string and send with type MYSQL_TYPE_NEWDECIMAL to server.
51-
- CONPY-51: Store field_count internelly for buffered cursors to prevent overriding/clearing the value by connection methods which directly send commands to database server.
52-
- CONPY-52: Fixed double free of resultset.
53-
54-
MariaDB Connector/Python 0.9.55 beta
55-
------------------------------------
56-
Release date: March 30th 2020
57-
58-
Notable Updates:
59-
60-
- CONPY-9: Fixed description (character length/code points and precision scale)
61-
- CONPY-45: Fixed conversion from time and datetime column types
62-
- CONPY-32: Fixed crash when fetching GEOMETRY columns
63-
64-
MariaDB Connector/Python 0.9.54 beta
65-
------------------------------------
66-
Release date: Feb 18th 2020
67-
68-
Notable Updates:
69-
70-
- Fixed parameter sequence when creating a xid object
71-
- Added ssl_capath in connect() method
72-
- CONPY-40: ConnectionPool._setconfig now accepts only DSN parameters
73-
- CONPY-35: Close and reinitialize statement if the cursor was reused with a different SQL statement
74-
- CONPY-34: If a python object can't be converted to a corresponding data type, an exception will be raised.
75-
- CONPY-39: If no pool_name was provided, an exception will be raised.
76-
- CONPY-33: Segfault when using auto completion in python shell
77-
- CONPY-37: Corrected option name: named_tuple
78-
- CONPY-36: connection key word socket was renamed to unix_socket
79-
13+
- CONPY-81: Fixed crash when switching between text and binary protocol with same cursor
14+
- CONPY-80: Parameters in set_config() method of ConnectionPool class have to be checked against the list of DSN keywords
15+
- CONPY-79: When inserting NULL values with executemany() method on a server which doesn't support BULK statements NULL values weren't inserted correctly.
16+
- CONPY-78: Since MaxScale doesn't support bulk operations yet, we have to check servers extended capability flag to determine if this feature is supported or not.
17+
- CONPY-76: Added aliases username, passwd and db to connection keywords.
18+
- CONPY-70: set_config() method needs to check the passed parameter and raise an exception if the parameter type is not a dictionary.
19+
- CONPY-72: When deallocating the connection pool class, we need to check beside pool_size if the array containing the connections is valid.
20+
- Fixed bug when inserting negative integer values with cursor.execute() method
21+
- CONPY-69: Set default character set (utf8mb4) with authentication packet

0 commit comments

Comments
 (0)