~ubuntu-branches/ubuntu/lucid/python-apsw/lucid

« back to all changes in this revision

Viewing changes to doc/types.html

  • Committer: Bazaar Package Importer
  • Author(s): Joel Rosdahl
  • Date: 2010-01-11 20:44:37 UTC
  • mfrom: (1.1.6 upstream) (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100111204437-iao0rcj1p2m29juy
Tags: 3.6.22-r1-1
* New upstream version.
* Added ${misc:Depends} for binary packages' requirements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
2
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
3
 
 
4
<html xmlns="http://www.w3.org/1999/xhtml">
 
5
  <head>
 
6
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
7
    
 
8
    <title>Types &mdash; APSW v3.6.22-r1 documentation</title>
 
9
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
 
10
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
 
11
    <script type="text/javascript">
 
12
      var DOCUMENTATION_OPTIONS = {
 
13
        URL_ROOT:    '#',
 
14
        VERSION:     '3.6.22-r1',
 
15
        COLLAPSE_MODINDEX: false,
 
16
        FILE_SUFFIX: '.html',
 
17
        HAS_SOURCE:  true
 
18
      };
 
19
    </script>
 
20
    <script type="text/javascript" src="_static/jquery.js"></script>
 
21
    <script type="text/javascript" src="_static/doctools.js"></script>
 
22
    <link rel="copyright" title="Copyright" href="copyright.html" />
 
23
    <link rel="top" title="APSW v3.6.22-r1 documentation" href="index.html" />
 
24
    <link rel="next" title="Execution and tracing" href="execution.html" />
 
25
    <link rel="prev" title="Exceptions" href="exceptions.html" /> 
 
26
  </head>
 
27
  <body>
 
28
    <div class="related">
 
29
      <h3>Navigation</h3>
 
30
      <ul>
 
31
        <li class="right" style="margin-right: 10px">
 
32
          <a href="genindex.html" title="General Index"
 
33
             accesskey="I">index</a></li>
 
34
        <li class="right" >
 
35
          <a href="modindex.html" title="Global Module Index"
 
36
             accesskey="M">modules</a> |</li>
 
37
        <li class="right" >
 
38
          <a href="execution.html" title="Execution and tracing"
 
39
             accesskey="N">next</a> |</li>
 
40
        <li class="right" >
 
41
          <a href="exceptions.html" title="Exceptions"
 
42
             accesskey="P">previous</a> |</li>
 
43
        <li><a href="index.html">APSW v3.6.22-r1 documentation</a> &raquo;</li> 
 
44
      </ul>
 
45
    </div>  
 
46
 
 
47
    <div class="document">
 
48
      <div class="documentwrapper">
 
49
        <div class="bodywrapper">
 
50
          <div class="body">
 
51
            
 
52
  <div class="section" id="types">
 
53
<span id="id1"></span><h1>Types<a class="headerlink" href="#types" title="Permalink to this headline">¶</a></h1>
 
54
<p>Read about <a class="reference external" href="http://www.sqlite.org/datatype3.html">SQLite 3 types</a>. ASPW always maintains the
 
55
correct type for values, and never converts them to something
 
56
else. Note however that SQLite may convert types based on column
 
57
affinity as <a class="reference external" href="http://www.sqlite.org/datatype3.html">described</a>. ASPW
 
58
requires that all values supplied are one of the corresponding
 
59
Python/SQLite types (or a subclass).</p>
 
60
<div class="section" id="mapping">
 
61
<h2>Mapping<a class="headerlink" href="#mapping" title="Permalink to this headline">¶</a></h2>
 
62
<ul class="simple">
 
63
<li>None in Python is NULL in SQLite</li>
 
64
<li>Python int or long is INTEGER in SQLite. The value represented must
 
65
fit within a 64 bit signed quantity (long long at the C level) or an
 
66
overflow exception is generated.</li>
 
67
<li>Python&#8217;s float type is used for REAL in SQLite. (At the C level they
 
68
are both 8 byte quantities and there is no loss of precision).</li>
 
69
<li>In Python 2, Python&#8217;s string or unicode is used for TEXT supplied to
 
70
SQLite and all text returned from SQLite is unicode.  For Python 3
 
71
only unicode is used.</li>
 
72
<li>For Python 2 the buffer class is used for BLOB in SQLite. In Python
 
73
3 the bytes type is used, although you can still supply buffers.</li>
 
74
</ul>
 
75
</div>
 
76
<div class="section" id="unicode">
 
77
<span id="id2"></span><h2>Unicode<a class="headerlink" href="#unicode" title="Permalink to this headline">¶</a></h2>
 
78
<p>All SQLite strings are Unicode. The actual binary representations can
 
79
be UTF8, or UTF16 in either byte order. ASPW uses the UTF8 interface
 
80
to SQLite which results in the binary string representation in your
 
81
database defaulting to UTF8 as well. All this is totally transparent
 
82
to your Python code.</p>
 
83
<p>Everywhere strings are used (eg as database values, SQL statements,
 
84
bindings names, user defined functions) you can use Unicode strings,
 
85
and in Python 3 must use Unicode.  In Python 2, you can also use the
 
86
bare Python string class, and ASPW will automatically call the unicode
 
87
converter if any non-ascii characters are present.</p>
 
88
<p>When returning text values from SQLite, ASPW always uses the Python
 
89
unicode class.</p>
 
