<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SQLObject and Python 3 — SQLObject 3.7.0 documentation</title> <link rel="stylesheet" href="_static/bizstyle.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <script type="text/javascript" src="_static/documentation_options.js"></script> <script type="text/javascript" src="_static/jquery.js"></script> <script type="text/javascript" src="_static/underscore.js"></script> <script type="text/javascript" src="_static/doctools.js"></script> <script type="text/javascript" src="_static/bizstyle.js"></script> <link rel="index" title="Index" href="genindex.html" /> <link rel="search" title="Search" href="search.html" /> <link rel="next" title="SQLObject" href="SQLObject.html" /> <link rel="prev" title="News" href="News.html" /> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <!--[if lt IE 9]> <script type="text/javascript" src="_static/css3-mediaqueries.js"></script> <![endif]--> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="SQLObject.html" title="SQLObject" accesskey="N">next</a> |</li> <li class="right" > <a href="News.html" title="News" accesskey="P">previous</a> |</li> <li class="nav-item nav-item-0"><a href="index.html">SQLObject 3.7.0 documentation</a> »</li> </ul> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">SQLObject and Python 3</a><ul> <li><a class="reference internal" href="#changes-between-python-2-and-python-3">Changes between Python 2 and Python 3</a><ul> <li><a class="reference internal" href="#blobcol">BLOBCol</a></li> <li><a class="reference internal" href="#stringcol">StringCol</a></li> <li><a class="reference internal" href="#unicodecol">UnicodeCol</a></li> </ul> </li> <li><a class="reference internal" href="#python-3-and-mysql">Python 3 and MySQL</a></li> <li><a class="reference internal" href="#using-databases-created-with-sqlobject-and-python-2-in-python-3">Using databases created with SQLObject and Python 2 in Python 3</a><ul> <li><a class="reference internal" href="#sqlite">SQLite</a></li> <li><a class="reference internal" href="#postgres">Postgres</a></li> <li><a class="reference internal" href="#mysql">MySQL</a></li> </ul> </li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="News.html" title="previous chapter">News</a></p> <h4>Next topic</h4> <p class="topless"><a href="SQLObject.html" title="next chapter">SQLObject</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="_sources/Python3.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3>Quick search</h3> <div class="searchformwrapper"> <form class="search" action="search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="sqlobject-and-python-3"> <h1><a class="toc-backref" href="#id1">SQLObject and Python 3</a><a class="headerlink" href="#sqlobject-and-python-3" title="Permalink to this headline">¶</a></h1> <div class="contents topic" id="contents"> <p class="topic-title first">Contents</p> <ul class="simple"> <li><a class="reference internal" href="#sqlobject-and-python-3" id="id1">SQLObject and Python 3</a><ul> <li><a class="reference internal" href="#changes-between-python-2-and-python-3" id="id2">Changes between Python 2 and Python 3</a><ul> <li><a class="reference internal" href="#blobcol" id="id3">BLOBCol</a></li> <li><a class="reference internal" href="#stringcol" id="id4">StringCol</a></li> <li><a class="reference internal" href="#unicodecol" id="id5">UnicodeCol</a></li> </ul> </li> <li><a class="reference internal" href="#python-3-and-mysql" id="id6">Python 3 and MySQL</a></li> <li><a class="reference internal" href="#using-databases-created-with-sqlobject-and-python-2-in-python-3" id="id7">Using databases created with SQLObject and Python 2 in Python 3</a><ul> <li><a class="reference internal" href="#sqlite" id="id8">SQLite</a></li> <li><a class="reference internal" href="#postgres" id="id9">Postgres</a></li> <li><a class="reference internal" href="#mysql" id="id10">MySQL</a></li> </ul> </li> </ul> </li> </ul> </div> <div class="section" id="changes-between-python-2-and-python-3"> <h2><a class="toc-backref" href="#id2">Changes between Python 2 and Python 3</a><a class="headerlink" href="#changes-between-python-2-and-python-3" title="Permalink to this headline">¶</a></h2> <p>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.</p> <div class="section" id="blobcol"> <h3><a class="toc-backref" href="#id3">BLOBCol</a><a class="headerlink" href="#blobcol" title="Permalink to this headline">¶</a></h3> <p>In Python 3, BLOBCol now accepts and returns bytes, rather than strings as it did in Python 2.</p> </div> <div class="section" id="stringcol"> <h3><a class="toc-backref" href="#id4">StringCol</a><a class="headerlink" href="#stringcol" title="Permalink to this headline">¶</a></h3> <p>In Python 3, StringCol now accepts arbitrary Unicode strings.</p> </div> <div class="section" id="unicodecol"> <h3><a class="toc-backref" href="#id5">UnicodeCol</a><a class="headerlink" href="#unicodecol" title="Permalink to this headline">¶</a></h3> <p>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.</p> </div> </div> <div class="section" id="python-3-and-mysql"> <h2><a class="toc-backref" href="#id6">Python 3 and MySQL</a><a class="headerlink" href="#python-3-and-mysql" title="Permalink to this headline">¶</a></h2> <p>SQLObject is tested using <a class="reference external" href="https://pypi.org/project/mysqlclient/">mysqlclient</a> as the database driver on Python 3. Note that the default encoding of MySQL databases is <em>latin1</em>, which can cause problems with general Unicode strings. We recommend specifying the character set as <em>utf8</em> when using MySQL to protect against these issues.</p> </div> <div class="section" id="using-databases-created-with-sqlobject-and-python-2-in-python-3"> <h2><a class="toc-backref" href="#id7">Using databases created with SQLObject and Python 2 in Python 3</a><a class="headerlink" href="#using-databases-created-with-sqlobject-and-python-2-in-python-3" title="Permalink to this headline">¶</a></h2> <p>For most cases, things should just work as before. The only issues should around UnicodeCol, as how this is handled has changed.</p> <div class="section" id="sqlite"> <h3><a class="toc-backref" href="#id8">SQLite</a><a class="headerlink" href="#sqlite" title="Permalink to this headline">¶</a></h3> <p>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.</p> </div> <div class="section" id="postgres"> <h3><a class="toc-backref" href="#id9">Postgres</a><a class="headerlink" href="#postgres" title="Permalink to this headline">¶</a></h3> <p>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.</p> </div> <div class="section" id="mysql"> <h3><a class="toc-backref" href="#id10">MySQL</a><a class="headerlink" href="#mysql" title="Permalink to this headline">¶</a></h3> <p>For MySQL, the results depend on whether the Python 2 database was using MySQLdb’s Unicode mode or not.</p> <p>If a character set was specified for the database using the charset parameter, such as:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>mysql:///localhost/test?charset=latin1 </pre></div> </div> <p>Things should work provided the same character set is specified when using Python 3.</p> <p>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.</p> <a class="reference external image-reference" href="https://sourceforge.net/projects/sqlobject"><img alt="Get SQLObject at SourceForge.net. Fast, secure and Free Open Source software downloads" class="noborder align-center" src="https://sourceforge.net/sflogo.php?group_id=74338&type=10" style="width: 80px; height: 15px;" /></a> </div> </div> </div> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="SQLObject.html" title="SQLObject" >next</a> |</li> <li class="right" > <a href="News.html" title="News" >previous</a> |</li> <li class="nav-item nav-item-0"><a href="index.html">SQLObject 3.7.0 documentation</a> »</li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright 2004-2018, Ian Bicking and contributors. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.7.4. </div> </body> </html>