Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(13)

Side by Side Diff: Modules/_sqlite/row.c

Issue 13583: sqlite3.Row doesn't support slice indexes
Patch Set: Created 6 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/sqlite3/test/factory.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* row.c - an enhanced tuple for database rows 1 /* row.c - an enhanced tuple for database rows
2 * 2 *
3 * Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de> 3 * Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>
4 * 4 *
5 * This file is part of pysqlite. 5 * This file is part of pysqlite.
6 * 6 *
7 * This software is provided 'as-is', without any express or implied 7 * This software is provided 'as-is', without any express or implied
8 * warranty. In no event will the authors be held liable for any damages 8 * warranty. In no event will the authors be held liable for any damages
9 * arising from the use of this software. 9 * arising from the use of this software.
10 * 10 *
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 Py_INCREF(item); 118 Py_INCREF(item);
119 return item; 119 return item;
120 } 120 }
121 121
122 } 122 }
123 123
124 PyErr_SetString(PyExc_IndexError, "No item with that key"); 124 PyErr_SetString(PyExc_IndexError, "No item with that key");
125 return NULL; 125 return NULL;
126 } 126 }
127 else if (PySlice_Check(idx)) { 127 else if (PySlice_Check(idx)) {
128 PyErr_SetString(PyExc_ValueError, "slices not implemented, yet"); 128 Py_ssize_t start, stop, step, slicelength, cur, i;
129 return NULL; 129 PyObject* result;
130 PyObject* it;
131 PyObject **src, **dest;
132 if (PySlice_GetIndicesEx((PyObject *)idx,
133 PyTuple_GET_SIZE(self->data),
134 &start, &stop, &step, &slicelength) < 0) {
135 return NULL;
136 }
137
138 if (step == 1) {
139 return PyTuple_GetSlice(self->data, start, stop);
140 }
141 else {
142 result = PyTuple_New(slicelength);
143 if (!result) return NULL;
144
145 src = ((PyTupleObject *)self->data)->ob_item;
146 dest = ((PyTupleObject *)result)->ob_item;
147 for (cur = start, i = 0; i < slicelength;
148 cur += step, i++) {
149 it = src[cur];
AntoinePitrou 2014/04/28 13:26:54 Why not simply use PyTuple_SET_ITEM and PyTuple_GE
150 Py_INCREF(it);
151 dest[i] = it;
152 }
153
154 return result;
155 }
130 } 156 }
131 else { 157 else {
132 PyErr_SetString(PyExc_IndexError, "Index must be int or string"); 158 PyErr_SetString(PyExc_IndexError, "Index must be int or string");
133 return NULL; 159 return NULL;
134 } 160 }
135 } 161 }
136 162
137 Py_ssize_t pysqlite_row_length(pysqlite_Row* self, PyObject* args, PyObject* kwa rgs) 163 Py_ssize_t pysqlite_row_length(pysqlite_Row* self, PyObject* args, PyObject* kwa rgs)
138 { 164 {
139 return PyTuple_GET_SIZE(self->data); 165 return PyTuple_GET_SIZE(self->data);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 0, /* tp_new */ 272 0, /* tp_new */
247 0 /* tp_free */ 273 0 /* tp_free */
248 }; 274 };
249 275
250 extern int pysqlite_row_setup_types(void) 276 extern int pysqlite_row_setup_types(void)
251 { 277 {
252 pysqlite_RowType.tp_new = PyType_GenericNew; 278 pysqlite_RowType.tp_new = PyType_GenericNew;
253 pysqlite_RowType.tp_as_mapping = &pysqlite_row_as_mapping; 279 pysqlite_RowType.tp_as_mapping = &pysqlite_row_as_mapping;
254 return PyType_Ready(&pysqlite_RowType); 280 return PyType_Ready(&pysqlite_RowType);
255 } 281 }
OLDNEW
« no previous file with comments | « Lib/sqlite3/test/factory.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+