Incompatible Change: The original message passed to
errors.Error()was not saved in such a way that it could be retrieved. Instead, the
Error.msgattribute was formatted with the error number and SQLSTATE value. Now only the original message is saved in the
Error.msgattribute. The formatted value together with the error number and SQLSTATE value can be obtained by printing or getting the string representation of the error object. Example:
try: conn = mysql.connector.connect(database = "baddb") except mysql.connector.Error as e: print "Error code:", e.errno # error number print "SQLSTATE value:", e.sqlstate # SQLSTATE value print "Error message:", e.msg # error message print "Error:", e # errno, sqlstate, msg values s = str(e) print "Error:", s # errno, sqlstate, msg values
Output for individual unit tests did not show timings, making it more difficult to debug problems that involve a change in test execution time. unittest.py now has a new
--statsoption that runs tests and shows elapsed time for each.
It is also possible to save the data to a MySQL server. When the
--stats-hostoption is given with other options such as
--stats-user, results are saved to a table called
myconnpy_X_Y_Z. The table contains the name of the test case and columns that combine Python and MySQL versions; for example, py27my55 or py33my56.
For example, to see the difference between MySQL 5.1 and 5.6, using Python 2.7, after running the test cases for both using Connector/Python 1.1.0, use this statement:
SELECT test_case, py27my51, py27my56, (py27my56-py27my51) AS diff51 FROM myconnpy_1_1_0 WHERE (py27my56-py27my51) > 0.5;
Connector/Python now includes a
mysql.connector.djangomodule that provides a Django backend for MySQL. This backend supports new features found in MySQL 5.6 such as fractional seconds support for temporal data types. For more information, see Connector/Python Django Backend.
MySQL Connector/Python now supports simple connection pooling that has these characteristics:
A pool opens a number of connections and handles thread safety when providing connections to requesters.
The size of a connection pool is configurable at pool creation time. It cannot be resized thereafter.
A connection pool can be named at pool creation time. If no name is given, one is generated using the connection parameters.
The connection pool name can be retrieved from the connection pool or connections obtained from it.
It is possible to have multiple connection pools. This enables applications to support pools of connections to different MySQL servers, for example.
For each connection request, the pool provides the next available connection. No round-robin or other scheduling algorithm is used.
It is possible to reconfigure the connection parameters used by a pool. These apply to connections obtained from the pool thereafter. Reconfiguring individual connections obtained from the pool by calling the connection
config()method is not supported.
Applications that can benefit from connection-pooling capability include:
Middleware that maintains multiple connections to multiple MySQL servers and requires connections to be readily available.
Web sites that can have more “permanent” connections open to the MySQL server.
The connection pooling implementation involves these interface elements:
A new module,
mysql.connector.pooling, provides two classes:
MySQLConnectionPoolinstantiates and manages connection pools, and
PooledMySQLConnectionis similar to
MySQLConnectionbut is used for connections that are part of a connection pool.
A new exception,
PoolError, occurs for pool-related exceptions.
PoolErroris a subclass of
For more information, see Connector/Python Connection Pooling.
fetchmany(), the result returned by
fetchall()was missing one row. (Bug #17041412)
Previously, executing a statement after the connection was closed raised an
OperationalErrorwith an unclear error. Connector/Python now returns the client error 2006,
MySQL Server has gone away, with an extra message.
Error()class has been extended to accept a new argument,
extra_msg. When given, it is appended between brackets. For example:
 Unknown MySQL Error (Some extra message)(Bug #17022399)
LOAD DATA LOCAL INFILEfailed for files approximately 14MB or larger. (Bug #17002411)
executemany()without any data produced a
ProgrammingErrorrather than doing nothing. (Bug #16660356)
InternalErrorwas raised during transaction rollback if there were unread results. The
MySQLConnection.rollback()method now consumes unread results instead of raising an error. (Bug #16656621)
Python 2.6 and 2.7 raised a
unicode_literalswas used and a database name contained nonlatin Unicode characters. (Bug #16655208)
MySQLCursor.executemany()method raised an exception when an SQL function was used as a column value when executing an
INSERTstatement. (Bug #69675, Bug #17065366)
OperationalErrorwas raised if a cursor object was closed while there were unread results. Connector/Python now raises an
InternalErrorindicating that there are still unread results. This provides information that to avoid the error it is necessary to consume the result by reading all rows. (Bug #67649, Bug #17041240)