1
/* cursor.c - the cursor type
3
* Copyright (C) 2004-2007 Gerhard HƤring <gh@ghaering.de>
5
* This file is part of pysqlite.
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
9
* arising from the use of this software.
11
* Permission is granted to anyone to use this software for any purpose,
12
* including commercial applications, and to alter it and redistribute it
13
* freely, subject to the following restrictions:
15
* 1. The origin of this software must not be misrepresented; you must not
16
* claim that you wrote the original software. If you use this software
17
* in a product, an acknowledgment in the product documentation would be
18
* appreciated but is not required.
19
* 2. Altered source versions must be plainly marked as such, and must not be
20
* misrepresented as being the original software.
21
* 3. This notice may not be removed or altered from any source distribution.
27
#include "sqlitecompat.h"
29
/* used to decide wether to call PyLong_FromLong or PyLong_FromLongLong */
31
#define INT32_MIN (-2147483647 - 1)
34
#define INT32_MAX 2147483647
37
PyObject* pysqlite_cursor_iternext(pysqlite_Cursor* self);
39
static pysqlite_StatementKind detect_statement_type(const char* statement)
46
/* skip over whitepace */
47
while (*src == '\r' || *src == '\n' || *src == ' ' || *src == '\t') {
52
return STATEMENT_INVALID;
56
while (isalpha(*src) && dst - buf < sizeof(buf) - 2) {
57
*dst++ = tolower(*src++);
62
if (!strcmp(buf, "select")) {
63
return STATEMENT_SELECT;
64
} else if (!strcmp(buf, "insert")) {
65
return STATEMENT_INSERT;
66
} else if (!strcmp(buf, "update")) {
67
return STATEMENT_UPDATE;
68
} else if (!strcmp(buf, "delete")) {
69
return STATEMENT_DELETE;
70
} else if (!strcmp(buf, "replace")) {
71
return STATEMENT_REPLACE;
73
return STATEMENT_OTHER;
77
int pysqlite_cursor_init(pysqlite_Cursor* self, PyObject* args, PyObject* kwargs)
79
pysqlite_Connection* connection;
81
if (!PyArg_ParseTuple(args, "O!", &pysqlite_ConnectionType, &connection))
86
Py_INCREF(connection);
87
self->connection = connection;
88
self->statement = NULL;
89
self->next_row = NULL;
91
self->row_cast_map = PyList_New(0);
92
if (!self->row_cast_map) {
97
self->description = Py_None;
100
self->lastrowid= Py_None;
104
self->rowcount = -1L;
107
self->row_factory = Py_None;
109
if (!pysqlite_check_thread(self->connection)) {
116
void pysqlite_cursor_dealloc(pysqlite_Cursor* self)
120
/* Reset the statement if the user has not closed the cursor */
121
if (self->statement) {
122
rc = pysqlite_statement_reset(self->statement);
123
Py_DECREF(self->statement);
126
Py_XDECREF(self->connection);
127
Py_XDECREF(self->row_cast_map);
128
Py_XDECREF(self->description);
129
Py_XDECREF(self->lastrowid);
130
Py_XDECREF(self->row_factory);
131
Py_XDECREF(self->next_row);
133
Py_TYPE(self)->tp_free((PyObject*)self);
136
PyObject* _pysqlite_get_converter(PyObject* key)
138
PyObject* upcase_key;
141
upcase_key = PyObject_CallMethod(key, "upper", "");
146
retval = PyDict_GetItem(converters, upcase_key);
147
Py_DECREF(upcase_key);
152
int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
155
const char* type_start = (const char*)-1;
159
const char* decltype;
160
PyObject* py_decltype;
164
if (!self->connection->detect_types) {
168
Py_XDECREF(self->row_cast_map);
169
self->row_cast_map = PyList_New(0);
171
for (i = 0; i < sqlite3_column_count(self->statement->st); i++) {
174
if (self->connection->detect_types & PARSE_COLNAMES) {
175
colname = sqlite3_column_name(self->statement->st, i);
177
for (pos = colname; *pos != 0; pos++) {
179
type_start = pos + 1;
180
} else if (*pos == ']' && type_start != (const char*)-1) {
181
key = PyUnicode_FromStringAndSize(type_start, pos - type_start);
183
/* creating a string failed, but it is too complicated
184
* to propagate the error here, we just assume there is
185
* no converter and proceed */
189
converter = _pysqlite_get_converter(key);
197
if (!converter && self->connection->detect_types & PARSE_DECLTYPES) {
198
decltype = sqlite3_column_decltype(self->statement->st, i);
200
for (pos = decltype;;pos++) {
201
/* Converter names are split at '(' and blanks.
202
* This allows 'INTEGER NOT NULL' to be treated as 'INTEGER' and
203
* 'NUMBER(10)' to be treated as 'NUMBER', for example.
204
* In other words, it will work as people expect it to work.*/
205
if (*pos == ' ' || *pos == '(' || *pos == 0) {
206
py_decltype = PyUnicode_FromStringAndSize(decltype, pos - decltype);
214
converter = _pysqlite_get_converter(py_decltype);
215
Py_DECREF(py_decltype);
223
if (PyList_Append(self->row_cast_map, converter) != 0) {
224
if (converter != Py_None) {
225
Py_DECREF(converter);
227
Py_XDECREF(self->row_cast_map);
228
self->row_cast_map = NULL;
237
PyObject* _pysqlite_build_column_name(const char* colname)
246
for (pos = colname;; pos++) {
247
if (*pos == 0 || *pos == '[') {
248
if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) {
251
return PyUnicode_FromStringAndSize(colname, pos - colname);
256
PyObject* pysqlite_unicode_from_string(const char* val_str, int optimize)
258
return PyUnicode_FromString(val_str);
262
* Returns a row from the currently active SQLite statement
265
* - sqlite3_step() has been called before and it returned SQLITE_ROW.
267
PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
271
PyObject* item = NULL;
284
Py_BEGIN_ALLOW_THREADS
285
numcols = sqlite3_data_count(self->statement->st);
288
row = PyTuple_New(numcols);
293
for (i = 0; i < numcols; i++) {
294
if (self->connection->detect_types) {
295
converter = PyList_GetItem(self->row_cast_map, i);
303
if (converter != Py_None) {
304
nbytes = sqlite3_column_bytes(self->statement->st, i);
305
val_str = (const char*)sqlite3_column_blob(self->statement->st, i);
310
item = PyBytes_FromStringAndSize(val_str, nbytes);
314
converted = PyObject_CallFunction(converter, "O", item);
321
Py_BEGIN_ALLOW_THREADS
322
coltype = sqlite3_column_type(self->statement->st, i);
324
if (coltype == SQLITE_NULL) {
327
} else if (coltype == SQLITE_INTEGER) {
328
intval = sqlite3_column_int64(self->statement->st, i);
329
if (intval < INT32_MIN || intval > INT32_MAX) {
330
converted = PyLong_FromLongLong(intval);
332
converted = PyLong_FromLong((long)intval);
334
} else if (coltype == SQLITE_FLOAT) {
335
converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i));
336
} else if (coltype == SQLITE_TEXT) {
337
val_str = (const char*)sqlite3_column_text(self->statement->st, i);
338
if ((self->connection->text_factory == (PyObject*)&PyUnicode_Type)
339
|| (self->connection->text_factory == pysqlite_OptimizedUnicode)) {
341
converted = pysqlite_unicode_from_string(val_str,
342
self->connection->text_factory == pysqlite_OptimizedUnicode ? 1 : 0);
345
colname = sqlite3_column_name(self->statement->st, i);
347
colname = "<unknown column name>";
349
PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'",
351
buf_bytes = PyByteArray_FromStringAndSize(buf, strlen(buf));
353
PyErr_SetString(pysqlite_OperationalError, "Could not decode to UTF-8");
355
error_obj = PyUnicode_FromEncodedObject(buf_bytes, "ascii", "replace");
357
PyErr_SetString(pysqlite_OperationalError, "Could not decode to UTF-8");
359
PyErr_SetObject(pysqlite_OperationalError, error_obj);
360
Py_DECREF(error_obj);
362
Py_DECREF(buf_bytes);
365
} else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) {
366
converted = PyBytes_FromString(val_str);
367
} else if (self->connection->text_factory == (PyObject*)&PyByteArray_Type) {
368
converted = PyByteArray_FromStringAndSize(val_str, strlen(val_str));
370
converted = PyObject_CallFunction(self->connection->text_factory, "y", val_str);
373
/* coltype == SQLITE_BLOB */
374
nbytes = sqlite3_column_bytes(self->statement->st, i);
375
buffer = PyBytes_FromStringAndSize(
376
sqlite3_column_blob(self->statement->st, i), nbytes);
385
PyTuple_SetItem(row, i, converted);
388
PyTuple_SetItem(row, i, Py_None);
392
if (PyErr_Occurred()) {
400
PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args)
403
const char* operation_cstr;
404
Py_ssize_t operation_len;
405
PyObject* parameters_list = NULL;
406
PyObject* parameters_iter = NULL;
407
PyObject* parameters = NULL;
413
PY_LONG_LONG lastrowid;
415
PyObject* descriptor;
416
PyObject* second_argument = NULL;
417
int allow_8bit_chars;
419
if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
423
/* Make shooting yourself in the foot with not utf-8 decodable 8-bit-strings harder */
424
allow_8bit_chars = ((self->connection->text_factory != (PyObject*)&PyUnicode_Type) &&
425
(self->connection->text_factory != (PyObject*)&PyUnicode_Type && pysqlite_OptimizedUnicode));
427
Py_XDECREF(self->next_row);
428
self->next_row = NULL;
432
if (!PyArg_ParseTuple(args, "OO", &operation, &second_argument)) {
436
if (!PyUnicode_Check(operation)) {
437
PyErr_SetString(PyExc_ValueError, "operation parameter must be str");
441
if (PyIter_Check(second_argument)) {
443
Py_INCREF(second_argument);
444
parameters_iter = second_argument;
447
parameters_iter = PyObject_GetIter(second_argument);
448
if (!parameters_iter) {
454
if (!PyArg_ParseTuple(args, "O|O", &operation, &second_argument)) {
458
if (!PyUnicode_Check(operation)) {
459
PyErr_SetString(PyExc_ValueError, "operation parameter must be str");
463
parameters_list = PyList_New(0);
464
if (!parameters_list) {
468
if (second_argument == NULL) {
469
second_argument = PyTuple_New(0);
470
if (!second_argument) {
474
Py_INCREF(second_argument);
476
if (PyList_Append(parameters_list, second_argument) != 0) {
477
Py_DECREF(second_argument);
480
Py_DECREF(second_argument);
482
parameters_iter = PyObject_GetIter(parameters_list);
483
if (!parameters_iter) {
488
if (self->statement != NULL) {
489
/* There is an active statement */
490
rc = pysqlite_statement_reset(self->statement);
493
operation_cstr = _PyUnicode_AsStringAndSize(operation, &operation_len);
494
if (operation == NULL)
497
/* reset description and rowcount */
498
Py_DECREF(self->description);
500
self->description = Py_None;
501
self->rowcount = -1L;
503
func_args = PyTuple_New(1);
507
Py_INCREF(operation);
508
if (PyTuple_SetItem(func_args, 0, operation) != 0) {
512
if (self->statement) {
513
(void)pysqlite_statement_reset(self->statement);
514
Py_DECREF(self->statement);
517
self->statement = (pysqlite_Statement*)pysqlite_cache_get(self->connection->statement_cache, func_args);
518
Py_DECREF(func_args);
520
if (!self->statement) {
524
if (self->statement->in_use) {
525
Py_DECREF(self->statement);
526
self->statement = PyObject_New(pysqlite_Statement, &pysqlite_StatementType);
527
if (!self->statement) {
530
rc = pysqlite_statement_create(self->statement, self->connection, operation);
531
if (rc != SQLITE_OK) {
532
Py_CLEAR(self->statement);
537
pysqlite_statement_reset(self->statement);
538
pysqlite_statement_mark_dirty(self->statement);
540
statement_type = detect_statement_type(operation_cstr);
541
if (self->connection->begin_statement) {
542
switch (statement_type) {
543
case STATEMENT_UPDATE:
544
case STATEMENT_DELETE:
545
case STATEMENT_INSERT:
546
case STATEMENT_REPLACE:
547
if (!self->connection->inTransaction) {
548
result = _pysqlite_connection_begin(self->connection);
555
case STATEMENT_OTHER:
556
/* it's a DDL statement or something similar
557
- we better COMMIT first so it works for all cases */
558
if (self->connection->inTransaction) {
559
result = pysqlite_connection_commit(self->connection, NULL);
566
case STATEMENT_SELECT:
568
PyErr_SetString(pysqlite_ProgrammingError,
569
"You cannot execute SELECT statements in executemany().");
576
func_args = PyTuple_New(1);
580
Py_INCREF(operation);
581
if (PyTuple_SetItem(func_args, 0, operation) != 0) {
585
if (self->statement) {
586
(void)pysqlite_statement_reset(self->statement);
587
Py_DECREF(self->statement);
590
self->statement = (pysqlite_Statement*)pysqlite_cache_get(self->connection->statement_cache, func_args);
591
Py_DECREF(func_args);
593
if (!self->statement) {
597
if (self->statement->in_use) {
598
Py_DECREF(self->statement);
599
self->statement = PyObject_New(pysqlite_Statement, &pysqlite_StatementType);
600
if (!self->statement) {
603
rc = pysqlite_statement_create(self->statement, self->connection, operation);
604
if (rc != SQLITE_OK) {
605
Py_CLEAR(self->statement);
610
pysqlite_statement_reset(self->statement);
611
pysqlite_statement_mark_dirty(self->statement);
614
parameters = PyIter_Next(parameters_iter);
619
pysqlite_statement_mark_dirty(self->statement);
621
pysqlite_statement_bind_parameters(self->statement, parameters, allow_8bit_chars);
622
if (PyErr_Occurred()) {
626
if (pysqlite_build_row_cast_map(self) != 0) {
627
PyErr_SetString(pysqlite_OperationalError, "Error while building row_cast_map");
631
/* Keep trying the SQL statement until the schema stops changing. */
633
/* Actually execute the SQL statement. */
634
rc = pysqlite_step(self->statement->st, self->connection);
635
if (rc == SQLITE_DONE || rc == SQLITE_ROW) {
636
/* If it worked, let's get out of the loop */
639
/* Something went wrong. Re-set the statement and try again. */
640
rc = pysqlite_statement_reset(self->statement);
641
if (rc == SQLITE_SCHEMA) {
642
/* If this was a result of the schema changing, let's try
644
rc = pysqlite_statement_recompile(self->statement, parameters);
645
if (rc == SQLITE_OK) {
648
/* If the database gave us an error, promote it to Python. */
649
(void)pysqlite_statement_reset(self->statement);
650
_pysqlite_seterror(self->connection->db, NULL);
654
if (PyErr_Occurred()) {
655
/* there was an error that occurred in a user-defined callback */
656
if (_enable_callback_tracebacks) {
662
(void)pysqlite_statement_reset(self->statement);
663
_pysqlite_seterror(self->connection->db, NULL);
668
if (pysqlite_build_row_cast_map(self) != 0) {
669
PyErr_SetString(pysqlite_OperationalError, "Error while building row_cast_map");
673
if (rc == SQLITE_ROW || (rc == SQLITE_DONE && statement_type == STATEMENT_SELECT)) {
674
Py_BEGIN_ALLOW_THREADS
675
numcols = sqlite3_column_count(self->statement->st);
678
if (self->description == Py_None) {
679
Py_BEGIN_ALLOW_THREADS
680
numcols = sqlite3_column_count(self->statement->st);
683
Py_DECREF(self->description);
684
self->description = PyTuple_New(numcols);
685
if (!self->description) {
688
for (i = 0; i < numcols; i++) {
689
descriptor = PyTuple_New(7);
693
PyTuple_SetItem(descriptor, 0, _pysqlite_build_column_name(sqlite3_column_name(self->statement->st, i)));
694
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 1, Py_None);
695
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 2, Py_None);
696
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 3, Py_None);
697
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 4, Py_None);
698
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 5, Py_None);
699
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 6, Py_None);
700
PyTuple_SetItem(self->description, i, descriptor);
705
if (rc == SQLITE_ROW) {
707
PyErr_SetString(pysqlite_ProgrammingError, "executemany() can only execute DML statements.");
711
self->next_row = _pysqlite_fetch_one_row(self);
712
} else if (rc == SQLITE_DONE && !multiple) {
713
pysqlite_statement_reset(self->statement);
714
Py_CLEAR(self->statement);
717
switch (statement_type) {
718
case STATEMENT_UPDATE:
719
case STATEMENT_DELETE:
720
case STATEMENT_INSERT:
721
case STATEMENT_REPLACE:
722
if (self->rowcount == -1L) {
725
self->rowcount += (long)sqlite3_changes(self->connection->db);
728
Py_DECREF(self->lastrowid);
729
if (!multiple && statement_type == STATEMENT_INSERT) {
730
Py_BEGIN_ALLOW_THREADS
731
lastrowid = sqlite3_last_insert_rowid(self->connection->db);
733
self->lastrowid = PyLong_FromLong((long)lastrowid);
736
self->lastrowid = Py_None;
740
rc = pysqlite_statement_reset(self->statement);
742
Py_XDECREF(parameters);
746
/* just to be sure (implicit ROLLBACKs with ON CONFLICT ROLLBACK/OR
747
* ROLLBACK could have happened */
748
#ifdef SQLITE_VERSION_NUMBER
749
#if SQLITE_VERSION_NUMBER >= 3002002
750
self->connection->inTransaction = !sqlite3_get_autocommit(self->connection->db);
754
Py_XDECREF(parameters);
755
Py_XDECREF(parameters_iter);
756
Py_XDECREF(parameters_list);
758
if (PyErr_Occurred()) {
759
self->rowcount = -1L;
763
return (PyObject*)self;
767
PyObject* pysqlite_cursor_execute(pysqlite_Cursor* self, PyObject* args)
769
return _pysqlite_query_execute(self, 0, args);
772
PyObject* pysqlite_cursor_executemany(pysqlite_Cursor* self, PyObject* args)
774
return _pysqlite_query_execute(self, 1, args);
777
PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)
779
PyObject* script_obj;
780
PyObject* script_str = NULL;
781
const char* script_cstr;
782
sqlite3_stmt* statement;
785
int statement_completed = 0;
787
if (!PyArg_ParseTuple(args, "O", &script_obj)) {
791
if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
795
if (PyUnicode_Check(script_obj)) {
796
script_cstr = _PyUnicode_AsString(script_obj);
801
PyErr_SetString(PyExc_ValueError, "script argument must be unicode.");
806
result = pysqlite_connection_commit(self->connection, NULL);
813
if (!sqlite3_complete(script_cstr)) {
816
statement_completed = 1;
818
Py_BEGIN_ALLOW_THREADS
819
rc = sqlite3_prepare(self->connection->db,
825
if (rc != SQLITE_OK) {
826
_pysqlite_seterror(self->connection->db, NULL);
830
/* execute statement, and ignore results of SELECT statements */
832
while (rc == SQLITE_ROW) {
833
rc = pysqlite_step(statement, self->connection);
834
/* TODO: we probably need more error handling here */
837
if (rc != SQLITE_DONE) {
838
(void)sqlite3_finalize(statement);
839
_pysqlite_seterror(self->connection->db, NULL);
843
rc = sqlite3_finalize(statement);
844
if (rc != SQLITE_OK) {
845
_pysqlite_seterror(self->connection->db, NULL);
851
Py_XDECREF(script_str);
853
if (!statement_completed) {
854
PyErr_SetString(pysqlite_ProgrammingError, "you did not provide a complete SQL statement");
857
if (PyErr_Occurred()) {
861
return (PyObject*)self;
865
PyObject* pysqlite_cursor_getiter(pysqlite_Cursor *self)
868
return (PyObject*)self;
871
PyObject* pysqlite_cursor_iternext(pysqlite_Cursor *self)
873
PyObject* next_row_tuple;
877
if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
881
if (!self->next_row) {
882
if (self->statement) {
883
(void)pysqlite_statement_reset(self->statement);
884
Py_DECREF(self->statement);
885
self->statement = NULL;
890
next_row_tuple = self->next_row;
891
self->next_row = NULL;
893
if (self->row_factory != Py_None) {
894
next_row = PyObject_CallFunction(self->row_factory, "OO", self, next_row_tuple);
895
Py_DECREF(next_row_tuple);
897
next_row = next_row_tuple;
900
if (self->statement) {
901
rc = pysqlite_step(self->statement->st, self->connection);
902
if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
903
(void)pysqlite_statement_reset(self->statement);
905
_pysqlite_seterror(self->connection->db, NULL);
909
if (rc == SQLITE_ROW) {
910
self->next_row = _pysqlite_fetch_one_row(self);
917
PyObject* pysqlite_cursor_fetchone(pysqlite_Cursor* self, PyObject* args)
921
row = pysqlite_cursor_iternext(self);
922
if (!row && !PyErr_Occurred()) {
930
PyObject* pysqlite_cursor_fetchmany(pysqlite_Cursor* self, PyObject* args, PyObject* kwargs)
932
static char *kwlist[] = {"size", NULL, NULL};
936
int maxrows = self->arraysize;
939
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:fetchmany", kwlist, &maxrows)) {
943
list = PyList_New(0);
948
/* just make sure we enter the loop */
952
row = pysqlite_cursor_iternext(self);
954
PyList_Append(list, row);
960
if (++counter == maxrows) {
965
if (PyErr_Occurred()) {
973
PyObject* pysqlite_cursor_fetchall(pysqlite_Cursor* self, PyObject* args)
978
list = PyList_New(0);
983
/* just make sure we enter the loop */
984
row = (PyObject*)Py_None;
987
row = pysqlite_cursor_iternext(self);
989
PyList_Append(list, row);
994
if (PyErr_Occurred()) {
1002
PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args)
1004
/* don't care, return None */
1009
PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args)
1011
if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
1015
if (self->statement) {
1016
(void)pysqlite_statement_reset(self->statement);
1017
Py_CLEAR(self->statement);
1024
static PyMethodDef cursor_methods[] = {
1025
{"execute", (PyCFunction)pysqlite_cursor_execute, METH_VARARGS,
1026
PyDoc_STR("Executes a SQL statement.")},
1027
{"executemany", (PyCFunction)pysqlite_cursor_executemany, METH_VARARGS,
1028
PyDoc_STR("Repeatedly executes a SQL statement.")},
1029
{"executescript", (PyCFunction)pysqlite_cursor_executescript, METH_VARARGS,
1030
PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")},
1031
{"fetchone", (PyCFunction)pysqlite_cursor_fetchone, METH_NOARGS,
1032
PyDoc_STR("Fetches one row from the resultset.")},
1033
{"fetchmany", (PyCFunction)pysqlite_cursor_fetchmany, METH_VARARGS|METH_KEYWORDS,
1034
PyDoc_STR("Fetches several rows from the resultset.")},
1035
{"fetchall", (PyCFunction)pysqlite_cursor_fetchall, METH_NOARGS,
1036
PyDoc_STR("Fetches all rows from the resultset.")},
1037
{"close", (PyCFunction)pysqlite_cursor_close, METH_NOARGS,
1038
PyDoc_STR("Closes the cursor.")},
1039
{"setinputsizes", (PyCFunction)pysqlite_noop, METH_VARARGS,
1040
PyDoc_STR("Required by DB-API. Does nothing in pysqlite.")},
1041
{"setoutputsize", (PyCFunction)pysqlite_noop, METH_VARARGS,
1042
PyDoc_STR("Required by DB-API. Does nothing in pysqlite.")},
1046
static struct PyMemberDef cursor_members[] =
1048
{"connection", T_OBJECT, offsetof(pysqlite_Cursor, connection), READONLY},
1049
{"description", T_OBJECT, offsetof(pysqlite_Cursor, description), READONLY},
1050
{"arraysize", T_INT, offsetof(pysqlite_Cursor, arraysize), 0},
1051
{"lastrowid", T_OBJECT, offsetof(pysqlite_Cursor, lastrowid), READONLY},
1052
{"rowcount", T_LONG, offsetof(pysqlite_Cursor, rowcount), READONLY},
1053
{"row_factory", T_OBJECT, offsetof(pysqlite_Cursor, row_factory), 0},
1057
static char cursor_doc[] =
1058
PyDoc_STR("SQLite database cursor class.");
1060
PyTypeObject pysqlite_CursorType = {
1061
PyVarObject_HEAD_INIT(NULL, 0)
1062
MODULE_NAME ".Cursor", /* tp_name */
1063
sizeof(pysqlite_Cursor), /* tp_basicsize */
1064
0, /* tp_itemsize */
1065
(destructor)pysqlite_cursor_dealloc, /* tp_dealloc */
1069
0, /* tp_reserved */
1071
0, /* tp_as_number */
1072
0, /* tp_as_sequence */
1073
0, /* tp_as_mapping */
1077
0, /* tp_getattro */
1078
0, /* tp_setattro */
1079
0, /* tp_as_buffer */
1080
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
1081
cursor_doc, /* tp_doc */
1082
0, /* tp_traverse */
1084
0, /* tp_richcompare */
1085
0, /* tp_weaklistoffset */
1086
(getiterfunc)pysqlite_cursor_getiter, /* tp_iter */
1087
(iternextfunc)pysqlite_cursor_iternext, /* tp_iternext */
1088
cursor_methods, /* tp_methods */
1089
cursor_members, /* tp_members */
1093
0, /* tp_descr_get */
1094
0, /* tp_descr_set */
1095
0, /* tp_dictoffset */
1096
(initproc)pysqlite_cursor_init, /* tp_init */
1102
extern int pysqlite_cursor_setup_types(void)
1104
pysqlite_CursorType.tp_new = PyType_GenericNew;
1105
return PyType_Ready(&pysqlite_CursorType);