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

Delta Between Two Patch Sets: Modules/_sqlite/row.c

Issue 10203: sqlite3.Row doesn't support sequence protocol
Left Patch Set: Created 5 years, 9 months ago
Right Patch Set: Created 5 years, 3 months 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/sqlite3/test/factory.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 PyObject* pysqlite_row_item(pysqlite_Row* self, Py_ssize_t idx) 66 PyObject* pysqlite_row_item(pysqlite_Row* self, Py_ssize_t idx)
67 { 67 {
68 PyObject* item = PyTuple_GetItem(self->data, idx); 68 PyObject* item = PyTuple_GetItem(self->data, idx);
69 Py_XINCREF(item); 69 Py_XINCREF(item);
70 return item; 70 return item;
71 } 71 }
72 72
73 PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx) 73 PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
74 { 74 {
75 long _idx; 75 long _idx;
76 int long_overflow;
76 char* key; 77 char* key;
77 Py_ssize_t nitems, i; 78 Py_ssize_t nitems, i;
78 char* compare_key; 79 char* compare_key;
79 80
80 char* p1; 81 char* p1;
81 char* p2; 82 char* p2;
82 83
83 PyObject* item; 84 PyObject* item;
84 85
85 if (PyLong_Check(idx)) { 86 if (PyLong_Check(idx)) {
86 _idx = PyLong_AsLong(idx); 87 _idx = PyLong_AsLongAndOverflow(idx, &long_overflow);
88 if (long_overflow) {
89 PyErr_Format(PyExc_IndexError,
90 "cannot fit '%.200s' into an index-sized integer",
91 idx->ob_type->tp_name);
92 return NULL;
93 }
94 if (_idx < 0)
95 _idx += PyTuple_GET_SIZE(self->data);
87 item = PyTuple_GetItem(self->data, _idx); 96 item = PyTuple_GetItem(self->data, _idx);
88 Py_XINCREF(item); 97 Py_XINCREF(item);
89 return item; 98 return item;
90 } else if (PyUnicode_Check(idx)) { 99 } else if (PyUnicode_Check(idx)) {
91 key = _PyUnicode_AsString(idx); 100 key = _PyUnicode_AsString(idx);
92 if (key == NULL) 101 if (key == NULL)
93 return NULL; 102 return NULL;
94 103
95 nitems = PyTuple_Size(self->description); 104 nitems = PyTuple_Size(self->description);
96 105
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 PyMappingMethods pysqlite_row_as_mapping = { 211 PyMappingMethods pysqlite_row_as_mapping = {
203 /* mp_length */ (lenfunc)pysqlite_row_length, 212 /* mp_length */ (lenfunc)pysqlite_row_length,
204 /* mp_subscript */ (binaryfunc)pysqlite_row_subscript, 213 /* mp_subscript */ (binaryfunc)pysqlite_row_subscript,
205 /* mp_ass_subscript */ (objobjargproc)0, 214 /* mp_ass_subscript */ (objobjargproc)0,
206 }; 215 };
207 216
208 static PySequenceMethods pysqlite_row_as_sequence = { 217 static PySequenceMethods pysqlite_row_as_sequence = {
209 /* sq_length */ (lenfunc)pysqlite_row_length, 218 /* sq_length */ (lenfunc)pysqlite_row_length,
210 /* sq_concat */ 0, 219 /* sq_concat */ 0,
211 /* sq_repeat */ 0, 220 /* sq_repeat */ 0,
212 /* sq_item */ (unaryfunc)pysqlite_row_item, 221 /* sq_item */ (ssizeargfunc)pysqlite_row_item,
213 }; 222 };
214 223
215 224
216 static PyMethodDef pysqlite_row_methods[] = { 225 static PyMethodDef pysqlite_row_methods[] = {
217 {"keys", (PyCFunction)pysqlite_row_keys, METH_NOARGS, 226 {"keys", (PyCFunction)pysqlite_row_keys, METH_NOARGS,
218 PyDoc_STR("Returns the keys of the row.")}, 227 PyDoc_STR("Returns the keys of the row.")},
219 {NULL, NULL} 228 {NULL, NULL}
220 }; 229 };
221 230
222 231
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 0 /* tp_free */ 271 0 /* tp_free */
263 }; 272 };
264 273
265 extern int pysqlite_row_setup_types(void) 274 extern int pysqlite_row_setup_types(void)
266 { 275 {
267 pysqlite_RowType.tp_new = PyType_GenericNew; 276 pysqlite_RowType.tp_new = PyType_GenericNew;
268 pysqlite_RowType.tp_as_mapping = &pysqlite_row_as_mapping; 277 pysqlite_RowType.tp_as_mapping = &pysqlite_row_as_mapping;
269 pysqlite_RowType.tp_as_sequence = &pysqlite_row_as_sequence; 278 pysqlite_RowType.tp_as_sequence = &pysqlite_row_as_sequence;
270 return PyType_Ready(&pysqlite_RowType); 279 return PyType_Ready(&pysqlite_RowType);
271 } 280 }
LEFTRIGHT

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