1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
++++++++++++++++++++++
SQLObject and Python 3
++++++++++++++++++++++
.. contents::
Changes between Python 2 and Python 3
-------------------------------------
There are a few changes in the behaviour of SQLObject on Python 3, due to
the changed stings / bytes handling introduced in Python 3.0.
BLOBCol
~~~~~~~
In Python 3, BLOBCol now accepts and returns bytes, rather than strings as it
did in Python 2.
StringCol
~~~~~~~~~
In Python 3, StringCol now accepts arbitrary Unicode strings.
UnicodeCol
~~~~~~~~~~
The dbEncoding parameter to UnicodeCol has no effect in Python 3 code. This
is now handled by the underlying database layer and is no longer exposed
via SQLObject. The parameter is still available for those writing Python 2
compatible code.
Python 3 and MySQL
------------------
SQLObject is tested using mysqlclient_ as the database driver on Python 3.
Note that the default encoding of MySQL databases is *latin1*, which can cause
problems with general Unicode strings. We recommend specifying the character
set as *utf8* when using MySQL to protect against these issues.
.. _mysqlclient: https://pypi.org/project/mysqlclient/
Using databases created with SQLObject and Python 2 in Python 3
---------------------------------------------------------------
For most cases, things should just work as before. The only issues should
around UnicodeCol, as how this is handled has changed.
SQLite
~~~~~~
The Python 3 sqlite driver expects Unicode columns to be encoded using
utf8. Columns created using the default encoding on Python 2 should work fine,
but columns created with a different encoding set using the dbEncoding
parameter may cause problems.
Postgres
~~~~~~~~
Postgres' behaviour is similar to sqlite. Columns created using the
default encoding on Python 2 should work fine, but columns created with a
different encoding set using the dbEncoding may cause problems.
MySQL
~~~~~
For MySQL, the results depend on whether the Python 2 database was using
MySQLdb's Unicode mode or not.
If a character set was specified for the database using the charset parameter,
such as::
mysql:///localhost/test?charset=latin1
Things should work provided the same character set is specified when using
Python 3.
If a character set wasn't specified, then things may work if the character set
is set to match the dbEncoding parameter used when defining the UnicodeCol.
.. footer:: Get SQLObject at Sourceforge.net_. Fast, secure and Free Open Source software downloads
.. _Sourceforge.net: http://sourceforge.net/projects/sqlobject
|