-
Incompatible Change: Previous series of Connector/Python had separate Python 2 and Python 3 code bases. For Connector/Python 2.0, the source tree has been reorganized to have a single code base, for easier maintenance, testing, and distribution.
This reorganization results in an incompatible change in behavior: With the use of “raw” cursors, the returned values is of the
bytearray
type. This is necessary for having both Python 2 and 3 return the same data. Consider the following example:import mysql.connector cnx = mysql.connector.connect(raw=True) cursor = cnx.cursor() cursor.execute('SELECT 1') print(cursor.fetchall())
In Connector/Python 1.x, the output is:
Using Python 2:
[('1',)]
Using Python 3:
[(b'1',)]
In Connector/Python 2.0, for both Python versions, the output is:
[(bytearray(b'1'),)]
To get the same value as in Connector/Python 1.x, do this:
Using Python 2:
str(bytearray(b'1'))
Using Python 3:
bytes((bytearray(b'1'))
(WL #7462)
Important Change: Previously, to enable use of
LOAD DATA LOCAL
, clients had to explicitly set theClientFlag.LOCAL_FILES
flag. This flag is now enabled by default. To disable it, theallow_local_infile
option forconnect()
can be set toFalse
. (WL #7937)For a stored procedure that produces multiple result sets, it is now possible to execute the procedure and process its results by executing a
CALL
statement. Execute the statement usingexecute()
with amulti=True
argument, and use the returned iterator to process each result in turn. (Bug #73291, Bug #19207922)-
Connector/Python now supports option files using two new options for
connect()
:option_files
: Which option files to read. The value can be a file path name (a string) or a sequence of path name strings. By default, Connector/Python reads no option files, so this argument must be given explicitly to cause option files to be read. Files are read in the order specified.option_groups
: Which groups to read from option files, if option files are read. The value can be an option group name (a string) or a sequence of group name strings. If this argument is not given, the default value is['client, 'connector_python']
to read the[client]
and[connector_python]
groups.
For more information, see Connector/Python Option-File Support. (WL #7228)
-
The
mysql.connector.cursor
module supports four new cursor classes:-
The
MySQLCursorDict
cursor class returns each row as a dictionary. The keys for each dictionary object are the column names of the MySQL result.cursor = cnx.cursor(dictionary=True)
-
The
MySQLCursorBufferedDict
cursor class is likeMySQLCursorDict
, but fetches the entire result set after executing the query and buffers the rows.cursor = cnx.cursor(dictionary=True, buffered=True)
-
The
MySQLCursorNamedTuple
cursor class returns each row as a named tuple. Each column is accessible through an attribute of the tuple-like object.cursor = cnx.cursor(named_tuple=True)
-
The
MySQLCursorBufferedNamedTuple
cursor class is likeMySQLCursorNamedTuple
, but fetches the entire result set after executing the query and buffers the rows.cursor = cnx.cursor(named_tuple=True, buffered=True)
For more information, see Subclasses cursor.MySQLCursor. (WL #7292)
-
The packaging modules and supporting files have been removed from the main repository and from the source packages for Connector/Python. They are still available in the Connector/Python 1.x series. (WL #7716)
Django
TimeField
values of00:00:00
were incorrectly converted toNULL
because Python considered that value equal toFalse
. (Bug #72732, Bug #18956789)Fetching results from a prepared statement that returned many columns could produce an error. (Bug #72602, Bug #18742429)
Previously, a
RuntimeError
exception was raised when a Django application was inactive for a while. Now, the Django back end verifies that the database connection is still valid each time a database request is made. (Bug #72545, Bug #18843153)