Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
72e731cc
Commit
72e731cc
authored
Mar 31, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #13583: sqlite3.Row now supports slice indexing.
Tests by Jessica McKellar.
parent
80d84c89
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
2 deletions
+24
-2
Doc/library/sqlite3.rst
Doc/library/sqlite3.rst
+3
-0
Lib/sqlite3/test/factory.py
Lib/sqlite3/test/factory.py
+18
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_sqlite/row.c
Modules/_sqlite/row.c
+1
-2
No files found.
Doc/library/sqlite3.rst
View file @
72e731cc
...
@@ -649,6 +649,9 @@ Row Objects
...
@@ -649,6 +649,9 @@ Row Objects
This method returns a list of column names. Immediately after a query,
This method returns a list of column names. Immediately after a query,
it is the first member of each tuple in :attr:`Cursor.description`.
it is the first member of each tuple in :attr:`Cursor.description`.
.. versionchanged:: 3.5
Added support of slicing.
Let's assume we initialize a table as in the example given above::
Let's assume we initialize a table as in the example given above::
conn = sqlite3.connect(":memory:")
conn = sqlite3.connect(":memory:")
...
...
Lib/sqlite3/test/factory.py
View file @
72e731cc
...
@@ -111,6 +111,24 @@ class RowFactoryTests(unittest.TestCase):
...
@@ -111,6 +111,24 @@ class RowFactoryTests(unittest.TestCase):
with
self
.
assertRaises
(
IndexError
):
with
self
.
assertRaises
(
IndexError
):
row
[
2
**
1000
]
row
[
2
**
1000
]
def
CheckSqliteRowSlice
(
self
):
# A sqlite.Row can be sliced like a list.
self
.
con
.
row_factory
=
sqlite
.
Row
row
=
self
.
con
.
execute
(
"select 1, 2, 3, 4"
).
fetchone
()
self
.
assertEqual
(
row
[
0
:
0
],
())
self
.
assertEqual
(
row
[
0
:
1
],
(
1
,))
self
.
assertEqual
(
row
[
1
:
3
],
(
2
,
3
))
self
.
assertEqual
(
row
[
3
:
1
],
())
# Explicit bounds are optional.
self
.
assertEqual
(
row
[
1
:],
(
2
,
3
,
4
))
self
.
assertEqual
(
row
[:
3
],
(
1
,
2
,
3
))
# Slices can use negative indices.
self
.
assertEqual
(
row
[
-
2
:
-
1
],
(
3
,))
self
.
assertEqual
(
row
[
-
2
:],
(
3
,
4
))
# Slicing supports steps.
self
.
assertEqual
(
row
[
0
:
4
:
2
],
(
1
,
3
))
self
.
assertEqual
(
row
[
3
:
0
:
-
2
],
(
4
,
2
))
def
CheckSqliteRowIter
(
self
):
def
CheckSqliteRowIter
(
self
):
"""Checks if the row object is iterable"""
"""Checks if the row object is iterable"""
self
.
con
.
row_factory
=
sqlite
.
Row
self
.
con
.
row_factory
=
sqlite
.
Row
...
...
Misc/NEWS
View file @
72e731cc
...
@@ -13,6 +13,8 @@ Core and Builtins
...
@@ -13,6 +13,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #13583: sqlite3.Row now supports slice indexing.
- Issue #18473: Fixed 2to3 and 3to2 compatible pickle mappings. Fixed
- Issue #18473: Fixed 2to3 and 3to2 compatible pickle mappings. Fixed
ambigious reverse mappings. Added many new mappings. Import mapping is no
ambigious reverse mappings. Added many new mappings. Import mapping is no
longer applied to modules already mapped with full name mapping.
longer applied to modules already mapped with full name mapping.
...
...
Modules/_sqlite/row.c
View file @
72e731cc
...
@@ -142,8 +142,7 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
...
@@ -142,8 +142,7 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
return
NULL
;
return
NULL
;
}
}
else
if
(
PySlice_Check
(
idx
))
{
else
if
(
PySlice_Check
(
idx
))
{
PyErr_SetString
(
PyExc_ValueError
,
"slices not implemented, yet"
);
return
PyObject_GetItem
(
self
->
data
,
idx
);
return
NULL
;
}
}
else
{
else
{
PyErr_SetString
(
PyExc_IndexError
,
"Index must be int or string"
);
PyErr_SetString
(
PyExc_IndexError
,
"Index must be int or string"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment