Mercurial > cpython-lru_cache-weakref
annotate Modules/_sqlite/cursor.c @ 37829:f048116aade0 legacy-trunk
It's probably a good idea to actually *install* setuptools, too. ;)
| author | Phillip J. Eby <pje@telecommunity.com> |
|---|---|
| date | Tue, 18 Apr 2006 04:34:50 +0000 |
| parents | 48311401a20e |
| children | 7da4af95ebad |
| 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 */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
30 #define INT32_MIN (-2147483647 - 1) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
31 #define INT32_MAX 2147483647 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
32 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
33 PyObject* cursor_iternext(Cursor *self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
34 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
35 static StatementKind detect_statement_type(char* statement) |
|
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 char buf[20]; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
38 char* src; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
39 char* dst; |
|
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 src = statement; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
42 /* skip over whitepace */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
43 while (*src == '\r' || *src == '\n' || *src == ' ' || *src == '\t') { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
44 src++; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
45 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
46 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
47 if (*src == 0) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
48 return STATEMENT_INVALID; |
|
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 dst = buf; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
51 *dst = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
52 while (isalpha(*src) && dst - buf < sizeof(buf) - 2) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
53 *dst++ = tolower(*src++); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
54 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
55 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
56 *dst = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
57 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
58 if (!strcmp(buf, "select")) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
59 return STATEMENT_SELECT; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
60 } else if (!strcmp(buf, "insert")) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
61 return STATEMENT_INSERT; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
62 } else if (!strcmp(buf, "update")) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
63 return STATEMENT_UPDATE; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
64 } else if (!strcmp(buf, "delete")) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
65 return STATEMENT_DELETE; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
66 } else if (!strcmp(buf, "replace")) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
67 return STATEMENT_REPLACE; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
68 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
69 return STATEMENT_OTHER; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
70 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
71 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
72 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
73 int cursor_init(Cursor* self, PyObject* args, PyObject* kwargs) |
|
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 Connection* connection; |
|
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 if (!PyArg_ParseTuple(args, "O!", &ConnectionType, &connection)) |
|
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 return -1; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
82 Py_INCREF(connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
83 self->connection = connection; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
84 self->statement = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
85 self->next_row = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
86 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
87 self->row_cast_map = PyList_New(0); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
88 if (!self->row_cast_map) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
89 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
90 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
91 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
92 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
93 self->description = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
94 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
95 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
96 self->lastrowid= Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
97 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
98 self->arraysize = 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
99 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
100 self->rowcount = PyInt_FromLong(-1L); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
101 if (!self->rowcount) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
102 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
103 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
104 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
105 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
106 self->row_factory = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
107 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
108 if (!check_thread(self->connection)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
109 return -1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
110 } |
|
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 return 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
113 } |
|
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 void cursor_dealloc(Cursor* self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
116 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
117 int rc; |
|
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 /* 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
|
120 if (self->statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
121 rc = statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
122 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
123 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
124 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
125 Py_XDECREF(self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
126 Py_XDECREF(self->row_cast_map); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
127 Py_XDECREF(self->description); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
128 Py_XDECREF(self->lastrowid); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
129 Py_XDECREF(self->rowcount); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
130 Py_XDECREF(self->row_factory); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
131 Py_XDECREF(self->next_row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
132 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
133 self->ob_type->tp_free((PyObject*)self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
134 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
135 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
136 int build_row_cast_map(Cursor* self) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
137 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
138 int i; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
139 const char* type_start = (const char*)-1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
140 const char* pos; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
141 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
142 const char* colname; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
143 const char* decltype; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
144 PyObject* py_decltype; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
145 PyObject* converter; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
146 PyObject* key; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
147 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
148 if (!self->connection->detect_types) { |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
149 return 0; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
150 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
151 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
152 Py_XDECREF(self->row_cast_map); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
153 self->row_cast_map = PyList_New(0); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
154 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
155 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
|
156 converter = NULL; |
|
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 if (self->connection->detect_types | PARSE_COLNAMES) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
159 colname = sqlite3_column_name(self->statement->st, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
160 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
161 for (pos = colname; *pos != 0; pos++) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
162 if (*pos == '[') { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
163 type_start = pos + 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
164 } else if (*pos == ']' && type_start != (const char*)-1) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
165 key = PyString_FromStringAndSize(type_start, pos - type_start); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
166 if (!key) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
167 /* creating a string failed, but it is too complicated |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
168 * to propagate the error here, we just assume there is |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
169 * no converter and proceed */ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
170 break; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
171 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
172 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
173 converter = PyDict_GetItem(converters, key); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
174 Py_DECREF(key); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
175 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
176 } |
|
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 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
179 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
180 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
181 if (!converter && self->connection->detect_types | PARSE_DECLTYPES) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
182 decltype = sqlite3_column_decltype(self->statement->st, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
183 if (decltype) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
184 for (pos = decltype;;pos++) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
185 if (*pos == ' ' || *pos == 0) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
186 py_decltype = PyString_FromStringAndSize(decltype, pos - decltype); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
187 if (!py_decltype) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
188 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
189 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
190 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
191 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
192 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
193 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
194 converter = PyDict_GetItem(converters, py_decltype); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
195 Py_DECREF(py_decltype); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
196 } |
|
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 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
199 if (!converter) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
200 converter = Py_None; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
201 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
202 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
203 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
|
204 if (converter != Py_None) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
205 Py_DECREF(converter); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
206 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
207 Py_XDECREF(self->row_cast_map); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
208 self->row_cast_map = NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
209 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
210 return -1; |
|
37362
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 } |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
213 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
214 return 0; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
215 } |
|
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 PyObject* _build_column_name(const char* colname) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
218 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
219 const char* pos; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
220 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
221 if (!colname) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
222 Py_INCREF(Py_None); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
223 return Py_None; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
224 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
225 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
226 for (pos = colname;; pos++) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
227 if (*pos == 0 || *pos == ' ') { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
228 return PyString_FromStringAndSize(colname, pos - colname); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
229 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
230 } |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
233 PyObject* unicode_from_string(const char* val_str, int optimize) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
234 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
235 const char* check; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
236 int is_ascii = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
237 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
238 if (optimize) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
239 is_ascii = 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
240 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
241 check = val_str; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
242 while (*check) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
243 if (*check & 0x80) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
244 is_ascii = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
245 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
246 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
247 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
248 check++; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
249 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
250 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
251 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
252 if (is_ascii) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
253 return PyString_FromString(val_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
254 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
255 return PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
256 } |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
259 /* |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
260 * Returns a row from the currently active SQLite statement |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
261 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
262 * Precondidition: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
263 * - 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
|
264 */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
265 PyObject* _fetch_one_row(Cursor* self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
266 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
267 int i, numcols; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
268 PyObject* row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
269 PyObject* item = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
270 int coltype; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
271 PY_LONG_LONG intval; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
272 PyObject* converter; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
273 PyObject* converted; |
| 37387 | 274 Py_ssize_t nbytes; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
275 PyObject* buffer; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
276 void* raw_buffer; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
277 const char* val_str; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
278 char buf[200]; |
|
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 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
281 numcols = sqlite3_data_count(self->statement->st); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
282 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
283 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
284 row = PyTuple_New(numcols); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
285 if (!row) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
286 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
287 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
288 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
289 for (i = 0; i < numcols; i++) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
290 if (self->connection->detect_types) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
291 converter = PyList_GetItem(self->row_cast_map, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
292 if (!converter) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
293 converter = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
294 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
295 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
296 converter = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
297 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
298 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
299 if (converter != Py_None) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
300 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
|
301 if (!val_str) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
302 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
303 converted = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
304 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
305 item = PyString_FromString(val_str); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
306 if (!item) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
307 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
308 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
309 converted = PyObject_CallFunction(converter, "O", item); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
310 if (!converted) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
311 /* TODO: have a way to log these errors */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
312 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
313 converted = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
314 PyErr_Clear(); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
315 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
316 Py_DECREF(item); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
317 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
318 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
319 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
320 coltype = sqlite3_column_type(self->statement->st, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
321 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
322 if (coltype == SQLITE_NULL) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
323 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
324 converted = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
325 } else if (coltype == SQLITE_INTEGER) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
326 intval = sqlite3_column_int64(self->statement->st, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
327 if (intval < INT32_MIN || intval > INT32_MAX) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
328 converted = PyLong_FromLongLong(intval); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
329 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
330 converted = PyInt_FromLong((long)intval); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
331 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
332 } else if (coltype == SQLITE_FLOAT) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
333 converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i)); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
334 } else if (coltype == SQLITE_TEXT) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
335 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
|
336 if ((self->connection->text_factory == (PyObject*)&PyUnicode_Type) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
337 || (self->connection->text_factory == OptimizedUnicode)) { |
|
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 converted = unicode_from_string(val_str, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
340 self->connection->text_factory == OptimizedUnicode ? 1 : 0); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
341 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
342 if (!converted) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
343 PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column %s with text %s", |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
344 sqlite3_column_name(self->statement->st, i), val_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
345 PyErr_SetString(OperationalError, buf); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
346 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
347 } else if (self->connection->text_factory == (PyObject*)&PyString_Type) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
348 converted = PyString_FromString(val_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
349 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
350 converted = PyObject_CallFunction(self->connection->text_factory, "s", val_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
351 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
352 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
353 /* coltype == SQLITE_BLOB */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
354 nbytes = sqlite3_column_bytes(self->statement->st, i); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
355 buffer = PyBuffer_New(nbytes); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
356 if (!buffer) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
357 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
358 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
359 if (PyObject_AsWriteBuffer(buffer, &raw_buffer, &nbytes)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
360 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
361 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
362 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
|
363 converted = buffer; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
364 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
365 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
366 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
367 PyTuple_SetItem(row, i, converted); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
368 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
369 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
370 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
371 Py_DECREF(row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
372 row = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
373 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
374 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
375 return row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
376 } |
|
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 PyObject* _query_execute(Cursor* self, int multiple, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
379 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
380 PyObject* operation; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
381 PyObject* operation_bytestr = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
382 char* operation_cstr; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
383 PyObject* parameters_list = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
384 PyObject* parameters_iter = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
385 PyObject* parameters = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
386 int i; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
387 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
388 PyObject* func_args; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
389 PyObject* result; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
390 int numcols; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
391 PY_LONG_LONG lastrowid; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
392 int statement_type; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
393 PyObject* descriptor; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
394 PyObject* second_argument = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
395 long rowcount = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
396 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
397 if (!check_thread(self->connection) || !check_connection(self->connection)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
398 return NULL; |
|
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 Py_XDECREF(self->next_row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
402 self->next_row = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
403 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
404 if (multiple) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
405 /* executemany() */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
406 if (!PyArg_ParseTuple(args, "OO", &operation, &second_argument)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
407 return NULL; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
410 if (!PyString_Check(operation) && !PyUnicode_Check(operation)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
411 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
|
412 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
413 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
414 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
415 if (PyIter_Check(second_argument)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
416 /* iterator */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
417 Py_INCREF(second_argument); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
418 parameters_iter = second_argument; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
419 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
420 /* sequence */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
421 parameters_iter = PyObject_GetIter(second_argument); |
|
37518
79d3c4ad9310
This change shouldn't have any functional effect. Coverity was
Neal Norwitz <nnorwitz@gmail.com>
parents:
37495
diff
changeset
|
422 if (!parameters_iter) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
423 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
424 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
425 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
426 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
427 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
428 /* execute() */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
429 if (!PyArg_ParseTuple(args, "O|O", &operation, &second_argument)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
430 return NULL; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
433 if (!PyString_Check(operation) && !PyUnicode_Check(operation)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
434 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
|
435 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
436 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
437 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
438 parameters_list = PyList_New(0); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
439 if (!parameters_list) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
440 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
441 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
442 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
443 if (second_argument == NULL) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
444 second_argument = PyTuple_New(0); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
445 if (!second_argument) { |
|
37461
6ab15fc85c2d
Fix a couple of memory issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
37458
diff
changeset
|
446 goto error; |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
447 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
448 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
449 Py_INCREF(second_argument); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
450 } |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
451 if (PyList_Append(parameters_list, second_argument) != 0) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
452 Py_DECREF(second_argument); |
|
37461
6ab15fc85c2d
Fix a couple of memory issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
37458
diff
changeset
|
453 goto error; |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
454 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
455 Py_DECREF(second_argument); |
|
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 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
|
458 if (!parameters_iter) { |
|
48311401a20e
Fix problem (not checking return result) reported by Coverity
Neal Norwitz <nnorwitz@gmail.com>
parents:
37518
diff
changeset
|
459 goto error; |
|
48311401a20e
Fix problem (not checking return result) reported by Coverity
Neal Norwitz <nnorwitz@gmail.com>
parents:
37518
diff
changeset
|
460 } |
|
37362
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 (self->statement != NULL) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
464 /* There is an active statement */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
465 rc = statement_reset(self->statement); |
|
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 if (PyString_Check(operation)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
469 operation_cstr = PyString_AsString(operation); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
470 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
471 operation_bytestr = PyUnicode_AsUTF8String(operation); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
472 if (!operation_bytestr) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
473 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
474 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
475 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
476 operation_cstr = PyString_AsString(operation_bytestr); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
477 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
478 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
479 /* reset description and rowcount */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
480 Py_DECREF(self->description); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
481 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
482 self->description = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
483 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
484 Py_DECREF(self->rowcount); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
485 self->rowcount = PyInt_FromLong(-1L); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
486 if (!self->rowcount) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
487 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
488 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
489 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
490 statement_type = detect_statement_type(operation_cstr); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
491 if (self->connection->begin_statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
492 switch (statement_type) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
493 case STATEMENT_UPDATE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
494 case STATEMENT_DELETE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
495 case STATEMENT_INSERT: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
496 case STATEMENT_REPLACE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
497 if (!self->connection->inTransaction) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
498 result = _connection_begin(self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
499 if (!result) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
500 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
501 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
502 Py_DECREF(result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
503 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
504 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
505 case STATEMENT_OTHER: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
506 /* it's a DDL statement or something similar |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
507 - we better COMMIT first so it works for all cases */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
508 if (self->connection->inTransaction) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
509 func_args = PyTuple_New(0); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
510 if (!func_args) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
511 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
512 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
513 result = connection_commit(self->connection, func_args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
514 Py_DECREF(func_args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
515 if (!result) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
516 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
517 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
518 Py_DECREF(result); |
|
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 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
521 case STATEMENT_SELECT: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
522 if (multiple) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
523 PyErr_SetString(ProgrammingError, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
524 "You cannot execute SELECT statements in executemany()."); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
525 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
526 } |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
527 break; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
528 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
529 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
530 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
531 func_args = PyTuple_New(1); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
532 if (!func_args) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
533 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
534 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
535 Py_INCREF(operation); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
536 if (PyTuple_SetItem(func_args, 0, operation) != 0) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
537 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
538 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
539 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
540 if (self->statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
541 (void)statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
542 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
543 } |
|
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 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
|
546 Py_DECREF(func_args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
547 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
548 if (!self->statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
549 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
550 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
551 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
552 if (self->statement->in_use) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
553 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
554 self->statement = PyObject_New(Statement, &StatementType); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
555 if (!self->statement) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
556 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
557 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
558 rc = statement_create(self->statement, self->connection, operation); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
559 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
560 self->statement = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
561 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
562 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
563 } |
|
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 statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
566 statement_mark_dirty(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
567 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
568 while (1) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
569 parameters = PyIter_Next(parameters_iter); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
570 if (!parameters) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
571 break; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
574 statement_mark_dirty(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
575 |
|
37381
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
576 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
|
577 if (PyErr_Occurred()) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
578 goto error; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
579 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
580 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
581 if (build_row_cast_map(self) != 0) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
582 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
|
583 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
584 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
585 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
586 rc = _sqlite_step_with_busyhandler(self->statement->st, self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
587 if (rc != SQLITE_DONE && rc != SQLITE_ROW) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
588 rc = statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
589 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
|
590 rc = statement_recompile(self->statement, parameters); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
591 if (rc == SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
592 rc = _sqlite_step_with_busyhandler(self->statement->st, self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
593 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
594 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
595 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
596 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
597 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
598 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
599 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
600 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
601 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
602 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
603 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
|
604 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
605 numcols = sqlite3_column_count(self->statement->st); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
606 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
607 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
608 if (self->description == Py_None) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
609 Py_DECREF(self->description); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
610 self->description = PyTuple_New(numcols); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
611 if (!self->description) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
612 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
613 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
614 for (i = 0; i < numcols; i++) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
615 descriptor = PyTuple_New(7); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
616 if (!descriptor) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
617 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
618 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
619 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
|
620 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 1, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
621 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 2, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
622 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 3, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
623 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 4, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
624 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 5, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
625 Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 6, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
626 PyTuple_SetItem(self->description, i, descriptor); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
627 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
628 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
629 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
630 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
631 if (rc == SQLITE_ROW) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
632 if (multiple) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
633 PyErr_SetString(ProgrammingError, "executemany() can only execute DML statements."); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
634 goto error; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
637 self->next_row = _fetch_one_row(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
638 } else if (rc == SQLITE_DONE && !multiple) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
639 statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
640 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
641 self->statement = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
642 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
643 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
644 switch (statement_type) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
645 case STATEMENT_UPDATE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
646 case STATEMENT_DELETE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
647 case STATEMENT_INSERT: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
648 case STATEMENT_REPLACE: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
649 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
650 rowcount += (long)sqlite3_changes(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
651 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
652 Py_DECREF(self->rowcount); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
653 self->rowcount = PyInt_FromLong(rowcount); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
654 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
655 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
656 Py_DECREF(self->lastrowid); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
657 if (statement_type == STATEMENT_INSERT) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
658 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
659 lastrowid = sqlite3_last_insert_rowid(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
660 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
661 self->lastrowid = PyInt_FromLong((long)lastrowid); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
662 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
663 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
664 self->lastrowid = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
665 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
666 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
667 if (multiple) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
668 rc = statement_reset(self->statement); |
|
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 Py_XDECREF(parameters); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
671 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
672 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
673 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
674 Py_XDECREF(operation_bytestr); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
675 Py_XDECREF(parameters); |
|
37547
48311401a20e
Fix problem (not checking return result) reported by Coverity
Neal Norwitz <nnorwitz@gmail.com>
parents:
37518
diff
changeset
|
676 Py_XDECREF(parameters_iter); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
677 Py_XDECREF(parameters_list); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
678 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
679 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
680 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
681 } else { |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
682 Py_INCREF(self); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
683 return (PyObject*)self; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
684 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
685 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
686 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
687 PyObject* cursor_execute(Cursor* self, PyObject* args) |
|
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 return _query_execute(self, 0, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
690 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
691 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
692 PyObject* cursor_executemany(Cursor* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
693 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
694 return _query_execute(self, 1, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
695 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
696 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
697 PyObject* cursor_executescript(Cursor* self, PyObject* args) |
|
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 PyObject* script_obj; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
700 PyObject* script_str = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
701 const char* script_cstr; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
702 sqlite3_stmt* statement; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
703 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
704 PyObject* func_args; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
705 PyObject* result; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
706 int statement_completed = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
707 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
708 if (!PyArg_ParseTuple(args, "O", &script_obj)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
709 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
710 } |
|
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 (!check_thread(self->connection) || !check_connection(self->connection)) { |
|
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 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
715 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
716 if (PyString_Check(script_obj)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
717 script_cstr = PyString_AsString(script_obj); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
718 } else if (PyUnicode_Check(script_obj)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
719 script_str = PyUnicode_AsUTF8String(script_obj); |
|
37461
6ab15fc85c2d
Fix a couple of memory issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
37458
diff
changeset
|
720 if (!script_str) { |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
721 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
722 } |
|
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 script_cstr = PyString_AsString(script_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
725 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
726 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
|
727 return NULL; |
|
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 /* commit first */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
731 func_args = PyTuple_New(0); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
732 if (!func_args) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
733 goto error; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
734 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
735 result = connection_commit(self->connection, func_args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
736 Py_DECREF(func_args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
737 if (!result) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
738 goto error; |
|
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 Py_DECREF(result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
741 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
742 while (1) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
743 if (!sqlite3_complete(script_cstr)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
744 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
745 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
746 statement_completed = 1; |
|
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 rc = sqlite3_prepare(self->connection->db, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
749 script_cstr, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
750 -1, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
751 &statement, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
752 &script_cstr); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
753 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
754 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
755 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
756 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
757 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
758 /* execute statement, and ignore results of SELECT statements */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
759 rc = SQLITE_ROW; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
760 while (rc == SQLITE_ROW) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
761 rc = _sqlite_step_with_busyhandler(statement, self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
762 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
763 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
764 if (rc != SQLITE_DONE) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
765 (void)sqlite3_finalize(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
766 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
767 goto error; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
770 rc = sqlite3_finalize(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
771 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
772 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
773 goto error; |
|
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 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
776 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
777 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
778 Py_XDECREF(script_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
779 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
780 if (!statement_completed) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
781 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
|
782 } |
|
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 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
785 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
786 } else { |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
787 Py_INCREF(self); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
788 return (PyObject*)self; |
|
37362
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
792 PyObject* cursor_getiter(Cursor *self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
793 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
794 Py_INCREF(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
795 return (PyObject*)self; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
798 PyObject* cursor_iternext(Cursor *self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
799 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
800 PyObject* next_row_tuple; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
801 PyObject* next_row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
802 int rc; |
|
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 if (!check_thread(self->connection) || !check_connection(self->connection)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
805 return NULL; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
808 if (!self->next_row) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
809 if (self->statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
810 (void)statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
811 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
812 self->statement = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
813 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
814 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
815 } |
|
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 next_row_tuple = self->next_row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
818 self->next_row = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
819 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
820 if (self->row_factory != Py_None) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
821 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
|
822 Py_DECREF(next_row_tuple); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
823 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
824 next_row = next_row_tuple; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
825 } |
|
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 rc = _sqlite_step_with_busyhandler(self->statement->st, self->connection); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
828 if (rc != SQLITE_DONE && rc != SQLITE_ROW) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
829 Py_DECREF(next_row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
830 _seterror(self->connection->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
831 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
832 } |
|
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 if (rc == SQLITE_ROW) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
835 self->next_row = _fetch_one_row(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
836 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
837 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
838 return next_row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
839 } |
|
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 PyObject* cursor_fetchone(Cursor* self, PyObject* args) |
|
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 PyObject* row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
844 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
845 row = cursor_iternext(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
846 if (!row && !PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
847 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
848 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
849 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
850 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
851 return row; |
|
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 PyObject* cursor_fetchmany(Cursor* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
855 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
856 PyObject* row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
857 PyObject* list; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
858 int maxrows = self->arraysize; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
859 int counter = 0; |
|
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 (!PyArg_ParseTuple(args, "|i", &maxrows)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
862 return NULL; |
|
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 list = PyList_New(0); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
866 if (!list) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
867 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
868 } |
|
37362
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 /* just make sure we enter the loop */ |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
871 row = Py_None; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
872 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
873 while (row) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
874 row = cursor_iternext(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
875 if (row) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
876 PyList_Append(list, row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
877 Py_DECREF(row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
878 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
879 break; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
882 if (++counter == maxrows) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
883 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
884 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
885 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
886 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
887 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
888 Py_DECREF(list); |
|
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 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
891 return list; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
892 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
893 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
894 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
895 PyObject* cursor_fetchall(Cursor* self, PyObject* args) |
|
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 PyObject* row; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
898 PyObject* list; |
|
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 list = PyList_New(0); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
901 if (!list) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
902 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
903 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
904 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
905 /* just make sure we enter the loop */ |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
906 row = (PyObject*)Py_None; |
|
37362
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 while (row) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
909 row = cursor_iternext(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
910 if (row) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
911 PyList_Append(list, row); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
912 Py_DECREF(row); |
|
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 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
915 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
916 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
917 Py_DECREF(list); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
918 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
919 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
920 return list; |
|
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 } |
|
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* pysqlite_noop(Connection* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
925 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
926 /* don't care, return None */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
927 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
928 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
929 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
930 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
931 PyObject* cursor_close(Cursor* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
932 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
933 if (!check_thread(self->connection) || !check_connection(self->connection)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
934 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
935 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
936 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
937 if (self->statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
938 (void)statement_reset(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
939 Py_DECREF(self->statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
940 self->statement = 0; |
|
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 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
944 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
945 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
946 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
947 static PyMethodDef cursor_methods[] = { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
948 {"execute", (PyCFunction)cursor_execute, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
949 PyDoc_STR("Executes a SQL statement.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
950 {"executemany", (PyCFunction)cursor_executemany, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
951 PyDoc_STR("Repeatedly executes a SQL statement.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
952 {"executescript", (PyCFunction)cursor_executescript, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
953 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
|
954 {"fetchone", (PyCFunction)cursor_fetchone, METH_NOARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
955 PyDoc_STR("Fetches several rows from the resultset.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
956 {"fetchmany", (PyCFunction)cursor_fetchmany, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
957 PyDoc_STR("Fetches all rows from the resultset.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
958 {"fetchall", (PyCFunction)cursor_fetchall, METH_NOARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
959 PyDoc_STR("Fetches one row from the resultset.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
960 {"close", (PyCFunction)cursor_close, METH_NOARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
961 PyDoc_STR("Closes the cursor.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
962 {"setinputsizes", (PyCFunction)pysqlite_noop, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
963 PyDoc_STR("Required by DB-API. Does nothing in pysqlite.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
964 {"setoutputsize", (PyCFunction)pysqlite_noop, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
965 PyDoc_STR("Required by DB-API. Does nothing in pysqlite.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
966 {NULL, NULL} |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
967 }; |
|
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 static struct PyMemberDef cursor_members[] = |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
970 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
971 {"connection", T_OBJECT, offsetof(Cursor, connection), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
972 {"description", T_OBJECT, offsetof(Cursor, description), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
973 {"arraysize", T_INT, offsetof(Cursor, arraysize), 0}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
974 {"lastrowid", T_OBJECT, offsetof(Cursor, lastrowid), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
975 {"rowcount", T_OBJECT, offsetof(Cursor, rowcount), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
976 {"row_factory", T_OBJECT, offsetof(Cursor, row_factory), 0}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
977 {NULL} |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
978 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
979 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
980 PyTypeObject CursorType = { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
981 PyObject_HEAD_INIT(NULL) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
982 0, /* ob_size */ |
|
37495
d3969aeba777
upgrade to final version of pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37461
diff
changeset
|
983 MODULE_NAME ".Cursor", /* tp_name */ |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
984 sizeof(Cursor), /* tp_basicsize */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
985 0, /* tp_itemsize */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
986 (destructor)cursor_dealloc, /* tp_dealloc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
987 0, /* tp_print */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
988 0, /* tp_getattr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
989 0, /* tp_setattr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
990 0, /* tp_compare */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
991 0, /* tp_repr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
992 0, /* tp_as_number */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
993 0, /* tp_as_sequence */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
994 0, /* tp_as_mapping */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
995 0, /* tp_hash */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
996 0, /* tp_call */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
997 0, /* tp_str */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
998 0, /* tp_getattro */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
999 0, /* tp_setattro */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1000 0, /* tp_as_buffer */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1001 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_ITER|Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1002 0, /* tp_doc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1003 0, /* tp_traverse */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1004 0, /* tp_clear */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1005 0, /* tp_richcompare */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1006 0, /* tp_weaklistoffset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1007 (getiterfunc)cursor_getiter, /* tp_iter */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1008 (iternextfunc)cursor_iternext, /* tp_iternext */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1009 cursor_methods, /* tp_methods */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1010 cursor_members, /* tp_members */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1011 0, /* tp_getset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1012 0, /* tp_base */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1013 0, /* tp_dict */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1014 0, /* tp_descr_get */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1015 0, /* tp_descr_set */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1016 0, /* tp_dictoffset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1017 (initproc)cursor_init, /* tp_init */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1018 0, /* tp_alloc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1019 0, /* tp_new */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1020 0 /* tp_free */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1021 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1022 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1023 extern int cursor_setup_types(void) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1024 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1025 CursorType.tp_new = PyType_GenericNew; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1026 return PyType_Ready(&CursorType); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1027 } |