90
<p>If you don&#8217;t know much about Unicode then read <a class="reference external" href="http://www.joelonsoftware.com/articles/Unicode.html">Joel&#8217;s article</a>.  SQLite does
 
91
not include conversion from random non-Unicode encodings to or from
 
92
Unicode.  (It does include conversion between 8 bit and 16 bit Unicode
 
93
encodings).  Python includes <a class="reference external" href="http://www.python.org/doc/2.5.2/lib/module-codecs.html">codecs</a> for
 
94
conversion to or from many different character sets.</p>
 
95
<p>If you don&#8217;t want to use Unicode and instead want a simple bytes in
 
96
are the same bytes out then you should only use blobs.</p>
 
97
<p>If you want to do manipulation of unicode text such as upper/lower
 
98
casing or sorting then you need to know about locales.  This is
 
99
because the exact same sequence of characters sort, upper case, lower
 
100
case etc differently depending on where you are.  As an example Turkic
 
101
languages have multiple letter i, German has ß which behaves like ss,
 
102
various accents sort differently in different European countries.
 
103
Fortunately there is a libary you can ask to do the right locale
 
104
specific thing <a class="reference external" href="http://en.wikipedia.org/wiki/International_Components_for_Unicode">ICU</a>.
 
105
A default SQLite compilation only deals with the 26 letter Roman
 
106
alphabet.  If you enable ICU with SQLite then you get <a class="reference external" href="http://www.sqlite.org/src/finfo?name=ext/icu/README.txt">good stuff</a>.
 
107
See the <a class="reference external" href="build.html#building"><em>Building</em></a> section on how to enable ICU for SQLite with
 
108
APSW.  Note that Python does not currently include ICU support and
 
109
hence sorting, upper/lower casing etc are limited and do not take
 
110
locales into account.</p>
 
111
<p>In summary, never confuse bytes with strings (which C sadly treats as
 
112
the same thing).  Either always use bytes (and SQLite blobs) for
 
113
everything or use strings (and SQLite strings) for everything.  If you
 
114
take the latter approach and have to deal with external input/output
 
115
then you must know what encodings are being used and it is best to
 
116
convert to Unicode as early as possible on input and late as possible on
 
117
output.</p>
 
118
</div>
 
119
</div>
 
120
 
 
121
 
 
122
          </div>
 
123
        </div>
 
124
      </div>
 
125
      <div class="sphinxsidebar">
 
126
        <div class="sphinxsidebarwrapper">
 
127
            <h3><a href="index.html">Table Of Contents</a></h3>
 
128
            <ul>
 
129
<li><a class="reference external" href="#">Types</a><ul>
 
130
<li><a class="reference external" href="#mapping">Mapping</a></li>
 
131
<li><a class="reference external" href="#unicode">Unicode</a></li>
 
132
</ul>
 
133
</li>
 
134
</ul>
 
135
 
 
136
            <h4>Previous topic</h4>
 
137
            <p class="topless"><a href="exceptions.html"
 
138
                                  title="previous chapter">Exceptions</a></p>
 
139
            <h4>Next topic</h4>
 
140
            <p class="topless"><a href="execution.html"
 
141
                                  title="next chapter">Execution and tracing</a></p>
 
142
            <h3>This Page</h3>
 
143
            <ul class="this-page-menu">
 
144
              <li><a href="_sources/types.txt"
 
145
                     rel="nofollow">Show Source</a></li>
 
146
            </ul>
 
147
          <div id="searchbox" style="display: none">
 
148
            <h3>Quick search</h3>
 
149
              <form class="search" action="search.html" method="get">
 
150
                <input type="text" name="q" size="18" />
 
151
                <input type="submit" value="Go" />
 
152
                <input type="hidden" name="check_keywords" value="yes" />
 
153
                <input type="hidden" name="area" value="default" />
 
154
              </form>
 
155
              <p class="searchtip" style="font-size: 90%">
 
156
              Enter search terms or a module, class or function name.
 
157
              </p>
 
158
          </div>
 
159
          <script type="text/javascript">$('#searchbox').show(0);</script>
 
160
        </div>
 
161
      </div>
 
162
      <div class="clearer"></div>
 
163
    </div>
 
164
    <div class="related">
 
165
      <h3>Navigation</h3>
 
166
      <ul>
 
167
        <li class="right" style="margin-right: 10px">
 
168
          <a href="genindex.html" title="General Index"
 
169
             >index</a></li>
 
170
        <li class="right" >
 
171
          <a href="modindex.html" title="Global Module Index"
 
172
             >modules</a> |</li>
 
173
        <li class="right" >
 
174
          <a href="execution.html" title="Execution and tracing"
 
175
             >next</a> |</li>
 
176
        <li class="right" >
 
177
          <a href="exceptions.html" title="Exceptions"
 
178
             >previous</a> |</li>
 
179
        <li><a href="index.html">APSW v3.6.22-r1 documentation</a> &raquo;</li> 
 
180
      </ul>
 
181
    </div>
 
182
    <div class="footer">
 
183
        &copy; <a href="copyright.html">Copyright</a> 2004-2009, Roger Binns &lt;rogerb@rogerbinns.com&gt;.
 
184
      Last updated on Jan 06, 2010.
 
185
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.
 
186
    </div>
 
187
  </body>
 
188
</html>
 
 
b'\\ No newline at end of file'