Mercurial > cpython-lru_cache-weakref
annotate Modules/_sqlite/connection.c @ 39496:352ffe77b71d legacy-trunk
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Mon, 14 Aug 2006 21:42:55 +0000 |
| parents | 408d2a596f99 |
| children | 69ea12db9b28 b9d4ced23506 |
| rev | line source |
|---|---|
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1 /* connection.c - the connection 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. |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
6 * |
|
37362
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 "cache.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 "connection.h" |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
27 #include "statement.h" |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
28 #include "cursor.h" |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
29 #include "prepare_protocol.h" |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
30 #include "util.h" |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
31 #include "sqlitecompat.h" |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
32 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
33 #include "pythread.h" |
|
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 int connection_set_isolation_level(Connection* self, PyObject* isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
36 |
|
38833
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
37 |
|
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
38 void _sqlite3_result_error(sqlite3_context* ctx, const char* errmsg, int len) |
|
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
39 { |
|
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
40 /* in older SQLite versions, calling sqlite3_result_error in callbacks |
|
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
41 * triggers a bug in SQLite that leads either to irritating results or |
|
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
42 * segfaults, depending on the SQLite version */ |
|
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
43 #if SQLITE_VERSION_NUMBER >= 3003003 |
|
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
44 sqlite3_result_error(ctx, errmsg, len); |
|
38835
0a8b851b0375
Speculative checkin (requires approval of Gerhard Haering)
Neal Norwitz <nnorwitz@gmail.com>
parents:
38833
diff
changeset
|
45 #else |
|
0a8b851b0375
Speculative checkin (requires approval of Gerhard Haering)
Neal Norwitz <nnorwitz@gmail.com>
parents:
38833
diff
changeset
|
46 PyErr_SetString(OperationalError, errmsg); |
|
38833
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
47 #endif |
|
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
48 } |
|
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
49 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
50 int connection_init(Connection* self, PyObject* args, PyObject* kwargs) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
51 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
52 static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL, NULL}; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
53 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
54 char* database; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
55 int detect_types = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
56 PyObject* isolation_level = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
57 PyObject* factory = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
58 int check_same_thread = 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
59 int cached_statements = 100; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
60 double timeout = 5.0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
61 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
62 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
63 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|diOiOi", kwlist, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
64 &database, &timeout, &detect_types, &isolation_level, &check_same_thread, &factory, &cached_statements)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
65 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
66 return -1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
67 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
68 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
69 self->begin_statement = NULL; |
|
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 self->statement_cache = NULL; |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
72 self->statements = NULL; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
73 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
74 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
75 self->row_factory = Py_None; |
|
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 Py_INCREF(&PyUnicode_Type); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
78 self->text_factory = (PyObject*)&PyUnicode_Type; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
79 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
80 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
81 rc = sqlite3_open(database, &self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
82 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
83 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
84 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
85 _seterror(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
86 return -1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
87 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
88 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
89 if (!isolation_level) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
90 isolation_level = PyString_FromString(""); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
91 if (!isolation_level) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
92 return -1; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
93 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
94 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
95 Py_INCREF(isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
96 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
97 self->isolation_level = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
98 connection_set_isolation_level(self, isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
99 Py_DECREF(isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
100 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
101 self->statement_cache = (Cache*)PyObject_CallFunction((PyObject*)&CacheType, "Oi", self, cached_statements); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
102 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
103 return -1; |
|
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 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
106 self->statements = PyList_New(0); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
107 if (!self->statements) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
108 return -1; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
109 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
110 self->created_statements = 0; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
111 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
112 /* By default, the Cache class INCREFs the factory in its initializer, and |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
113 * decrefs it in its deallocator method. Since this would create a circular |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
114 * reference here, we're breaking it by decrementing self, and telling the |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
115 * cache class to not decref the factory (self) in its deallocator. |
|
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 self->statement_cache->decref_factory = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
118 Py_DECREF(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
119 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
120 self->inTransaction = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
121 self->detect_types = detect_types; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
122 self->timeout = timeout; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
123 (void)sqlite3_busy_timeout(self->db, (int)(timeout*1000)); |
|
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 self->thread_ident = PyThread_get_thread_ident(); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
126 self->check_same_thread = check_same_thread; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
127 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
128 self->function_pinboard = PyDict_New(); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
129 if (!self->function_pinboard) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
130 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
131 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
132 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
133 self->collations = PyDict_New(); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
134 if (!self->collations) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
135 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
136 } |
|
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 self->Warning = Warning; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
139 self->Error = Error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
140 self->InterfaceError = InterfaceError; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
141 self->DatabaseError = DatabaseError; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
142 self->DataError = DataError; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
143 self->OperationalError = OperationalError; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
144 self->IntegrityError = IntegrityError; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
145 self->InternalError = InternalError; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
146 self->ProgrammingError = ProgrammingError; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
147 self->NotSupportedError = NotSupportedError; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
148 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
149 return 0; |
|
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 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
152 /* Empty the entire statement cache of this connection */ |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
153 void flush_statement_cache(Connection* self) |
|
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 Node* node; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
156 Statement* statement; |
|
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 node = self->statement_cache->first; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
159 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
160 while (node) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
161 statement = (Statement*)(node->data); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
162 (void)statement_finalize(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
163 node = node->next; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
164 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
165 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
166 Py_DECREF(self->statement_cache); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
167 self->statement_cache = (Cache*)PyObject_CallFunction((PyObject*)&CacheType, "O", self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
168 Py_DECREF(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
169 self->statement_cache->decref_factory = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
170 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
171 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
172 void reset_all_statements(Connection* self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
173 { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
174 int i; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
175 PyObject* weakref; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
176 PyObject* statement; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
177 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
178 for (i = 0; i < PyList_Size(self->statements); i++) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
179 weakref = PyList_GetItem(self->statements, i); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
180 statement = PyWeakref_GetObject(weakref); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
181 if (statement != Py_None) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
182 (void)statement_reset((Statement*)statement); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
183 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
184 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
185 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
186 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
187 void connection_dealloc(Connection* self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
188 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
189 Py_XDECREF(self->statement_cache); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
190 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
191 /* Clean up if user has not called .close() explicitly. */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
192 if (self->db) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
193 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
194 sqlite3_close(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
195 Py_END_ALLOW_THREADS |
|
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 if (self->begin_statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
199 PyMem_Free(self->begin_statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
200 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
201 Py_XDECREF(self->isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
202 Py_XDECREF(self->function_pinboard); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
203 Py_XDECREF(self->row_factory); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
204 Py_XDECREF(self->text_factory); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
205 Py_XDECREF(self->collations); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
206 Py_XDECREF(self->statements); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
207 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
208 self->ob_type->tp_free((PyObject*)self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
209 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
210 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
211 PyObject* connection_cursor(Connection* self, PyObject* args, PyObject* kwargs) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
212 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
213 static char *kwlist[] = {"factory", NULL, NULL}; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
214 PyObject* factory = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
215 PyObject* cursor; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
216 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
217 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
218 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
219 &factory)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
220 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
221 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
222 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
223 if (!check_thread(self) || !check_connection(self)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
224 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
225 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
226 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
227 if (factory == NULL) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
228 factory = (PyObject*)&CursorType; |
|
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 cursor = PyObject_CallFunction(factory, "O", self); |
|
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 if (cursor && self->row_factory != Py_None) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
234 Py_XDECREF(((Cursor*)cursor)->row_factory); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
235 Py_INCREF(self->row_factory); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
236 ((Cursor*)cursor)->row_factory = self->row_factory; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
239 return cursor; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
242 PyObject* connection_close(Connection* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
243 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
244 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
245 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
246 if (!check_thread(self)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
247 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
248 } |
|
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 flush_statement_cache(self); |
|
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 (self->db) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
253 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
254 rc = sqlite3_close(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
255 Py_END_ALLOW_THREADS |
|
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 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
258 _seterror(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
259 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
260 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
261 self->db = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
262 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
263 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
264 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
265 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
266 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
267 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
268 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
269 /* |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
270 * Checks if a connection object is usable (i. e. not closed). |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
271 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
272 * 0 => error; 1 => ok |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
273 */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
274 int check_connection(Connection* con) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
275 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
276 if (!con->db) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
277 PyErr_SetString(ProgrammingError, "Cannot operate on a closed database."); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
278 return 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
279 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
280 return 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
281 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
282 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
283 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
284 PyObject* _connection_begin(Connection* self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
285 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
286 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
287 const char* tail; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
288 sqlite3_stmt* statement; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
289 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
290 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
291 rc = sqlite3_prepare(self->db, self->begin_statement, -1, &statement, &tail); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
292 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
293 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
294 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
295 _seterror(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
296 goto error; |
|
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 rc = _sqlite_step_with_busyhandler(statement, self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
300 if (rc == SQLITE_DONE) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
301 self->inTransaction = 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
302 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
303 _seterror(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
304 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
305 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
306 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
307 rc = sqlite3_finalize(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
308 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
309 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
310 if (rc != SQLITE_OK && !PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
311 _seterror(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
312 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
313 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
314 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
315 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
316 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
317 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
318 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
319 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
320 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
321 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
322 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
323 PyObject* connection_commit(Connection* self, PyObject* args) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
324 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
325 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
326 const char* tail; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
327 sqlite3_stmt* statement; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
328 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
329 if (!check_thread(self) || !check_connection(self)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
330 return NULL; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
333 if (self->inTransaction) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
334 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
335 rc = sqlite3_prepare(self->db, "COMMIT", -1, &statement, &tail); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
336 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
337 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
338 _seterror(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
339 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
340 } |
|
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 rc = _sqlite_step_with_busyhandler(statement, self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
343 if (rc == SQLITE_DONE) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
344 self->inTransaction = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
345 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
346 _seterror(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
347 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
348 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
349 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
350 rc = sqlite3_finalize(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
351 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
352 if (rc != SQLITE_OK && !PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
353 _seterror(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
354 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
355 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
356 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
357 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
358 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
359 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
360 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
361 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
362 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
363 return Py_None; |
|
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 PyObject* connection_rollback(Connection* self, PyObject* args) |
|
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 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
370 const char* tail; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
371 sqlite3_stmt* statement; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
372 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
373 if (!check_thread(self) || !check_connection(self)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
374 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
375 } |
|
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 if (self->inTransaction) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
378 reset_all_statements(self); |
|
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 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
381 rc = sqlite3_prepare(self->db, "ROLLBACK", -1, &statement, &tail); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
382 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
383 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
384 _seterror(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
385 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
386 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
387 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
388 rc = _sqlite_step_with_busyhandler(statement, self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
389 if (rc == SQLITE_DONE) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
390 self->inTransaction = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
391 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
392 _seterror(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
393 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
394 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
395 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
396 rc = sqlite3_finalize(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
397 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
398 if (rc != SQLITE_OK && !PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
399 _seterror(self->db); |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
402 } |
|
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 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
405 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
406 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
407 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
408 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
409 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
410 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
411 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
412 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
413 void _set_result(sqlite3_context* context, PyObject* py_val) |
|
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 long longval; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
416 const char* buffer; |
| 37387 | 417 Py_ssize_t buflen; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
418 PyObject* stringval; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
419 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
420 if ((!py_val) || PyErr_Occurred()) { |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
421 sqlite3_result_null(context); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
422 } else if (py_val == Py_None) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
423 sqlite3_result_null(context); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
424 } else if (PyInt_Check(py_val)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
425 longval = PyInt_AsLong(py_val); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
426 sqlite3_result_int64(context, (PY_LONG_LONG)longval); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
427 } else if (PyFloat_Check(py_val)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
428 sqlite3_result_double(context, PyFloat_AsDouble(py_val)); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
429 } else if (PyBuffer_Check(py_val)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
430 if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
431 PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
432 } else { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
433 sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
434 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
435 } else if (PyString_Check(py_val)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
436 sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
437 } else if (PyUnicode_Check(py_val)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
438 stringval = PyUnicode_AsUTF8String(py_val); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
439 if (stringval) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
440 sqlite3_result_text(context, PyString_AsString(stringval), -1, SQLITE_TRANSIENT); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
441 Py_DECREF(stringval); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
442 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
443 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
444 /* TODO: raise error */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
445 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
446 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
447 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
448 PyObject* _build_py_params(sqlite3_context *context, int argc, sqlite3_value** argv) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
449 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
450 PyObject* args; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
451 int i; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
452 sqlite3_value* cur_value; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
453 PyObject* cur_py_value; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
454 const char* val_str; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
455 PY_LONG_LONG val_int; |
| 37387 | 456 Py_ssize_t buflen; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
457 void* raw_buffer; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
458 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
459 args = PyTuple_New(argc); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
460 if (!args) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
461 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
462 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
463 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
464 for (i = 0; i < argc; i++) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
465 cur_value = argv[i]; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
466 switch (sqlite3_value_type(argv[i])) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
467 case SQLITE_INTEGER: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
468 val_int = sqlite3_value_int64(cur_value); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
469 cur_py_value = PyInt_FromLong((long)val_int); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
470 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
471 case SQLITE_FLOAT: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
472 cur_py_value = PyFloat_FromDouble(sqlite3_value_double(cur_value)); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
473 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
474 case SQLITE_TEXT: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
475 val_str = (const char*)sqlite3_value_text(cur_value); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
476 cur_py_value = PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
477 /* TODO: have a way to show errors here */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
478 if (!cur_py_value) { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
479 PyErr_Clear(); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
480 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
481 cur_py_value = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
482 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
483 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
484 case SQLITE_BLOB: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
485 buflen = sqlite3_value_bytes(cur_value); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
486 cur_py_value = PyBuffer_New(buflen); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
487 if (!cur_py_value) { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
488 break; |
|
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 if (PyObject_AsWriteBuffer(cur_py_value, &raw_buffer, &buflen)) { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
491 Py_DECREF(cur_py_value); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
492 cur_py_value = NULL; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
493 break; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
494 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
495 memcpy(raw_buffer, sqlite3_value_blob(cur_value), buflen); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
496 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
497 case SQLITE_NULL: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
498 default: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
499 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
500 cur_py_value = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
501 } |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
502 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
503 if (!cur_py_value) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
504 Py_DECREF(args); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
505 return NULL; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
506 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
507 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
508 PyTuple_SetItem(args, i, cur_py_value); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
509 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
510 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
511 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
512 return args; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
513 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
514 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
515 void _func_callback(sqlite3_context* context, int argc, sqlite3_value** argv) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
516 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
517 PyObject* args; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
518 PyObject* py_func; |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
519 PyObject* py_retval = NULL; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
520 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
521 PyGILState_STATE threadstate; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
522 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
523 threadstate = PyGILState_Ensure(); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
524 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
525 py_func = (PyObject*)sqlite3_user_data(context); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
526 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
527 args = _build_py_params(context, argc, argv); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
528 if (args) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
529 py_retval = PyObject_CallObject(py_func, args); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
530 Py_DECREF(args); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
531 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
532 |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
533 if (py_retval) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
534 _set_result(context, py_retval); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
535 Py_DECREF(py_retval); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
536 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
537 if (_enable_callback_tracebacks) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
538 PyErr_Print(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
539 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
540 PyErr_Clear(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
541 } |
|
38833
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
542 _sqlite3_result_error(context, "user-defined function raised exception", -1); |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
543 } |
|
37362
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 PyGILState_Release(threadstate); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
546 } |
|
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 static void _step_callback(sqlite3_context *context, int argc, sqlite3_value** params) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
549 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
550 PyObject* args; |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
551 PyObject* function_result = NULL; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
552 PyObject* aggregate_class; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
553 PyObject** aggregate_instance; |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
554 PyObject* stepmethod = NULL; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
555 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
556 PyGILState_STATE threadstate; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
557 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
558 threadstate = PyGILState_Ensure(); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
559 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
560 aggregate_class = (PyObject*)sqlite3_user_data(context); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
561 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
562 aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*)); |
|
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 if (*aggregate_instance == 0) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
565 *aggregate_instance = PyObject_CallFunction(aggregate_class, ""); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
566 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
567 if (PyErr_Occurred()) { |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
568 *aggregate_instance = 0; |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
569 if (_enable_callback_tracebacks) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
570 PyErr_Print(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
571 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
572 PyErr_Clear(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
573 } |
|
38833
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
574 _sqlite3_result_error(context, "user-defined aggregate's '__init__' method raised error", -1); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
575 goto error; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
576 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
577 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
578 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
579 stepmethod = PyObject_GetAttrString(*aggregate_instance, "step"); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
580 if (!stepmethod) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
581 goto error; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
582 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
583 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
584 args = _build_py_params(context, argc, params); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
585 if (!args) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
586 goto error; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
587 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
588 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
589 function_result = PyObject_CallObject(stepmethod, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
590 Py_DECREF(args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
591 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
592 if (!function_result) { |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
593 if (_enable_callback_tracebacks) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
594 PyErr_Print(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
595 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
596 PyErr_Clear(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
597 } |
|
38833
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
598 _sqlite3_result_error(context, "user-defined aggregate's 'step' method raised error", -1); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
599 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
600 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
601 error: |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
602 Py_XDECREF(stepmethod); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
603 Py_XDECREF(function_result); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
604 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
605 PyGILState_Release(threadstate); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
606 } |
|
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 void _final_callback(sqlite3_context* context) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
609 { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
610 PyObject* function_result = NULL; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
611 PyObject** aggregate_instance; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
612 PyObject* aggregate_class; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
613 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
614 PyGILState_STATE threadstate; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
615 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
616 threadstate = PyGILState_Ensure(); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
617 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
618 aggregate_class = (PyObject*)sqlite3_user_data(context); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
619 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
620 aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*)); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
621 if (!*aggregate_instance) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
622 /* this branch is executed if there was an exception in the aggregate's |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
623 * __init__ */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
624 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
625 goto error; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
626 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
627 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
628 function_result = PyObject_CallMethod(*aggregate_instance, "finalize", ""); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
629 if (!function_result) { |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
630 if (_enable_callback_tracebacks) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
631 PyErr_Print(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
632 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
633 PyErr_Clear(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
634 } |
|
38833
d7bc6470e838
- Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
635 _sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1); |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
636 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
637 _set_result(context, function_result); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
638 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
639 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
640 error: |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
641 Py_XDECREF(*aggregate_instance); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
642 Py_XDECREF(function_result); |
|
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 PyGILState_Release(threadstate); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
645 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
646 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
647 void _drop_unused_statement_references(Connection* self) |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
648 { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
649 PyObject* new_list; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
650 PyObject* weakref; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
651 int i; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
652 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
653 /* we only need to do this once in a while */ |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
654 if (self->created_statements++ < 200) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
655 return; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
656 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
657 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
658 self->created_statements = 0; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
659 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
660 new_list = PyList_New(0); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
661 if (!new_list) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
662 return; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
663 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
664 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
665 for (i = 0; i < PyList_Size(self->statements); i++) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
666 weakref = PyList_GetItem(self->statements, i); |
|
38883
408d2a596f99
Fixed a memory leak that was introduced with incorrect usage of the Python weak
Gerhard Häring <gh@ghaering.de>
parents:
38835
diff
changeset
|
667 if (PyWeakref_GetObject(weakref) != Py_None) { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
668 if (PyList_Append(new_list, weakref) != 0) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
669 Py_DECREF(new_list); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
670 return; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
671 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
672 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
673 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
674 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
675 Py_DECREF(self->statements); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
676 self->statements = new_list; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
677 } |
|
37362
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 PyObject* connection_create_function(Connection* self, PyObject* args, PyObject* kwargs) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
680 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
681 static char *kwlist[] = {"name", "narg", "func", NULL, NULL}; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
682 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
683 PyObject* func; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
684 char* name; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
685 int narg; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
686 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
687 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
688 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO", kwlist, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
689 &name, &narg, &func)) |
|
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 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
692 } |
|
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 rc = sqlite3_create_function(self->db, name, narg, SQLITE_UTF8, (void*)func, _func_callback, NULL, NULL); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
695 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
696 if (rc != SQLITE_OK) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
697 /* Workaround for SQLite bug: no error code or string is available here */ |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
698 PyErr_SetString(OperationalError, "Error creating function"); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
699 return NULL; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
700 } else { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
701 PyDict_SetItem(self->function_pinboard, func, Py_None); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
702 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
703 Py_INCREF(Py_None); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
704 return Py_None; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
705 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
706 } |
|
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 PyObject* connection_create_aggregate(Connection* self, PyObject* args, PyObject* kwargs) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
709 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
710 PyObject* aggregate_class; |
|
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 int n_arg; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
713 char* name; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
714 static char *kwlist[] = { "name", "n_arg", "aggregate_class", NULL }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
715 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
716 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
717 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO:create_aggregate", |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
718 kwlist, &name, &n_arg, &aggregate_class)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
719 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
720 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
721 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
722 rc = sqlite3_create_function(self->db, name, n_arg, SQLITE_UTF8, (void*)aggregate_class, 0, &_step_callback, &_final_callback); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
723 if (rc != SQLITE_OK) { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
724 /* Workaround for SQLite bug: no error code or string is available here */ |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
725 PyErr_SetString(OperationalError, "Error creating aggregate"); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
726 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
727 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
728 PyDict_SetItem(self->function_pinboard, aggregate_class, Py_None); |
|
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 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
731 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
732 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
733 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
734 |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
735 int _authorizer_callback(void* user_arg, int action, const char* arg1, const char* arg2 , const char* dbname, const char* access_attempt_source) |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
736 { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
737 PyObject *ret; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
738 int rc; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
739 PyGILState_STATE gilstate; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
740 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
741 gilstate = PyGILState_Ensure(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
742 ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
743 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
744 if (!ret) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
745 if (_enable_callback_tracebacks) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
746 PyErr_Print(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
747 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
748 PyErr_Clear(); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
749 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
750 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
751 rc = SQLITE_DENY; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
752 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
753 if (PyInt_Check(ret)) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
754 rc = (int)PyInt_AsLong(ret); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
755 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
756 rc = SQLITE_DENY; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
757 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
758 Py_DECREF(ret); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
759 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
760 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
761 PyGILState_Release(gilstate); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
762 return rc; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
763 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
764 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
765 PyObject* connection_set_authorizer(Connection* self, PyObject* args, PyObject* kwargs) |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
766 { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
767 PyObject* authorizer_cb; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
768 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
769 static char *kwlist[] = { "authorizer_callback", NULL }; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
770 int rc; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
771 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
772 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:set_authorizer", |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
773 kwlist, &authorizer_cb)) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
774 return NULL; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
775 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
776 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
777 rc = sqlite3_set_authorizer(self->db, _authorizer_callback, (void*)authorizer_cb); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
778 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
779 if (rc != SQLITE_OK) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
780 PyErr_SetString(OperationalError, "Error setting authorizer callback"); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
781 return NULL; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
782 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
783 PyDict_SetItem(self->function_pinboard, authorizer_cb, Py_None); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
784 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
785 Py_INCREF(Py_None); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
786 return Py_None; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
787 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
788 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
789 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
790 int check_thread(Connection* self) |
|
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 if (self->check_same_thread) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
793 if (PyThread_get_thread_ident() != self->thread_ident) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
794 PyErr_Format(ProgrammingError, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
795 "SQLite objects created in a thread can only be used in that same thread." |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
796 "The object was created in thread id %ld and this is thread id %ld", |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
797 self->thread_ident, PyThread_get_thread_ident()); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
798 return 0; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
801 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
802 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
803 return 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
804 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
805 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
806 static PyObject* connection_get_isolation_level(Connection* self, void* unused) |
|
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 Py_INCREF(self->isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
809 return self->isolation_level; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
810 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
811 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
812 static PyObject* connection_get_total_changes(Connection* self, void* unused) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
813 { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
814 if (!check_connection(self)) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
815 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
816 } else { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
817 return Py_BuildValue("i", sqlite3_total_changes(self->db)); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
818 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
819 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
820 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
821 static int connection_set_isolation_level(Connection* self, PyObject* isolation_level) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
822 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
823 PyObject* res; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
824 PyObject* begin_statement; |
|
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 Py_XDECREF(self->isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
827 |
| 37763 | 828 if (self->begin_statement) { |
| 829 PyMem_Free(self->begin_statement); | |
| 830 self->begin_statement = NULL; | |
| 831 } | |
| 832 | |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
833 if (isolation_level == Py_None) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
834 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
835 self->isolation_level = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
836 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
837 res = connection_commit(self, NULL); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
838 if (!res) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
839 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
840 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
841 Py_DECREF(res); |
|
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 self->inTransaction = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
844 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
845 Py_INCREF(isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
846 self->isolation_level = isolation_level; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
847 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
848 begin_statement = PyString_FromString("BEGIN "); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
849 if (!begin_statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
850 return -1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
851 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
852 PyString_Concat(&begin_statement, isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
853 if (!begin_statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
854 return -1; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
857 self->begin_statement = PyMem_Malloc(PyString_Size(begin_statement) + 2); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
858 if (!self->begin_statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
859 return -1; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
862 strcpy(self->begin_statement, PyString_AsString(begin_statement)); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
863 Py_DECREF(begin_statement); |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
866 return 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
867 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
868 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
869 PyObject* connection_call(Connection* self, PyObject* args, PyObject* kwargs) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
870 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
871 PyObject* sql; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
872 Statement* statement; |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
873 PyObject* weakref; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
874 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
875 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
876 if (!PyArg_ParseTuple(args, "O", &sql)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
877 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
878 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
879 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
880 _drop_unused_statement_references(self); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
881 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
882 statement = PyObject_New(Statement, &StatementType); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
883 if (!statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
884 return NULL; |
|
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 rc = statement_create(statement, self, sql); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
888 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
889 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
890 if (rc == PYSQLITE_TOO_MUCH_SQL) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
891 PyErr_SetString(Warning, "You can only execute one statement at a time."); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
892 } else if (rc == PYSQLITE_SQL_WRONG_TYPE) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
893 PyErr_SetString(Warning, "SQL is of wrong type. Must be string or unicode."); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
894 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
895 _seterror(self->db); |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
898 Py_DECREF(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
899 statement = 0; |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
900 } else { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
901 weakref = PyWeakref_NewRef((PyObject*)statement, NULL); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
902 if (!weakref) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
903 Py_DECREF(statement); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
904 statement = 0; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
905 goto error; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
906 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
907 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
908 if (PyList_Append(self->statements, weakref) != 0) { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
909 Py_DECREF(weakref); |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
910 statement = 0; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
911 goto error; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
912 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
913 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
914 Py_DECREF(weakref); |
|
37362
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 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
917 error: |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
918 return (PyObject*)statement; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
919 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
920 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
921 PyObject* connection_execute(Connection* self, PyObject* args, PyObject* kwargs) |
|
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 PyObject* cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
924 PyObject* result = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
925 PyObject* method = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
926 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
927 cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
928 if (!cursor) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
929 goto error; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
932 method = PyObject_GetAttrString(cursor, "execute"); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
933 if (!method) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
934 Py_DECREF(cursor); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
935 cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
936 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
937 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
938 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
939 result = PyObject_CallObject(method, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
940 if (!result) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
941 Py_DECREF(cursor); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
942 cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
943 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
944 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
945 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
946 Py_XDECREF(result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
947 Py_XDECREF(method); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
948 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
949 return cursor; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
950 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
951 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
952 PyObject* connection_executemany(Connection* self, PyObject* args, PyObject* kwargs) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
953 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
954 PyObject* cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
955 PyObject* result = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
956 PyObject* method = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
957 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
958 cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
959 if (!cursor) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
960 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
961 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
962 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
963 method = PyObject_GetAttrString(cursor, "executemany"); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
964 if (!method) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
965 Py_DECREF(cursor); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
966 cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
967 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
968 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
969 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
970 result = PyObject_CallObject(method, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
971 if (!result) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
972 Py_DECREF(cursor); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
973 cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
974 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
975 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
976 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
977 Py_XDECREF(result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
978 Py_XDECREF(method); |
|
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 return cursor; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
981 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
982 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
983 PyObject* connection_executescript(Connection* self, PyObject* args, PyObject* kwargs) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
984 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
985 PyObject* cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
986 PyObject* result = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
987 PyObject* method = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
988 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
989 cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
990 if (!cursor) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
991 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
992 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
993 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
994 method = PyObject_GetAttrString(cursor, "executescript"); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
995 if (!method) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
996 Py_DECREF(cursor); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
997 cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
998 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
999 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1000 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1001 result = PyObject_CallObject(method, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1002 if (!result) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1003 Py_DECREF(cursor); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1004 cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1005 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1006 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1007 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1008 Py_XDECREF(result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1009 Py_XDECREF(method); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1010 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1011 return cursor; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1012 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1013 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1014 /* ------------------------- COLLATION CODE ------------------------ */ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1015 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1016 static int |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1017 collation_callback( |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1018 void* context, |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1019 int text1_length, const void* text1_data, |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1020 int text2_length, const void* text2_data) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1021 { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1022 PyObject* callback = (PyObject*)context; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1023 PyObject* string1 = 0; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1024 PyObject* string2 = 0; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1025 PyGILState_STATE gilstate; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1026 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1027 PyObject* retval = NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1028 int result = 0; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1029 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1030 gilstate = PyGILState_Ensure(); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1031 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1032 if (PyErr_Occurred()) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1033 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1034 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1035 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1036 string1 = PyString_FromStringAndSize((const char*)text1_data, text1_length); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1037 string2 = PyString_FromStringAndSize((const char*)text2_data, text2_length); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1038 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1039 if (!string1 || !string2) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1040 goto finally; /* failed to allocate strings */ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1041 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1042 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1043 retval = PyObject_CallFunctionObjArgs(callback, string1, string2, NULL); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1044 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1045 if (!retval) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1046 /* execution failed */ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1047 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1048 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1049 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1050 result = PyInt_AsLong(retval); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1051 if (PyErr_Occurred()) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1052 result = 0; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1053 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1054 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1055 finally: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1056 Py_XDECREF(string1); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1057 Py_XDECREF(string2); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1058 Py_XDECREF(retval); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1059 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1060 PyGILState_Release(gilstate); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1061 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1062 return result; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1063 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1064 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1065 static PyObject * |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1066 connection_interrupt(Connection* self, PyObject* args) |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1067 { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1068 PyObject* retval = NULL; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1069 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1070 if (!check_connection(self)) { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1071 goto finally; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1072 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1073 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1074 sqlite3_interrupt(self->db); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1075 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1076 Py_INCREF(Py_None); |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1077 retval = Py_None; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1078 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1079 finally: |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1080 return retval; |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1081 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1082 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1083 static PyObject * |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1084 connection_create_collation(Connection* self, PyObject* args) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1085 { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1086 PyObject* callable; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1087 PyObject* uppercase_name = 0; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1088 PyObject* name; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1089 PyObject* retval; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1090 char* chk; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1091 int rc; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1092 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1093 if (!check_thread(self) || !check_connection(self)) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1094 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1095 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1096 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1097 if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyString_Type, &name, &callable)) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1098 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1099 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1100 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1101 uppercase_name = PyObject_CallMethod(name, "upper", ""); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1102 if (!uppercase_name) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1103 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1104 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1105 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1106 chk = PyString_AsString(uppercase_name); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1107 while (*chk) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1108 if ((*chk >= '0' && *chk <= '9') |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1109 || (*chk >= 'A' && *chk <= 'Z') |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1110 || (*chk == '_')) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1111 { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1112 chk++; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1113 } else { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1114 PyErr_SetString(ProgrammingError, "invalid character in collation name"); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1115 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1116 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1117 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1118 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1119 if (callable != Py_None && !PyCallable_Check(callable)) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1120 PyErr_SetString(PyExc_TypeError, "parameter must be callable"); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1121 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1122 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1123 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1124 if (callable != Py_None) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1125 PyDict_SetItem(self->collations, uppercase_name, callable); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1126 } else { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1127 PyDict_DelItem(self->collations, uppercase_name); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1128 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1129 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1130 rc = sqlite3_create_collation(self->db, |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1131 PyString_AsString(uppercase_name), |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1132 SQLITE_UTF8, |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1133 (callable != Py_None) ? callable : NULL, |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1134 (callable != Py_None) ? collation_callback : NULL); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1135 if (rc != SQLITE_OK) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1136 PyDict_DelItem(self->collations, uppercase_name); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1137 _seterror(self->db); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1138 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1139 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1140 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1141 finally: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1142 Py_XDECREF(uppercase_name); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1143 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1144 if (PyErr_Occurred()) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1145 retval = NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1146 } else { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1147 Py_INCREF(Py_None); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1148 retval = Py_None; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1149 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1150 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1151 return retval; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1152 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1153 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1154 static char connection_doc[] = |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
1155 PyDoc_STR("SQLite database connection object."); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1156 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1157 static PyGetSetDef connection_getset[] = { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1158 {"isolation_level", (getter)connection_get_isolation_level, (setter)connection_set_isolation_level}, |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1159 {"total_changes", (getter)connection_get_total_changes, (setter)0}, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1160 {NULL} |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1161 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1162 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1163 static PyMethodDef connection_methods[] = { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1164 {"cursor", (PyCFunction)connection_cursor, METH_VARARGS|METH_KEYWORDS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1165 PyDoc_STR("Return a cursor for the connection.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1166 {"close", (PyCFunction)connection_close, METH_NOARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1167 PyDoc_STR("Closes the connection.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1168 {"commit", (PyCFunction)connection_commit, METH_NOARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1169 PyDoc_STR("Commit the current transaction.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1170 {"rollback", (PyCFunction)connection_rollback, METH_NOARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1171 PyDoc_STR("Roll back the current transaction.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1172 {"create_function", (PyCFunction)connection_create_function, METH_VARARGS|METH_KEYWORDS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1173 PyDoc_STR("Creates a new function. Non-standard.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1174 {"create_aggregate", (PyCFunction)connection_create_aggregate, METH_VARARGS|METH_KEYWORDS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1175 PyDoc_STR("Creates a new aggregate. Non-standard.")}, |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1176 {"set_authorizer", (PyCFunction)connection_set_authorizer, METH_VARARGS|METH_KEYWORDS, |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1177 PyDoc_STR("Sets authorizer callback. Non-standard.")}, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1178 {"execute", (PyCFunction)connection_execute, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1179 PyDoc_STR("Executes a SQL statement. Non-standard.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1180 {"executemany", (PyCFunction)connection_executemany, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1181 PyDoc_STR("Repeatedly executes a SQL statement. Non-standard.")}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1182 {"executescript", (PyCFunction)connection_executescript, METH_VARARGS, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1183 PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")}, |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1184 {"create_collation", (PyCFunction)connection_create_collation, METH_VARARGS, |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
1185 PyDoc_STR("Creates a collation function. Non-standard.")}, |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1186 {"interrupt", (PyCFunction)connection_interrupt, METH_NOARGS, |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1187 PyDoc_STR("Abort any pending database operation. Non-standard.")}, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1188 {NULL, NULL} |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1189 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1190 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1191 static struct PyMemberDef connection_members[] = |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1192 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1193 {"Warning", T_OBJECT, offsetof(Connection, Warning), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1194 {"Error", T_OBJECT, offsetof(Connection, Error), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1195 {"InterfaceError", T_OBJECT, offsetof(Connection, InterfaceError), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1196 {"DatabaseError", T_OBJECT, offsetof(Connection, DatabaseError), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1197 {"DataError", T_OBJECT, offsetof(Connection, DataError), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1198 {"OperationalError", T_OBJECT, offsetof(Connection, OperationalError), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1199 {"IntegrityError", T_OBJECT, offsetof(Connection, IntegrityError), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1200 {"InternalError", T_OBJECT, offsetof(Connection, InternalError), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1201 {"ProgrammingError", T_OBJECT, offsetof(Connection, ProgrammingError), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1202 {"NotSupportedError", T_OBJECT, offsetof(Connection, NotSupportedError), RO}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1203 {"row_factory", T_OBJECT, offsetof(Connection, row_factory)}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1204 {"text_factory", T_OBJECT, offsetof(Connection, text_factory)}, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1205 {NULL} |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1206 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1207 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1208 PyTypeObject ConnectionType = { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1209 PyObject_HEAD_INIT(NULL) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1210 0, /* ob_size */ |
|
37495
d3969aeba777
upgrade to final version of pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37458
diff
changeset
|
1211 MODULE_NAME ".Connection", /* tp_name */ |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1212 sizeof(Connection), /* tp_basicsize */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1213 0, /* tp_itemsize */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1214 (destructor)connection_dealloc, /* tp_dealloc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1215 0, /* tp_print */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1216 0, /* tp_getattr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1217 0, /* tp_setattr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1218 0, /* tp_compare */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1219 0, /* tp_repr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1220 0, /* tp_as_number */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1221 0, /* tp_as_sequence */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1222 0, /* tp_as_mapping */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1223 0, /* tp_hash */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1224 (ternaryfunc)connection_call, /* tp_call */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1225 0, /* tp_str */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1226 0, /* tp_getattro */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1227 0, /* tp_setattro */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1228 0, /* tp_as_buffer */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1229 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1230 connection_doc, /* tp_doc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1231 0, /* tp_traverse */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1232 0, /* tp_clear */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1233 0, /* tp_richcompare */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1234 0, /* tp_weaklistoffset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1235 0, /* tp_iter */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1236 0, /* tp_iternext */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1237 connection_methods, /* tp_methods */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1238 connection_members, /* tp_members */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1239 connection_getset, /* tp_getset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1240 0, /* tp_base */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1241 0, /* tp_dict */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1242 0, /* tp_descr_get */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1243 0, /* tp_descr_set */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1244 0, /* tp_dictoffset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1245 (initproc)connection_init, /* tp_init */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1246 0, /* tp_alloc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1247 0, /* tp_new */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1248 0 /* tp_free */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1249 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1250 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1251 extern int connection_setup_types(void) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1252 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1253 ConnectionType.tp_new = PyType_GenericNew; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1254 return PyType_Ready(&ConnectionType); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1255 } |
