File: blob.html

package info (click to toggle)
python-apsw 3.46.0.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,684 kB
  • sloc: python: 13,125; ansic: 12,334; javascript: 911; makefile: 10; sh: 7
file content (368 lines) | stat: -rw-r--r-- 36,248 bytes parent folder | download
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="./">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Blob Input/Output &mdash; APSW 3.46.0.1 documentation</title>
      <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=72bcf2f2" />
      <link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=19f00094" />
      <link rel="stylesheet" type="text/css" href="_static/apsw.css?v=3c7e2631" />

  
    <link rel="shortcut icon" href="_static/favicon.ico"/>
  <!--[if lt IE 9]>
    <script src="_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="_static/jquery.js?v=5d32c60e"></script>
        <script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
        <script src="_static/documentation_options.js?v=d98f5d2b"></script>
        <script src="_static/doctools.js?v=9a2dae69"></script>
        <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="_static/js/theme.js"></script>
    <link rel="author" title="About these documents" href="about.html" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="copyright" title="Copyright" href="copyright.html" />
    <link rel="next" title="Backup" href="backup.html" />
    <link rel="prev" title="Cursors (executing SQL)" href="cursor.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="index.html" class="icon icon-home">
            APSW
              <img src="_static/apswlogo.png" class="logo" alt="Logo"/>
          </a>
              <div class="version">
                3.46.0.1
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="about.html">About</a></li>
<li class="toctree-l1"><a class="reference internal" href="tips.html">Tips</a></li>
<li class="toctree-l1"><a class="reference internal" href="example.html">Example/Tour</a></li>
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation and customization</a></li>
<li class="toctree-l1"><a class="reference internal" href="extensions.html">Extensions</a></li>
<li class="toctree-l1"><a class="reference internal" href="apsw.html">APSW Module</a></li>
<li class="toctree-l1"><a class="reference internal" href="connection.html">Connections to a database</a></li>
<li class="toctree-l1"><a class="reference internal" href="cursor.html">Cursors (executing SQL)</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Blob Input/Output</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#zeroblob-class">zeroblob class</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#apsw.zeroblob"><code class="docutils literal notranslate"><span class="pre">zeroblob</span></code></a><ul>
<li class="toctree-l4"><a class="reference internal" href="#apsw.zeroblob.length"><code class="docutils literal notranslate"><span class="pre">zeroblob.length()</span></code></a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#blob-class">Blob class</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#apsw.Blob"><code class="docutils literal notranslate"><span class="pre">Blob</span></code></a><ul>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Blob.__enter__"><code class="docutils literal notranslate"><span class="pre">Blob.__enter__()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Blob.__exit__"><code class="docutils literal notranslate"><span class="pre">Blob.__exit__()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Blob.close"><code class="docutils literal notranslate"><span class="pre">Blob.close()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Blob.length"><code class="docutils literal notranslate"><span class="pre">Blob.length()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Blob.read"><code class="docutils literal notranslate"><span class="pre">Blob.read()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Blob.read_into"><code class="docutils literal notranslate"><span class="pre">Blob.read_into()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Blob.reopen"><code class="docutils literal notranslate"><span class="pre">Blob.reopen()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Blob.seek"><code class="docutils literal notranslate"><span class="pre">Blob.seek()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Blob.tell"><code class="docutils literal notranslate"><span class="pre">Blob.tell()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Blob.write"><code class="docutils literal notranslate"><span class="pre">Blob.write()</span></code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="backup.html">Backup</a></li>
<li class="toctree-l1"><a class="reference internal" href="vtable.html">Virtual Tables</a></li>
<li class="toctree-l1"><a class="reference internal" href="vfs.html">Virtual File System (VFS)</a></li>
<li class="toctree-l1"><a class="reference internal" href="shell.html">Shell</a></li>
<li class="toctree-l1"><a class="reference internal" href="bestpractice.html">Best Practice</a></li>
<li class="toctree-l1"><a class="reference internal" href="ext.html">Various interesting and useful bits of functionality</a></li>
<li class="toctree-l1"><a class="reference internal" href="exceptions.html">Exceptions and Errors</a></li>
<li class="toctree-l1"><a class="reference internal" href="execution.html">Execution and tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="dbapi.html">DBAPI notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="pysqlite.html">sqlite3 module differences</a></li>
<li class="toctree-l1"><a class="reference internal" href="benchmarking.html">Benchmarking</a></li>
<li class="toctree-l1"><a class="reference internal" href="copyright.html">Copyright and License</a></li>
<li class="toctree-l1"><a class="reference internal" href="changes.html">Change History</a></li>
<li class="toctree-l1"><a class="reference internal" href="py-modindex.html">Module Index</a></li>
<li class="toctree-l1"><a class="reference internal" href="genindex.html">Index</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">APSW</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content style-external-links">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
      <li class="breadcrumb-item active">Blob Input/Output</li>
      <li class="wy-breadcrumbs-aside">
            <a href="_sources/blob.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul><div class="rst-breadcrumbs-buttons" role="navigation" aria-label="Sequential page navigation">
        <a href="cursor.html" class="btn btn-neutral float-left" title="Cursors (executing SQL)" accesskey="p"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="backup.html" class="btn btn-neutral float-right" title="Backup" accesskey="n">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
  </div>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="blob-input-output">
