-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
sqlite3.Row doesn't support slice indexes #57792
Comments
When using the sqlite3.Row object as a row factory, one can access the resulting rows by index (such as row[1]) or by name (such as row['b']). However, the slice functionality is lost, as doing row[0:2] raises the error: "slices not implemented, yet" Here is a patch that fixes this, I implemented it and I added the corresponding unit test. |
Thanks for the patch. Two things:
/home/antoine/cpython/default/Modules/_sqlite/row.c: In function ‘pysqlite_row_subscript’:
|
Thanks for the ticket and patch, xapple! I updated the patch to address the compiler warning and use assertEqual. While testing, I noticed that slicing with steps wasn't supported, so I expanded the sqlite3.Row slicing code to support steps, and added some additional tests. The slicing code in Modules/_sqlite/row.c:pysqlite_row_subscript is unfortunately pretty redundant with the slicing code in Objects/tupleobject.c. It'd be better to either be able to factor the code from both into a function (but I couldn't see how to do this without making it part of the public API), or have tuple, sqlite.Row, etc. implement a shared slicing interface. Perhaps we should defer that decision to a future ticket, though. Note that even after this patch, sqlite.Row instances don't support negative indices.
|
I've also uploaded a short script that sets up an in-memory sqlite database that fetches Rows, for easy manual testing. |
May be just use PyObject_GetItem(self->data, idx)? |
Here is a patch with much simpler implementation. |
Could you look at the patch Gerhard? |
New changeset e47f520eb756 by Serhiy Storchaka in branch 'default': |
The implementation can be much simpler, but in any case thank you for your patches Lucas and Jessica. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: