Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-69093: Support basic incremental I/O to blobs in sqlite3#30680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4fa0e913fe9108865c1c8788fd54a1361e55aedfbadb6ef32219f4cb6dafe0effac9013475fa1f6015ff01e526c354bebf9709456e6e5099e9a8080d4fb1b5a7288f9525a9c32f65cc80dd047fd34a77b9d55705d47ea17e07a116982c812e92495b8f2ce8a0a8752032132cf287803e0fc5a39cd0bde1cf7e15e7e77217c57e45add76f72237684e58905e89d69fca285bb3d2f3051afd7c3110644e87ced431a2dae1b9e8fa47e644166803d21529360e628eb16f7411d07e8149e3656b4caaafdeb2eb12219f32a21d836b0ca13d91705ceee31544f4cd3220b576d9b5cdfaaa272118e51188f685ba96df66197d12a82e63b3ebe277475add365bacf0875ff202d1fa590116f4d0d7aec288aaaf7abf9e65c06a5c864ea1045c2f848d98d906bc90b75d1be34fe6b8ab73b1d05c70b48742a47f7dec703d4fda167eb3b38f0df1b5f95395b386f26c3623fac770a290bb188708b34e15c087a9c89285c1ddfce49b35f9e7ae6b453f522154edcaf784a810bc67ed8d834bf259011269a5a1eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import sqlite3 | ||
| con = sqlite3.connect(":memory:") | ||
| con.execute("create table test(blob_col blob)") | ||
| con.execute("insert into test(blob_col) values (zeroblob(10))") | ||
| blob = con.blobopen("test", "blob_col", 1) | ||
| blob.write(b"Hello") | ||
| blob.write(b"World") | ||
| blob.seek(0) | ||
| print(blob.read()) # will print b"HelloWorld" | ||
| blob.close() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -394,6 +394,20 @@ Connection Objects | ||
| supplied, this must be a callable returning an instance of :class:`Cursor` | ||
| or its subclasses. | ||
| .. method:: blobopen(table, column, row, /, *, readonly=False, name="main") | ||
| Open a :class:`Blob` handle to the :abbr:`BLOB (Binary Large OBject)` | ||
| located in row *row*, column *column*, table *table* of database *name*. | ||
| When *readonly* is :const:`True` the blob is opened without write | ||
| permissions. | ||
erlend-aasland marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| .. note:: | ||
| The blob size cannot be changed using the :class:`Blob` class. | ||
| Use the SQL function ``zeroblob`` to create a blob with a fixed size. | ||
| .. versionadded:: 3.11 | ||
| .. method:: commit() | ||
| This method commits the current transaction. If you don't call this method, | ||
| @@ -1088,6 +1102,58 @@ Exceptions | ||
| transactions turned off. It is a subclass of :exc:`DatabaseError`. | ||
| .. _sqlite3-blob-objects: | ||
| Blob Objects | ||
| ------------ | ||
| .. versionadded:: 3.11 | ||
| .. class:: Blob | ||
| A :class:`Blob` instance is a :term:`file-like object` that can read and write | ||
| data in an SQLite :abbr:`BLOB (Binary Large OBject)`. Call ``len(blob)`` to | ||
| get the size (number of bytes) of the blob. | ||
| .. method:: close() | ||
| Close the blob. | ||
| The blob will be unusable from this point onward. An | ||
| :class:`~sqlite3.Error` (or subclass) exception will be raised if any | ||
| further operation is attempted with the blob. | ||
| .. method:: read(length=-1, /) | ||
| Read *length* bytes of data from the blob at the current offset position. | ||
| If the end of the blob is reached, the data up to | ||
| :abbr:`EOF (End of File)` will be returned. When *length* is not | ||
| specified, or is negative, :meth:`~Blob.read` will read until the end of | ||
| the blob. | ||
| .. method:: write(data, /) | ||
| Write *data* to the blob at the current offset. This function cannot | ||
| change the blob length. Writing beyond the end of the blob will raise | ||
| :exc:`ValueError`. | ||
| .. method:: tell() | ||
| Return the current access position of the blob. | ||
| .. method:: seek(offset, origin=os.SEEK_SET, /) | ||
| Set the current access position of the blob to *offset*. The *origin* | ||
| argument defaults to :data:`os.SEEK_SET` (absolute blob positioning). | ||
| Other values for *origin* are :data:`os.SEEK_CUR` (seek relative to the | ||
| current position) and :data:`os.SEEK_END` (seek relative to the blob’s | ||
| end). | ||
| :class:`Blob` example: | ||
| .. literalinclude:: ../includes/sqlite3/blob.py | ||
| .. _sqlite3-types: | ||
| SQLite and Python types | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -393,6 +393,10 @@ sqlite3 | ||
| :class:`sqlite3.Connection` for creating aggregate window functions. | ||
| (Contributed by Erlend E. Aasland in :issue:`34916`.) | ||
| * Add :meth:`~sqlite3.Connection.blobopen` to :class:`sqlite3.Connection`. | ||
| :class:`sqlite3.Blob` allows incremental I/O operations on blobs. | ||
| (Contributed by Aviv Palivoda and Erlend E. Aasland in :issue:`24905`) | ||
erlend-aasland marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| sys | ||
| --- | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Add :meth:`~sqlite3.Connection.blobopen` to :class:`sqlite3.Connection`. | ||
| :class:`sqlite3.Blob` allows incremental I/O operations on blobs. | ||
| Patch by Aviv Palivoda and Erlend E. Aasland. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.