<span id="blobio"></span><h1>Blob Input/Output<a class="headerlink" href="#blob-input-output" title="Link to this heading"></a></h1>
<p>A <a class="reference external" href="https://en.wikipedia.org/wiki/Binary_large_object">blob</a> is a
SQLite <a class="reference external" href="https://sqlite.org/datatype3.html">datatype</a> representing
a sequence of bytes.  It can be zero or more bytes in size.  Blobs
cannot be resized, but you can read and overwrite parts of them.</p>
<p>SQLite blobs have an absolute maximum size of 2GB and a <a class="reference external" href="https://sqlite.org/c3ref/c_limit_attached.html">default
maximum size</a> of
1GB.</p>
<p>An alternate approach to using blobs is to store the data in files and
store the filename in the database.  Doing so loses the <a class="reference external" href="https://sqlite.org/transactional.html">ACID</a> properties of SQLite.
There are <a class="reference external" href="https://www.sqlite.org/fasterthanfs.html">benchmarks</a>.</p>
<section id="zeroblob-class">
<h2>zeroblob class<a class="headerlink" href="#zeroblob-class" title="Link to this heading"></a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="apsw.zeroblob">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">zeroblob</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">size</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.zeroblob" title="Link to this definition"></a></dt>
<dd><p>If you want to insert a blob into a row, you need to
supply the entire blob in one go.  Using this class or
<a class="reference external" href="https://www.sqlite.org/lang_corefunc.html#zeroblob">function</a>
allocates the space in the database filling it with zeroes.</p>
<p>You can then overwrite parts in smaller chunks, without having
to do it all at once.  The <a class="reference internal" href="example.html#example-blob-io"><span class="std std-ref">example</span></a> shows
how to use it.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>size</strong> – Number of zeroed bytes to create</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="apsw.zeroblob.length">
<span class="sig-prename descclassname"><span class="pre">zeroblob.</span></span><span class="sig-name descname"><span class="pre">length</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></span><a class="headerlink" href="#apsw.zeroblob.length" title="Link to this definition"></a></dt>
<dd><p>Size of zero blob in bytes.</p>
</dd></dl>

</section>
<section id="blob-class">
<h2>Blob class<a class="headerlink" href="#blob-class" title="Link to this heading"></a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="apsw.Blob">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">Blob</span></span><a class="headerlink" href="#apsw.Blob" title="Link to this definition"></a></dt>
<dd><p>This object is created by <a class="reference internal" href="connection.html#apsw.Connection.blob_open" title="apsw.Connection.blob_open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.blob_open()</span></code></a> and provides
access to a blob in the database.  It behaves like a Python file.
It wraps a <a class="reference external" href="https://sqlite.org/c3ref/blob.html">sqlite3_blob</a>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>You cannot change the size of a blob using this object. You should
create it with the correct size in advance either by using
<a class="reference internal" href="#apsw.zeroblob" title="apsw.zeroblob"><code class="xref py py-class docutils literal notranslate"><span class="pre">zeroblob</span></code></a> or the <a class="reference external" href="https://sqlite.org/lang_corefunc.html">zeroblob()</a> function.</p>
</div>
<p>See the <a class="reference internal" href="example.html#example-blob-io"><span class="std std-ref">example</span></a>.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="apsw.Blob.__enter__">
<span class="sig-prename descclassname"><span class="pre">Blob.</span></span><span class="sig-name descname"><span class="pre">__enter__</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="#apsw.Blob" title="apsw.Blob"><span class="pre">Blob</span></a></span></span><a class="headerlink" href="#apsw.Blob.__enter__" title="Link to this definition"></a></dt>
<dd><p>You can use a blob as a <a class="reference external" href="https://docs.python.org/3/reference/datamodel.html#with-statement-context-managers">context manager</a>
as defined in <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0343/"><strong>PEP 0343</strong></a>.  When you use <em>with</em> statement,
the blob is always <a class="reference internal" href="#apsw.Blob.close" title="apsw.Blob.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">closed</span></code></a> on exit from the block, even if an
exception occurred in the block.</p>
<p>For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">connection</span><span class="o">.</span><span class="n">blob_open</span><span class="p">()</span> <span class="k">as</span> <span class="n">blob</span><span class="p">:</span>
    <span class="n">blob</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;...&quot;</span><span class="p">)</span>
    <span class="n">res</span><span class="o">=</span><span class="n">blob</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">1024</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="apsw.Blob.__exit__">
<span class="sig-prename descclassname"><span class="pre">Blob.</span></span><span class="sig-name descname"><span class="pre">__exit__</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">etype</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.12)"><span class="pre">type</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#BaseException" title="(in Python v3.12)"><span class="pre">BaseException</span></a><span class="p"><span class="pre">]</span></span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">evalue</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#BaseException" title="(in Python v3.12)"><span class="pre">BaseException</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">etraceback</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/types.html#types.TracebackType" title="(in Python v3.12)"><span class="pre">types.TracebackType</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.Blob.__exit__" title="Link to this definition"></a></dt>
<dd><p>Implements context manager in conjunction with
<a class="reference internal" href="#apsw.Blob.__enter__" title="apsw.Blob.__enter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__enter__()</span></code></a>.  Any exception that happened in the
<em>with</em> block is raised after closing the blob.</p>
</dd></dl>

<dl class="py method" id="index-1">
<dt class="sig sig-object py" id="apsw.Blob.close">
<span class="sig-prename descclassname"><span class="pre">Blob.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.Blob.close" title="Link to this definition"></a></dt>
<dd><p>Closes the blob.  Note that even if an error occurs the blob is
still closed.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>In some cases errors that technically occurred in the
<a class="reference internal" href="#apsw.Blob.read" title="apsw.Blob.read"><code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code></a> and <a class="reference internal" href="#apsw.Blob.write" title="apsw.Blob.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code></a> routines may not be
reported until close is called.  Similarly errors that occurred
in those methods (eg calling <a class="reference internal" href="#apsw.Blob.write" title="apsw.Blob.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code></a> on a read-only
blob) may also be re-reported in <a class="reference internal" href="#apsw.Blob.close" title="apsw.Blob.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a>.  (This
behaviour is what the underlying SQLite APIs do - it is not APSW
doing it.)</p>
</div>
<p>It is okay to call <a class="reference internal" href="#apsw.Blob.close" title="apsw.Blob.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> multiple times.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>force</strong> – Ignores any errors during close.</p>
</dd>
</dl>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/blob_close.html">sqlite3_blob_close</a></p>
</dd></dl>

<dl class="py method" id="index-2">
<dt class="sig sig-object py" id="apsw.Blob.length">
<span class="sig-prename descclassname"><span class="pre">Blob.</span></span><span class="sig-name descname"><span class="pre">length</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></span><a class="headerlink" href="#apsw.Blob.length" title="Link to this definition"></a></dt>
<dd><p>Returns the size of the blob in bytes.</p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/blob_bytes.html">sqlite3_blob_bytes</a></p>
</dd></dl>

<dl class="py method" id="index-3">
<dt class="sig sig-object py" id="apsw.Blob.read">
<span class="sig-prename descclassname"><span class="pre">Blob.</span></span><span class="sig-name descname"><span class="pre">read</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">length</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">-1</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.12)"><span class="pre">bytes</span></a></span></span><a class="headerlink" href="#apsw.Blob.read" title="Link to this definition"></a></dt>
<dd><p>Reads amount of data requested, or till end of file, whichever is
earlier. Attempting to read beyond the end of the blob returns an
empty bytes in the same manner as end of file on normal file
objects.  Negative numbers read all remaining data.</p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/blob_read.html">sqlite3_blob_read</a></p>
</dd></dl>

