Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-24905: Support BLOB incremental I/O in sqlite module#271
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
Closed
Uh oh!
There was an error while loading. Please reload this page.
Closed
Changes from all commits
Commits
Show all changes
18 commits Select commit Hold shift + click to select a range
4fa0e91 support BLOB incremental I/O in sqlite module
palaviv 3fe9108 Note that blob size cannot be changed using the blob object
palaviv 865c1c8 Use assertRaises in tests
palaviv 788fd54 Fix doc error
palaviv a1361e5 blob support sequence protocol
palaviv 5aedfba Calculate blob length once at creation
palaviv db6ef32 Add initial Doc for sequence protocol
palaviv 219f4cb Don't support blob operation
palaviv 6dafe0e move news entry to blurb
palaviv ffac901 Add blob to PCBuild
palaviv 3475fa1 Update version
palaviv f6015ff Fix memory leak
palaviv 01e526c Update version
palaviv 354bebf Fix CR comments in documentation and testing
palaviv 9709456 Fix CR comments in code
palaviv e6e5099 Make readonly and dbname keyword arguements only
palaviv e9a8080 Fix more CR comments
palaviv d4fb1b5 Add more indicative error on write bigger then blob length
palaviv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import sqlite3 | ||
| con = sqlite3.connect(":memory:") | ||
| # creating the table | ||
| con.execute("create table test(id integer primary key, blob_col blob)") | ||
| con.execute("insert into test(blob_col) values (zeroblob(10))") | ||
| # opening blob handle | ||
| blob = con.open_blob("test", "blob_col", 1) | ||
| blob.write(b"Hello") | ||
| blob.write(b"World") | ||
| blob.seek(0) | ||
| print(blob.read()) # will print b"HelloWorld" | ||
| blob.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import sqlite3 | ||
| con = sqlite3.connect(":memory:") | ||
| # creating the table | ||
| con.execute("create table test(id integer primary key, blob_col blob)") | ||
| con.execute("insert into test(blob_col) values (zeroblob(10))") | ||
| # opening blob handle | ||
| with con.open_blob("test", "blob_col", 1) as blob: | ||
| blob.write(b"Hello") | ||
| blob.write(b"World") | ||
| blob.seek(0) | ||
| print(blob.read()) # will print b"HelloWorld" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -301,6 +301,21 @@ Connection Objects | ||
| supplied, this must be a callable returning an instance of :class:`Cursor` | ||
| or its subclasses. | ||
| .. method:: open_blob(table, column, row, *, readonly=False, dbname="main") | ||
| On success a :class:`Blob` handle to the | ||
| :abbr:`BLOB (Binary Large OBject)` located in row *row*, | ||
| column *column*, table *table* in database *dbname* will be returned. | ||
| When *readonly* is :const:`True` the BLOB is opened with read | ||
| permissions. Otherwise the BLOB has read and write permissions. | ||
| .. note:: | ||
| The BLOB size cannot be changed using the :class:`Blob` class. Use | ||
| ``zeroblob`` to create the blob in the wanted size in advance. | ||
| .. versionadded:: 3.10 | ||
| .. method:: commit() | ||
| This method commits the current transaction. If you don't call this method, | ||
| @@ -853,6 +868,66 @@ Exceptions | ||
| transactions turned off. It is a subclass of :exc:`DatabaseError`. | ||
| .. _sqlite3-blob-objects: | ||
| Blob Objects | ||
| ------------ | ||
| .. versionadded:: 3.10 | ||
| .. class:: Blob | ||
| A :class:`Blob` instance can read and write the data in the | ||
| :abbr:`BLOB (Binary Large OBject)`. The :class:`Blob` object implement both | ||
| the file and sequence protocol. For example, you can read data from the | ||
| :class:`Blob` by doing ``obj.read(5)`` or by doing ``obj[:5]``. | ||
| You can call ``len(obj)`` to get size of the BLOB. | ||
| .. method:: Blob.close() | ||
| Close the BLOB now (rather than whenever __del__ is called). | ||
| The BLOB will be unusable from this point forward; an | ||
| :class:`~sqlite3.Error` (or subclass) exception will be | ||
| raised if any operation is attempted with the BLOB. | ||
| .. method:: Blob.__len__() | ||
palaviv marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| Return the BLOB size. | ||
| .. method:: Blob.read([size]) | ||
| Read *size* bytes of data from the BLOB at the current offset position. | ||
| If the end of the BLOB is reached we will return the data up to end of | ||
| file. When *size* is not specified or negative we will read up to end | ||
| of BLOB. | ||
| .. method:: Blob.write(data) | ||
| Write *data* to the BLOB at the current offset. This function cannot | ||
| changed BLOB length. If data write will result in writing to more | ||
| then BLOB current size an error will be raised. | ||
| .. method:: Blob.tell() | ||
| Return the current offset of the BLOB. | ||
| .. method:: Blob.seek(offset, whence=os.SEEK_SET) | ||
| Set the BLOB offset. The *whence* argument is optional and defaults to | ||
| :data:`os.SEEK_SET` or 0 (absolute BLOB positioning); other values | ||
| are :data:`os.SEEK_CUR` or 1 (seek relative to the current position) and | ||
| :data:`os.SEEK_END` or 2 (seek relative to the BLOB’s end). | ||
| :class:`Blob` example: | ||
| .. literalinclude:: ../includes/sqlite3/blob.py | ||
| A :class:`Blob` can also be used with :term:`context manager`: | ||
| .. literalinclude:: ../includes/sqlite3/blob_with.py | ||
| .. _sqlite3-types: | ||
| SQLite and Python types | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick:
Blob.*prefix can be removed.