Mercurial > cpython-lru_cache-weakref
annotate Modules/_sqlite/cursor.c @ 39496:352ffe77b71d legacy-trunk
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Mon, 14 Aug 2006 21:42:55 +0000 |
| parents | c4ac6ea497a1 |
| children | fb5eaa4be700 b9d4ced23506 |
| rev | line source |
|---|---|
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1 /* cursor.c - the cursor type |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
2 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2004-2006 Gerhard Häring <gh@ghaering.de> |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
4 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
5 * This file is part of pysqlite. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
6 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
7 * This software is provided 'as-is', without any express or implied |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
8 * warranty. In no event will the authors be held liable for any damages |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
9 * arising from the use of this software. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
10 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
11 * Permission is granted to anyone to use this software for any purpose, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
12 * including commercial applications, and to alter it and redistribute it |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
13 * freely, subject to the following restrictions: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
14 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
15 * 1. The origin of this software must not be misrepresented; you must not |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
16 * claim that you wrote the original software. If you use this software |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
17 * in a product, an acknowledgment in the product documentation would be |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
18 * appreciated but is not required. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
19 * 2. Altered source versions must be plainly marked as such, and must not be |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
20 * misrepresented as being the original software. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
21 * 3. This notice may not be removed or altered from any source distribution. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
22 */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
23 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
24 #include "cursor.h" |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
25 #include "module.h" |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
26 #include "util.h" |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
27 #include "sqlitecompat.h" |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
28 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
29 /* used to decide wether to call PyInt_FromLong or PyLong_FromLongLong */ |
|
38022
3518e94aa663
Fix some warnings on Mac OS X 10.4
Neal Norwitz <nnorwitz@gmail.com>
parents:
37938
diff
changeset
|
30 #ifndef INT32_MIN |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
31 #define INT32_MIN (-2147483647 - 1) |
|
38022
3518e94aa663
Fix some warnings on Mac OS X 10.4
Neal Norwitz <nnorwitz@gmail.com>
parents:
37938
diff
changeset
|
32 #endif |
|
3518e94aa663
Fix some warnings on Mac OS X 10.4
Neal Norwitz <nnorwitz@gmail.com>
parents:
37938
diff
changeset
|
33 #ifndef INT32_MAX |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
34 #define INT32_MAX 2147483647 |
|
38022
3518e94aa663
Fix some warnings on Mac OS X 10.4
Neal Norwitz <nnorwitz@gmail.com>
parents:
37938
diff
changeset
|
35 #endif |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
36 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
37 PyObject* cursor_iternext(Cursor *self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
38 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
39 static StatementKind detect_statement_type(char* statement) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
40 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
41 char buf[20]; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
42 char* src; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
43 char* dst; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
44 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
45 src = statement; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
46 /* skip over whitepace */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
47 while (*src == '\r' || *src == '\n' || *src == ' ' || *src == '\t') { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
48 src++; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
49 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
50 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
51 if (*src == 0) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
52 return STATEMENT_INVALID; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
53 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
54 dst = buf; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
55 *dst = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
56 while (isalpha(*src) && dst - buf < sizeof(buf) - 2) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
57 *dst++ = tolower(*src++); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
58 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
59 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
60 *dst = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
61 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
62 if (!strcmp(buf, "select")) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
63 return STATEMENT_SELECT; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
64 } else if (!strcmp(buf, "insert")) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
65 return STATEMENT_INSERT; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
66 } else if (!strcmp(buf, "update")) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
67 return STATEMENT_UPDATE; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
68 } else if (!strcmp(buf, "delete")) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
69 return STATEMENT_DELETE; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
70 } else if (!strcmp(buf, "replace")) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
71 return STATEMENT_REPLACE; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
72 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
73 return STATEMENT_OTHER; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
74 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
75 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
76 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
77 int cursor_init(Cursor* self, PyObject* args, PyObject* kwargs) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
78 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
79 Connection* connection; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
80 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
81 if (!PyArg_ParseTuple(args, "O!", &ConnectionType, &connection)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
82 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
83 return -1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
84 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
85 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
86 Py_INCREF(connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
87 self->connection = connection; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
88 self->statement = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
89 self->next_row = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
90 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
91 self->row_cast_map = PyList_New(0); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
92 if (!self->row_cast_map) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
93 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
94 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
95 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
96 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
97 self->description = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
98 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
99 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
100 self->lastrowid= Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
101 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
102 self->arraysize = 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
103 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
104 self->rowcount = PyInt_FromLong(-1L); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
105 if (!self->rowcount) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
106 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
107 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
108 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
109 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
110 self->row_factory = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
111 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
112 if (!check_thread(self->connection)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
113 return -1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
114 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
115 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
116 return 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
117 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
118 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
119 void cursor_dealloc(Cursor* self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
120 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
121 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
122 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
123 /* Reset the statement if the user has not closed the cursor */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
124 if (self->statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
125 rc = statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
126 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
127 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
128 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
129 Py_XDECREF(self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
130 Py_XDECREF(self->row_cast_map); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
131 Py_XDECREF(self->description); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
132 Py_XDECREF(self->lastrowid); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
133 Py_XDECREF(self->rowcount); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
134 Py_XDECREF(self->row_factory); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
135 Py_XDECREF(self->next_row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
136 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
137 self->ob_type->tp_free((PyObject*)self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
138 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
139 |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
140 PyObject* _get_converter(PyObject* key) |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
141 { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
142 PyObject* upcase_key; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
143 PyObject* retval; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
144 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
145 upcase_key = PyObject_CallMethod(key, "upper", ""); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
146 if (!upcase_key) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
147 return NULL; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
148 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
149 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
150 retval = PyDict_GetItem(converters, upcase_key); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
151 Py_DECREF(upcase_key); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
152 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
153 return retval; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
154 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
155 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
156 int build_row_cast_map(Cursor* self) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
157 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
158 int i; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
159 const char* type_start = (const char*)-1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
160 const char* pos; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
161 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
162 const char* colname; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
163 const char* decltype; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
164 PyObject* py_decltype; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
165 PyObject* converter; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
166 PyObject* key; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
167 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
168 if (!self->connection->detect_types) { |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
169 return 0; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
170 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
171 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
172 Py_XDECREF(self->row_cast_map); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
173 self->row_cast_map = PyList_New(0); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
174 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
175 for (i = 0; i < sqlite3_column_count(self->statement->st); i++) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
176 converter = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
177 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
178 if (self->connection->detect_types | PARSE_COLNAMES) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
179 colname = sqlite3_column_name(self->statement->st, i); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
180 if (colname) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
181 for (pos = colname; *pos != 0; pos++) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
182 if (*pos == '[') { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
183 type_start = pos + 1; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
184 } else if (*pos == ']' && type_start != (const char*)-1) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
185 key = PyString_FromStringAndSize(type_start, pos - type_start); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
186 if (!key) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
187 /* creating a string failed, but it is too complicated |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
188 * to propagate the error here, we just assume there is |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
189 * no converter and proceed */ |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
190 break; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
191 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
192 |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
193 converter = _get_converter(key); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
194 Py_DECREF(key); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
195 break; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
196 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
197 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
198 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
199 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
200 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
201 if (!converter && self->connection->detect_types | PARSE_DECLTYPES) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
202 decltype = sqlite3_column_decltype(self->statement->st, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
203 if (decltype) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
204 for (pos = decltype;;pos++) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
205 if (*pos == ' ' || *pos == 0) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
206 py_decltype = PyString_FromStringAndSize(decltype, pos - decltype); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
207 if (!py_decltype) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
208 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
209 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
210 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
211 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
212 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
213 |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
214 converter = _get_converter(py_decltype); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
215 Py_DECREF(py_decltype); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
216 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
217 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
218 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
219 if (!converter) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
220 converter = Py_None; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
221 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
222 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
223 if (PyList_Append(self->row_cast_map, converter) != 0) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
224 if (converter != Py_None) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
225 Py_DECREF(converter); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
226 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
227 Py_XDECREF(self->row_cast_map); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
228 self->row_cast_map = NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
229 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
230 return -1; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
231 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
232 } |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
233 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
234 return 0; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
235 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
236 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
237 PyObject* _build_column_name(const char* colname) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
238 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
239 const char* pos; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
240 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
241 if (!colname) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
242 Py_INCREF(Py_None); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
243 return Py_None; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
244 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
245 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
246 for (pos = colname;; pos++) { |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
247 if (*pos == 0 || *pos == '[') { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
248 if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
249 pos--; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
250 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
251 return PyString_FromStringAndSize(colname, pos - colname); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
252 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
253 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
254 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
255 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
256 PyObject* unicode_from_string(const char* val_str, int optimize) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
257 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
258 const char* check; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
259 int is_ascii = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
260 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
261 if (optimize) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
262 is_ascii = 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
263 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
264 check = val_str; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
265 while (*check) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
266 if (*check & 0x80) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
267 is_ascii = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
268 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
269 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
270 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
271 check++; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
272 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
273 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
274 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
275 if (is_ascii) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
276 return PyString_FromString(val_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
277 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
278 return PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
279 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
280 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
281 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
282 /* |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
283 * Returns a row from the currently active SQLite statement |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
284 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
285 * Precondidition: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
286 * - sqlite3_step() has been called before and it returned SQLITE_ROW. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
287 */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
288 PyObject* _fetch_one_row(Cursor* self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
289 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
290 int i, numcols; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
291 PyObject* row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
292 PyObject* item = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
293 int coltype; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
294 PY_LONG_LONG intval; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
295 PyObject* converter; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
296 PyObject* converted; |
| 37387 | 297 Py_ssize_t nbytes; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
298 PyObject* buffer; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
299 void* raw_buffer; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
300 const char* val_str; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
301 char buf[200]; |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
302 const char* colname; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
303 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
304 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
305 numcols = sqlite3_data_count(self->statement->st); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
306 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
307 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
308 row = PyTuple_New(numcols); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
309 if (!row) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
310 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
311 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
312 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
313 for (i = 0; i < numcols; i++) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
314 if (self->connection->detect_types) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
315 converter = PyList_GetItem(self->row_cast_map, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
316 if (!converter) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
317 converter = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
318 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
319 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
320 converter = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
321 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
322 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
323 if (converter != Py_None) { |
|
38978
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
324 nbytes = sqlite3_column_bytes(self->statement->st, i); |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
325 val_str = (const char*)sqlite3_column_blob(self->statement->st, i); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
326 if (!val_str) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
327 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
328 converted = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
329 } else { |
|
38978
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
330 item = PyString_FromStringAndSize(val_str, nbytes); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
331 if (!item) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
332 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
333 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
334 converted = PyObject_CallFunction(converter, "O", item); |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
335 Py_DECREF(item); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
336 if (!converted) { |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
337 break; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
338 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
339 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
340 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
341 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
342 coltype = sqlite3_column_type(self->statement->st, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
343 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
344 if (coltype == SQLITE_NULL) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
345 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
346 converted = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
347 } else if (coltype == SQLITE_INTEGER) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
348 intval = sqlite3_column_int64(self->statement->st, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
349 if (intval < INT32_MIN || intval > INT32_MAX) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
350 converted = PyLong_FromLongLong(intval); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
351 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
352 converted = PyInt_FromLong((long)intval); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
353 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
354 } else if (coltype == SQLITE_FLOAT) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
355 converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i)); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
356 } else if (coltype == SQLITE_TEXT) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
357 val_str = (const char*)sqlite3_column_text(self->statement->st, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
358 if ((self->connection->text_factory == (PyObject*)&PyUnicode_Type) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
359 || (self->connection->text_factory == OptimizedUnicode)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
360 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
361 converted = unicode_from_string(val_str, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
362 self->connection->text_factory == OptimizedUnicode ? 1 : 0); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
363 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
364 if (!converted) { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
365 colname = sqlite3_column_name(self->statement->st, i); |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
366 if (!colname) { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
367 colname = "<unknown column name>"; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
368 } |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
369 PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'", |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
370 colname , val_str); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
371 PyErr_SetString(OperationalError, buf); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
372 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
373 } else if (self->connection->text_factory == (PyObject*)&PyString_Type) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
374 converted = PyString_FromString(val_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
375 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
376 converted = PyObject_CallFunction(self->connection->text_factory, "s", val_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
377 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
378 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
379 /* coltype == SQLITE_BLOB */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
380 nbytes = sqlite3_column_bytes(self->statement->st, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
381 buffer = PyBuffer_New(nbytes); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
382 if (!buffer) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
383 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
384 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
385 if (PyObject_AsWriteBuffer(buffer, &raw_buffer, &nbytes)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
386 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
387 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
388 memcpy(raw_buffer, sqlite3_column_blob(self->statement->st, i), nbytes); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
389 converted = buffer; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
390 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
391 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
392 |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
393 if (converted) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
394 PyTuple_SetItem(row, i, converted); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
395 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
396 Py_INCREF(Py_None); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
397 PyTuple_SetItem(row, i, Py_None); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
398 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
399 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
400 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
401 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
402 Py_DECREF(row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
403 row = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
404 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
405 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
406 return row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
407 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
408 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
409 PyObject* _query_execute(Cursor* self, int multiple, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
410 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
411 PyObject* operation; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
412 PyObject* operation_bytestr = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
413 char* operation_cstr; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
414 PyObject* parameters_list = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
415 PyObject* parameters_iter = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
416 PyObject* parameters = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
417 int i; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
418 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
419 PyObject* func_args; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
420 PyObject* result; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
421 int numcols; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
422 PY_LONG_LONG lastrowid; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
423 int statement_type; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
424 PyObject* descriptor; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
425 PyObject* second_argument = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
426 long rowcount = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
427 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
428 if (!check_thread(self->connection) || !check_connection(self->connection)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
429 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
430 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
431 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
432 Py_XDECREF(self->next_row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
433 self->next_row = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
434 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
435 if (multiple) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
436 /* executemany() */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
437 if (!PyArg_ParseTuple(args, "OO", &operation, &second_argument)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
438 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
439 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
440 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
441 if (!PyString_Check(operation) && !PyUnicode_Check(operation)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
442 PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode"); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
443 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
444 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
445 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
446 if (PyIter_Check(second_argument)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
447 /* iterator */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
448 Py_INCREF(second_argument); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
449 parameters_iter = second_argument; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
450 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
451 /* sequence */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
452 parameters_iter = PyObject_GetIter(second_argument); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
453 if (!parameters_iter) { |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
454 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
455 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
456 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
457 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
458 /* execute() */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
459 if (!PyArg_ParseTuple(args, "O|O", &operation, &second_argument)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
460 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
461 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
462 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
463 if (!PyString_Check(operation) && !PyUnicode_Check(operation)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
464 PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode"); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
465 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
466 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
467 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
468 parameters_list = PyList_New(0); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
469 if (!parameters_list) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
470 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
471 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
472 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
473 if (second_argument == NULL) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
474 second_argument = PyTuple_New(0); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
475 if (!second_argument) { |
|
37461
6ab15fc85c2d
Fix a couple of memory issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
37458
diff
changeset
|
476 goto error; |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
477 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
478 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
479 Py_INCREF(second_argument); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
480 } |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
481 if (PyList_Append(parameters_list, second_argument) != 0) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
482 Py_DECREF(second_argument); |
|
37461
6ab15fc85c2d
Fix a couple of memory issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
37458
diff
changeset
|
483 goto error; |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
484 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
485 Py_DECREF(second_argument); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
486 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
487 parameters_iter = PyObject_GetIter(parameters_list); |
|
37547
48311401a20e
Fix problem (not checking return result) reported by Coverity
Neal Norwitz <nnorwitz@gmail.com>
parents:
37518
diff
changeset
|
488 if (!parameters_iter) { |
|
48311401a20e
Fix problem (not checking return result) reported by Coverity
Neal Norwitz <nnorwitz@gmail.com>
parents:
37518
diff
changeset
|
489 goto error; |
|
48311401a20e
Fix problem (not checking return result) reported by Coverity
Neal Norwitz <nnorwitz@gmail.com>
parents:
37518
diff
changeset
|
490 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
491 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
492 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
493 if (self->statement != NULL) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
494 /* There is an active statement */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
495 rc = statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
496 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
497 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
498 if (PyString_Check(operation)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
499 operation_cstr = PyString_AsString(operation); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
500 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
501 operation_bytestr = PyUnicode_AsUTF8String(operation); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
502 if (!operation_bytestr) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
503 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
504 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
505 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
506 operation_cstr = PyString_AsString(operation_bytestr); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
507 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
508 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
509 /* reset description and rowcount */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
510 Py_DECREF(self->description); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
511 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
512 self->description = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
513 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
514 Py_DECREF(self->rowcount); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
515 self->rowcount = PyInt_FromLong(-1L); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
516 if (!self->rowcount) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
517 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
518 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
519 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
520 statement_type = detect_statement_type(operation_cstr); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
521 if (self->connection->begin_statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
522 switch (statement_type) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
523 case STATEMENT_UPDATE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
524 case STATEMENT_DELETE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
525 case STATEMENT_INSERT: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
526 case STATEMENT_REPLACE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
527 if (!self->connection->inTransaction) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
528 result = _connection_begin(self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
529 if (!result) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
530 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
531 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
532 Py_DECREF(result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
533 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
534 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
535 case STATEMENT_OTHER: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
536 /* it's a DDL statement or something similar |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
537 - we better COMMIT first so it works for all cases */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
538 if (self->connection->inTransaction) { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
539 result = connection_commit(self->connection, NULL); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
540 if (!result) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
541 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
542 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
543 Py_DECREF(result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
544 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
545 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
546 case STATEMENT_SELECT: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
547 if (multiple) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
548 PyErr_SetString(ProgrammingError, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
549 "You cannot execute SELECT statements in executemany()."); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
550 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
551 } |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
552 break; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
553 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
554 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
555 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
556 func_args = PyTuple_New(1); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
557 if (!func_args) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
558 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
559 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
560 Py_INCREF(operation); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
561 if (PyTuple_SetItem(func_args, 0, operation) != 0) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
562 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
563 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
564 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
565 if (self->statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
566 (void)statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
567 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
568 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
569 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
570 self->statement = (Statement*)cache_get(self->connection->statement_cache, func_args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
571 Py_DECREF(func_args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
572 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
573 if (!self->statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
574 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
575 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
576 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
577 if (self->statement->in_use) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
578 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
579 self->statement = PyObject_New(Statement, &StatementType); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
580 if (!self->statement) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
581 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
582 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
583 rc = statement_create(self->statement, self->connection, operation); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
584 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
585 self->statement = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
586 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
587 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
588 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
589 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
590 statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
591 statement_mark_dirty(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
592 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
593 while (1) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
594 parameters = PyIter_Next(parameters_iter); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
595 if (!parameters) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
596 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
597 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
598 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
599 statement_mark_dirty(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
600 |
|
37381
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
601 statement_bind_parameters(self->statement, parameters); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
602 if (PyErr_Occurred()) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
603 goto error; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
604 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
605 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
606 if (build_row_cast_map(self) != 0) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
607 PyErr_SetString(OperationalError, "Error while building row_cast_map"); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
608 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
609 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
610 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
611 rc = _sqlite_step_with_busyhandler(self->statement->st, self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
612 if (rc != SQLITE_DONE && rc != SQLITE_ROW) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
613 rc = statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
614 if (rc == SQLITE_SCHEMA) { |
|
37381
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
615 rc = statement_recompile(self->statement, parameters); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
616 if (rc == SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
617 rc = _sqlite_step_with_busyhandler(self->statement->st, self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
618 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
619 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
620 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
621 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
622 } else { |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
623 if (PyErr_Occurred()) { |
| 39251 | 624 /* there was an error that occurred in a user-defined callback */ |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
625 if (_enable_callback_tracebacks) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
626 PyErr_Print(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
627 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
628 PyErr_Clear(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
629 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
38022
diff
changeset
|
630 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
631 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
632 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
633 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
634 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
635 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
636 if (rc == SQLITE_ROW || (rc == SQLITE_DONE && statement_type == STATEMENT_SELECT)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
637 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
638 numcols = sqlite3_column_count(self->statement->st); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
639 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
640 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
641 if (self->description == Py_None) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
642 Py_DECREF(self->description); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
643 self->description = PyTuple_New(numcols); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
644 if (!self->description) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
645 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
646 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
647 for (i = 0; i < numcols; i++) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
648 descriptor = PyTuple_New(7); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
649 if (!descriptor) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
650 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
651 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
652 PyTuple_SetItem(descriptor, 0, _build_column_name(sqlite3_column_name(self->statement->st, i))); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
653 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 1, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
654 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 2, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
655 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 3, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
656 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 4, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
657 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 5, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
658 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 6, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
659 PyTuple_SetItem(self->description, i, descriptor); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
660 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
661 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
662 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
663 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
664 if (rc == SQLITE_ROW) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
665 if (multiple) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
666 PyErr_SetString(ProgrammingError, "executemany() can only execute DML statements."); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
667 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
668 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
669 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
670 self->next_row = _fetch_one_row(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
671 } else if (rc == SQLITE_DONE && !multiple) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
672 statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
673 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
674 self->statement = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
675 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
676 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
677 switch (statement_type) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
678 case STATEMENT_UPDATE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
679 case STATEMENT_DELETE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
680 case STATEMENT_INSERT: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
681 case STATEMENT_REPLACE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
682 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
683 rowcount += (long)sqlite3_changes(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
684 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
685 Py_DECREF(self->rowcount); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
686 self->rowcount = PyInt_FromLong(rowcount); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
687 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
688 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
689 Py_DECREF(self->lastrowid); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
690 if (statement_type == STATEMENT_INSERT) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
691 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
692 lastrowid = sqlite3_last_insert_rowid(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
693 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
694 self->lastrowid = PyInt_FromLong((long)lastrowid); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
695 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
696 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
697 self->lastrowid = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
698 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
699 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
700 if (multiple) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
701 rc = statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
702 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
703 Py_XDECREF(parameters); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
704 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
705 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
706 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
707 Py_XDECREF(operation_bytestr); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
708 Py_XDECREF(parameters); |
|
37547
48311401a20e
Fix problem (not checking return result) reported by Coverity
Neal Norwitz <nnorwitz@gmail.com>
parents:
37518
diff
changeset
|
709 Py_XDECREF(parameters_iter); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
710 Py_XDECREF(parameters_list); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
711 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
712 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
713 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
714 } else { |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
715 Py_INCREF(self); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
716 return (PyObject*)self; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
717 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
718 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
719 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
720 PyObject* cursor_execute(Cursor* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
721 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
722 return _query_execute(self, 0, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
723 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
724 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
725 PyObject* cursor_executemany(Cursor* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
726 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
727 return _query_execute(self, 1, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
728 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
729 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
730 PyObject* cursor_executescript(Cursor* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
731 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
732 PyObject* script_obj; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
733 PyObject* script_str = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
734 const char* script_cstr; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
735 sqlite3_stmt* statement; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
736 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
737 PyObject* result; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
738 int statement_completed = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
739 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
740 if (!PyArg_ParseTuple(args, "O", &script_obj)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
741 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
742 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
743 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
744 if (!check_thread(self->connection) || !check_connection(self->connection)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
745 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
746 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
747 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
748 if (PyString_Check(script_obj)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
749 script_cstr = PyString_AsString(script_obj); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
750 } else if (PyUnicode_Check(script_obj)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
751 script_str = PyUnicode_AsUTF8String(script_obj); |
|
37461
6ab15fc85c2d
Fix a couple of memory issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
37458
diff
changeset
|
752 if (!script_str) { |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
753 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
754 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
755 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
756 script_cstr = PyString_AsString(script_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
757 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
758 PyErr_SetString(PyExc_ValueError, "script argument must be unicode or string."); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
759 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
760 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
761 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
762 /* commit first */ |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
763 result = connection_commit(self->connection, NULL); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
764 if (!result) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
765 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
766 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
767 Py_DECREF(result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
768 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
769 while (1) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
770 if (!sqlite3_complete(script_cstr)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
771 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
772 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
773 statement_completed = 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
774 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
775 rc = sqlite3_prepare(self->connection->db, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
776 script_cstr, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
777 -1, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
778 &statement, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
779 &script_cstr); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
780 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
781 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
782 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
783 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
784 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
785 /* execute statement, and ignore results of SELECT statements */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
786 rc = SQLITE_ROW; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
787 while (rc == SQLITE_ROW) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
788 rc = _sqlite_step_with_busyhandler(statement, self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
789 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
790 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
791 if (rc != SQLITE_DONE) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
792 (void)sqlite3_finalize(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
793 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
794 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
795 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
796 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
797 rc = sqlite3_finalize(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
798 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
799 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
800 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
801 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
802 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
803 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
804 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
805 Py_XDECREF(script_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
806 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
807 if (!statement_completed) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
808 PyErr_SetString(ProgrammingError, "you did not provide a complete SQL statement"); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
809 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
810 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
811 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
812 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
813 } else { |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
814 Py_INCREF(self); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
815 return (PyObject*)self; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
816 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
817 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
818 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
819 PyObject* cursor_getiter(Cursor *self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
820 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
821 Py_INCREF(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
822 return (PyObject*)self; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
823 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
824 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
825 PyObject* cursor_iternext(Cursor *self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
826 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
827 PyObject* next_row_tuple; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
828 PyObject* next_row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
829 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
830 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
831 if (!check_thread(self->connection) || !check_connection(self->connection)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
832 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
833 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
834 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
835 if (!self->next_row) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
836 if (self->statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
837 (void)statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
838 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
839 self->statement = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
840 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
841 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
842 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
843 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
844 next_row_tuple = self->next_row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
845 self->next_row = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
846 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
847 if (self->row_factory != Py_None) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
848 next_row = PyObject_CallFunction(self->row_factory, "OO", self, next_row_tuple); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
849 Py_DECREF(next_row_tuple); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
850 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
851 next_row = next_row_tuple; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
852 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
853 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
854 rc = _sqlite_step_with_busyhandler(self->statement->st, self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
855 if (rc != SQLITE_DONE && rc != SQLITE_ROW) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
856 Py_DECREF(next_row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
857 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
858 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
859 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
860 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
861 if (rc == SQLITE_ROW) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
862 self->next_row = _fetch_one_row(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
863 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
864 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
865 return next_row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
866 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
867 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
868 PyObject* cursor_fetchone(Cursor* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
869 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
870 PyObject* row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
871 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
872 row = cursor_iternext(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
873 if (!row && !PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
874 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
875 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
876 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
877 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
878 return row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
879 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
880 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
881 PyObject* cursor_fetchmany(Cursor* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
882 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
883 PyObject* row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
884 PyObject* list; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
885 int maxrows = self->arraysize; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
886 int counter = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
887 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
888 if (!PyArg_ParseTuple(args, "|i", &maxrows)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
889 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
890 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
891 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
892 list = PyList_New(0); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
893 if (!list) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
894 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
895 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
896 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
897 /* just make sure we enter the loop */ |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
898 row = Py_None; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
899 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
900 while (row) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
901 row = cursor_iternext(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
902 if (row) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
903 PyList_Append(list, row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
904 Py_DECREF(row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
905 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
906 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
907 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
908 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
909 if (++counter == maxrows) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
910 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
911 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
912 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
913 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
914 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
915 Py_DECREF(list); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
916 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
917 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
918 return list; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
919 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
920 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
921 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
922 PyObject* cursor_fetchall(Cursor* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
923 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
924 PyObject* row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
925 PyObject* list; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
926 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
927 list = PyList_New(0); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
928 if (!list) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
929 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
930 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
931 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
932 /* just make sure we enter the loop */ |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
933 row = (PyObject*)Py_None; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
934 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
935 while (row) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
936 row = cursor_iternext(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
937 if (row) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
938 PyList_Append(list, row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
939 Py_DECREF(row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
940 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
941 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
942 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
943 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
944 Py_DECREF(list); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
945 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
946 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
947 return list; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
948 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
949 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
950 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
951 PyObject* pysqlite_noop(Connection* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
952 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
953 /* don't care, return None */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
954 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
955 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
956 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
957 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
958 PyObject* cursor_close(Cursor* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
959 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
960 if (!check_thread(self->connection) || !check_connection(self->connection)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
961 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
962 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
963 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
964 if (self->statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
965 (void)statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
966 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
967 self->statement = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
968 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
969 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
970 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
971 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
972 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
973 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
974 static PyMethodDef cursor_methods[] = { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
975 {"execute", (PyCFunction)cursor_execute, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
976 PyDoc_STR("Executes a SQL statement.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
977 {"executemany", (PyCFunction)cursor_executemany, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
978 PyDoc_STR("Repeatedly executes a SQL statement.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
979 {"executescript", (PyCFunction)cursor_executescript, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
980 PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
981 {"fetchone", (PyCFunction)cursor_fetchone, METH_NOARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
982 PyDoc_STR("Fetches several rows from the resultset.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
983 {"fetchmany", (PyCFunction)cursor_fetchmany, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
984 PyDoc_STR("Fetches all rows from the resultset.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
985 {"fetchall", (PyCFunction)cursor_fetchall, METH_NOARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
986 PyDoc_STR("Fetches one row from the resultset.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
987 {"close", (PyCFunction)cursor_close, METH_NOARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
988 PyDoc_STR("Closes the cursor.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
989 {"setinputsizes", (PyCFunction)pysqlite_noop, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
990 PyDoc_STR("Required by DB-API. Does nothing in pysqlite.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
991 {"setoutputsize", (PyCFunction)pysqlite_noop, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
992 PyDoc_STR("Required by DB-API. Does nothing in pysqlite.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
993 {NULL, NULL} |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
994 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
995 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
996 static struct PyMemberDef cursor_members[] = |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
997 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
998 {"connection", T_OBJECT, offsetof(Cursor, connection), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
999 {"description", T_OBJECT, offsetof(Cursor, description), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1000 {"arraysize", T_INT, offsetof(Cursor, arraysize), 0}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1001 {"lastrowid", T_OBJECT, offsetof(Cursor, lastrowid), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1002 {"rowcount", T_OBJECT, offsetof(Cursor, rowcount), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1003 {"row_factory", T_OBJECT, offsetof(Cursor, row_factory), 0}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1004 {NULL} |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1005 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1006 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
1007 static char cursor_doc[] = |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
1008 PyDoc_STR("SQLite database cursor class."); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
1009 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1010 PyTypeObject CursorType = { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1011 PyObject_HEAD_INIT(NULL) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1012 0, /* ob_size */ |
|
37495
d3969aeba777
upgrade to final version of pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37461
diff
changeset
|
1013 MODULE_NAME ".Cursor", /* tp_name */ |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1014 sizeof(Cursor), /* tp_basicsize */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1015 0, /* tp_itemsize */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1016 (destructor)cursor_dealloc, /* tp_dealloc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1017 0, /* tp_print */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1018 0, /* tp_getattr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1019 0, /* tp_setattr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1020 0, /* tp_compare */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1021 0, /* tp_repr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1022 0, /* tp_as_number */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1023 0, /* tp_as_sequence */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1024 0, /* tp_as_mapping */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1025 0, /* tp_hash */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1026 0, /* tp_call */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1027 0, /* tp_str */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1028 0, /* tp_getattro */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1029 0, /* tp_setattro */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1030 0, /* tp_as_buffer */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1031 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_ITER|Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37547
diff
changeset
|
1032 cursor_doc, /* tp_doc */ |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1033 0, /* tp_traverse */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1034 0, /* tp_clear */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1035 0, /* tp_richcompare */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1036 0, /* tp_weaklistoffset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1037 (getiterfunc)cursor_getiter, /* tp_iter */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1038 (iternextfunc)cursor_iternext, /* tp_iternext */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1039 cursor_methods, /* tp_methods */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1040 cursor_members, /* tp_members */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1041 0, /* tp_getset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1042 0, /* tp_base */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1043 0, /* tp_dict */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1044 0, /* tp_descr_get */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1045 0, /* tp_descr_set */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1046 0, /* tp_dictoffset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1047 (initproc)cursor_init, /* tp_init */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1048 0, /* tp_alloc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1049 0, /* tp_new */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1050 0 /* tp_free */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1051 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1052 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1053 extern int cursor_setup_types(void) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1054 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1055 CursorType.tp_new = PyType_GenericNew; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1056 return PyType_Ready(&CursorType); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1057 } |