<dl class="py method" id="index-4">
<dt class="sig sig-object py" id="apsw.Blob.read_into">
<span class="sig-prename descclassname"><span class="pre">Blob.</span></span><span class="sig-name descname"><span class="pre">read_into</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">buffer</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytearray" title="(in Python v3.12)"><span class="pre">bytearray</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/array.html#array.array" title="(in Python v3.12)"><span class="pre">array.array</span></a><span class="p"><span class="pre">[</span></span><span class="pre">Any</span><span class="p"><span class="pre">]</span></span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#memoryview" title="(in Python v3.12)"><span class="pre">memoryview</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">length</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">-1</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.Blob.read_into" title="Link to this definition"></a></dt>
<dd><p>Reads from the blob into a buffer you have supplied.  This method is
useful if you already have a buffer like object that data is being
assembled in, and avoids allocating results in <a class="reference internal" href="#apsw.Blob.read" title="apsw.Blob.read"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blob.read()</span></code></a> and
then copying into buffer.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>buffer</strong> – A writable buffer like object.
There is a <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytearray" title="(in Python v3.12)"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> type that is very useful.
<a class="reference external" href="https://docs.python.org/3/library/array.html#module-array" title="(in Python v3.12)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">Arrays</span></code></a> also work.</p></li>
<li><p><strong>offset</strong> – The position to start writing into the buffer
defaulting to the beginning.</p></li>
<li><p><strong>length</strong> – How much of the blob to read.  The default is the
remaining space left in the buffer.  Note that if
there is more space available than blob left then you
will get a <em>ValueError</em> exception.</p></li>
</ul>
</dd>
</dl>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/blob_read.html">sqlite3_blob_read</a></p>
</dd></dl>

<dl class="py method" id="index-5">
<dt class="sig sig-object py" id="apsw.Blob.reopen">
<span class="sig-prename descclassname"><span class="pre">Blob.</span></span><span class="sig-name descname"><span class="pre">reopen</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rowid</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.Blob.reopen" title="Link to this definition"></a></dt>
<dd><p>Change this blob object to point to a different row.  It can be
faster than closing an existing blob an opening a new one.</p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/blob_reopen.html">sqlite3_blob_reopen</a></p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="apsw.Blob.seek">
<span class="sig-prename descclassname"><span class="pre">Blob.</span></span><span class="sig-name descname"><span class="pre">seek</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">offset</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">whence</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.Blob.seek" title="Link to this definition"></a></dt>
<dd><p>Changes current position to <em>offset</em> biased by <em>whence</em>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>offset</strong> – New position to seek to.  Can be positive or negative number.</p></li>
<li><p><strong>whence</strong> – Use 0 if <em>offset</em> is relative to the beginning of the blob,
1 if <em>offset</em> is relative to the current position,
and 2 if <em>offset</em> is relative to the end of the blob.</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.12)"><strong>ValueError</strong></a> – If the resulting offset is before the beginning (less than zero) or beyond the end of the blob.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="apsw.Blob.tell">
<span class="sig-prename descclassname"><span class="pre">Blob.</span></span><span class="sig-name descname"><span class="pre">tell</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></span><a class="headerlink" href="#apsw.Blob.tell" title="Link to this definition"></a></dt>
<dd><p>Returns the current offset.</p>
</dd></dl>

<dl class="py method" id="index-6">
<dt class="sig sig-object py" id="apsw.Blob.write">
<span class="sig-prename descclassname"><span class="pre">Blob.</span></span><span class="sig-name descname"><span class="pre">write</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.12)"><span class="pre">bytes</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.Blob.write" title="Link to this definition"></a></dt>
<dd><p>Writes the data to the blob.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>data</strong> – bytes to write</p>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><ul class="simple">
<li><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#TypeError" title="(in Python v3.12)"><strong>TypeError</strong></a> – Wrong data type</p></li>
<li><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.12)"><strong>ValueError</strong></a> – If the data would go beyond the end of the blob.
You cannot increase the size of a blob by writing beyond the end.
You need to use <a class="reference internal" href="#apsw.zeroblob" title="apsw.zeroblob"><code class="xref py py-class docutils literal notranslate"><span class="pre">zeroblob</span></code></a> to set the desired size first when
inserting the blob.</p></li>
</ul>
</dd>
</dl>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/blob_write.html">sqlite3_blob_write</a></p>
</dd></dl>

</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="cursor.html" class="btn btn-neutral float-left" title="Cursors (executing SQL)" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="backup.html" class="btn btn-neutral float-right" title="Backup" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; <a href="copyright.html">Copyright</a> 2004-2024, Roger Binns &lt;rogerb@rogerbinns.com&gt;.
      <span class="lastupdated">Last updated on Jun 16, 2024.
      </span></p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>