Mercurial > cpython-lru_cache-weakref
annotate Modules/_sqlite/connection.c @ 51334:8aa71c19dcb8 legacy-trunk
#5059: fix example.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Thu, 05 Feb 2009 10:59:28 +0000 |
| parents | 4c77d1016f60 |
| children | 3889d9528601 af9b6c43804e |
| 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 * |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
3 * Copyright (C) 2004-2007 Gerhard Häring <gh@ghaering.de> |
|
37362
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 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
35 #define ACTION_FINALIZE 1 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
36 #define ACTION_RESET 2 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
37 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
38 static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
39 |
|
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
|
40 |
|
49154
4c77d1016f60
Fixes issue #3103. In the sqlite3 module, made one more function static. All renaming public symbos now have the pysqlite prefix to avoid name clashes. This at least once created problems where the same symbol name appeared somewhere in Apache and the sqlite3 module was used from mod_python.
Gerhard Häring <gh@ghaering.de>
parents:
49153
diff
changeset
|
41 static void _sqlite3_result_error(sqlite3_context* ctx, const char* errmsg, int len) |
|
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
|
42 { |
|
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 /* 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
|
44 * 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
|
45 * 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
|
46 #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
|
47 sqlite3_result_error(ctx, errmsg, len); |
|
38835
0a8b851b0375
Speculative checkin (requires approval of Gerhard Haering)
Neal Norwitz <nnorwitz@gmail.com>
parents:
38833
diff
changeset
|
48 #else |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
49 PyErr_SetString(pysqlite_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
|
50 #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
|
51 } |
|
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
|
52 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
53 int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
54 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
55 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
|
56 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
57 PyObject* database; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
58 int detect_types = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
59 PyObject* isolation_level = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
60 PyObject* factory = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
61 int check_same_thread = 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
62 int cached_statements = 100; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
63 double timeout = 5.0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
64 int rc; |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
65 PyObject* class_attr = NULL; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
66 PyObject* class_attr_str = NULL; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
67 int is_apsw_connection = 0; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
68 PyObject* database_utf8; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
69 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
70 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|diOiOi", kwlist, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
71 &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
|
72 { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
73 return -1; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
74 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
75 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
76 self->begin_statement = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
77 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
78 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
|
79 self->statements = NULL; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
80 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
81 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
82 self->row_factory = Py_None; |
|
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 Py_INCREF(&PyUnicode_Type); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
85 self->text_factory = (PyObject*)&PyUnicode_Type; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
86 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
87 if (PyString_Check(database) || PyUnicode_Check(database)) { |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
88 if (PyString_Check(database)) { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
89 database_utf8 = database; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
90 Py_INCREF(database_utf8); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
91 } else { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
92 database_utf8 = PyUnicode_AsUTF8String(database); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
93 if (!database_utf8) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
94 return -1; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
95 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
96 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
97 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
98 Py_BEGIN_ALLOW_THREADS |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
99 rc = sqlite3_open(PyString_AsString(database_utf8), &self->db); |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
100 Py_END_ALLOW_THREADS |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
101 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
102 Py_DECREF(database_utf8); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
103 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
104 if (rc != SQLITE_OK) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
105 _pysqlite_seterror(self->db, NULL); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
106 return -1; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
107 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
108 } else { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
109 /* Create a pysqlite connection from a APSW connection */ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
110 class_attr = PyObject_GetAttrString(database, "__class__"); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
111 if (class_attr) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
112 class_attr_str = PyObject_Str(class_attr); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
113 if (class_attr_str) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
114 if (strcmp(PyString_AsString(class_attr_str), "<type 'apsw.Connection'>") == 0) { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
115 /* In the APSW Connection object, the first entry after |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
116 * PyObject_HEAD is the sqlite3* we want to get hold of. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
117 * Luckily, this is the same layout as we have in our |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
118 * pysqlite_Connection */ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
119 self->db = ((pysqlite_Connection*)database)->db; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
120 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
121 Py_INCREF(database); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
122 self->apsw_connection = database; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
123 is_apsw_connection = 1; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
124 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
125 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
126 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
127 Py_XDECREF(class_attr_str); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
128 Py_XDECREF(class_attr); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
129 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
130 if (!is_apsw_connection) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
131 PyErr_SetString(PyExc_ValueError, "database parameter must be string or APSW Connection object"); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
132 return -1; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
133 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
134 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
135 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
136 if (!isolation_level) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
141 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
142 Py_INCREF(isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
143 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
144 self->isolation_level = NULL; |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
145 pysqlite_connection_set_isolation_level(self, isolation_level); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
146 Py_DECREF(isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
147 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
148 self->statement_cache = (pysqlite_Cache*)PyObject_CallFunction((PyObject*)&pysqlite_CacheType, "Oi", self, cached_statements); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
149 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
150 return -1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
151 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
152 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
157 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
|
158 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
159 /* 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
|
160 * 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
|
161 * 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
|
162 * 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
|
163 */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
164 self->statement_cache->decref_factory = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
165 Py_DECREF(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
166 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
167 self->inTransaction = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
168 self->detect_types = detect_types; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
169 self->timeout = timeout; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
170 (void)sqlite3_busy_timeout(self->db, (int)(timeout*1000)); |
|
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 self->thread_ident = PyThread_get_thread_ident(); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
173 self->check_same_thread = check_same_thread; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
174 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
175 self->function_pinboard = PyDict_New(); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
176 if (!self->function_pinboard) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
177 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
178 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
179 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
180 self->collations = PyDict_New(); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
181 if (!self->collations) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
182 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
183 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
184 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
185 self->Warning = pysqlite_Warning; |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
186 self->Error = pysqlite_Error; |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
187 self->InterfaceError = pysqlite_InterfaceError; |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
188 self->DatabaseError = pysqlite_DatabaseError; |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
189 self->DataError = pysqlite_DataError; |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
190 self->OperationalError = pysqlite_OperationalError; |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
191 self->IntegrityError = pysqlite_IntegrityError; |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
192 self->InternalError = pysqlite_InternalError; |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
193 self->ProgrammingError = pysqlite_ProgrammingError; |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
194 self->NotSupportedError = pysqlite_NotSupportedError; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
195 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
196 return 0; |
|
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 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
199 /* Empty the entire statement cache of this connection */ |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
200 void pysqlite_flush_statement_cache(pysqlite_Connection* self) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
201 { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
202 pysqlite_Node* node; |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
203 pysqlite_Statement* statement; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
204 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
205 node = self->statement_cache->first; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
206 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
207 while (node) { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
208 statement = (pysqlite_Statement*)(node->data); |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
209 (void)pysqlite_statement_finalize(statement); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
210 node = node->next; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
211 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
212 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
213 Py_DECREF(self->statement_cache); |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
214 self->statement_cache = (pysqlite_Cache*)PyObject_CallFunction((PyObject*)&pysqlite_CacheType, "O", self); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
215 Py_DECREF(self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
216 self->statement_cache->decref_factory = 0; |
|
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 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
219 /* action in (ACTION_RESET, ACTION_FINALIZE) */ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
220 void pysqlite_do_all_statements(pysqlite_Connection* self, int action) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
221 { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
222 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
|
223 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
|
224 PyObject* statement; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
225 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 if (statement != Py_None) { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
230 if (action == ACTION_RESET) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
231 (void)pysqlite_statement_reset((pysqlite_Statement*)statement); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
232 } else { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
233 (void)pysqlite_statement_finalize((pysqlite_Statement*)statement); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
234 } |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
235 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
236 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
237 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
238 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
239 void pysqlite_connection_dealloc(pysqlite_Connection* self) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
240 { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
241 PyObject* ret = NULL; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
242 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
243 Py_XDECREF(self->statement_cache); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
244 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
245 /* Clean up if user has not called .close() explicitly. */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
246 if (self->db) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
247 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
248 sqlite3_close(self->db); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
249 Py_END_ALLOW_THREADS |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
250 } else if (self->apsw_connection) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
251 ret = PyObject_CallMethod(self->apsw_connection, "close", ""); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
252 Py_XDECREF(ret); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
253 Py_XDECREF(self->apsw_connection); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
254 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
255 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
256 if (self->begin_statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
257 PyMem_Free(self->begin_statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
258 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
259 Py_XDECREF(self->isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
260 Py_XDECREF(self->function_pinboard); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
261 Py_XDECREF(self->row_factory); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
262 Py_XDECREF(self->text_factory); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
263 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
|
264 Py_XDECREF(self->statements); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
265 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
266 self->ob_type->tp_free((PyObject*)self); |
|
37362
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 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
269 PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
270 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
271 static char *kwlist[] = {"factory", NULL, NULL}; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
272 PyObject* factory = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
273 PyObject* cursor; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
274 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
275 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
276 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
277 &factory)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
278 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
279 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
280 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
281 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) { |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
282 return NULL; |
|
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
285 if (factory == NULL) { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
286 factory = (PyObject*)&pysqlite_CursorType; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
287 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
288 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
289 cursor = PyObject_CallFunction(factory, "O", self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
290 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
291 if (cursor && self->row_factory != Py_None) { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
292 Py_XDECREF(((pysqlite_Cursor*)cursor)->row_factory); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
293 Py_INCREF(self->row_factory); |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
294 ((pysqlite_Cursor*)cursor)->row_factory = self->row_factory; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
295 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
296 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
297 return cursor; |
|
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 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
300 PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
301 { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
302 PyObject* ret; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
303 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
304 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
305 if (!pysqlite_check_thread(self)) { |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
306 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
307 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
308 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
309 pysqlite_do_all_statements(self, ACTION_FINALIZE); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
310 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
311 if (self->db) { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
312 if (self->apsw_connection) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
313 ret = PyObject_CallMethod(self->apsw_connection, "close", ""); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
314 Py_XDECREF(ret); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
315 Py_XDECREF(self->apsw_connection); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
316 self->apsw_connection = NULL; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
317 self->db = NULL; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
318 } else { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
319 Py_BEGIN_ALLOW_THREADS |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
320 rc = sqlite3_close(self->db); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
321 Py_END_ALLOW_THREADS |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
322 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
323 if (rc != SQLITE_OK) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
324 _pysqlite_seterror(self->db, NULL); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
325 return NULL; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
326 } else { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
327 self->db = NULL; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
328 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
329 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
330 } |
|
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 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
333 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
334 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
335 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
336 /* |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
337 * 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
|
338 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
339 * 0 => error; 1 => ok |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
340 */ |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
341 int pysqlite_check_connection(pysqlite_Connection* con) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
342 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
343 if (!con->db) { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
344 PyErr_SetString(pysqlite_ProgrammingError, "Cannot operate on a closed database."); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
345 return 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
346 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
347 return 1; |
|
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 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
350 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
351 PyObject* _pysqlite_connection_begin(pysqlite_Connection* self) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
352 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
353 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
354 const char* tail; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
355 sqlite3_stmt* statement; |
|
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 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
358 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
|
359 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
360 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
361 if (rc != SQLITE_OK) { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
362 _pysqlite_seterror(self->db, statement); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
363 goto error; |
|
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 |
|
49154
4c77d1016f60
Fixes issue #3103. In the sqlite3 module, made one more function static. All renaming public symbos now have the pysqlite prefix to avoid name clashes. This at least once created problems where the same symbol name appeared somewhere in Apache and the sqlite3 module was used from mod_python.
Gerhard Häring <gh@ghaering.de>
parents:
49153
diff
changeset
|
366 rc = pysqlite_step(statement, self); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
367 if (rc == SQLITE_DONE) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
368 self->inTransaction = 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
369 } else { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
370 _pysqlite_seterror(self->db, statement); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
371 } |
|
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 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
374 rc = sqlite3_finalize(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
375 Py_END_ALLOW_THREADS |
|
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 (rc != SQLITE_OK && !PyErr_Occurred()) { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
378 _pysqlite_seterror(self->db, NULL); |
|
37362
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
381 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
382 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
383 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
384 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
385 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
386 return Py_None; |
|
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 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
389 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
390 PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
391 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
392 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
393 const char* tail; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
394 sqlite3_stmt* statement; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
395 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
396 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) { |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
397 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
398 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
399 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
400 if (self->inTransaction) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
401 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
402 rc = sqlite3_prepare(self->db, "COMMIT", -1, &statement, &tail); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
403 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
404 if (rc != SQLITE_OK) { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
405 _pysqlite_seterror(self->db, NULL); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
406 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
407 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
408 |
|
49154
4c77d1016f60
Fixes issue #3103. In the sqlite3 module, made one more function static. All renaming public symbos now have the pysqlite prefix to avoid name clashes. This at least once created problems where the same symbol name appeared somewhere in Apache and the sqlite3 module was used from mod_python.
Gerhard Häring <gh@ghaering.de>
parents:
49153
diff
changeset
|
409 rc = pysqlite_step(statement, self); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
410 if (rc == SQLITE_DONE) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
411 self->inTransaction = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
412 } else { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
413 _pysqlite_seterror(self->db, statement); |
|
37362
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 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
416 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
417 rc = sqlite3_finalize(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
418 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
419 if (rc != SQLITE_OK && !PyErr_Occurred()) { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
420 _pysqlite_seterror(self->db, NULL); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
421 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
422 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
423 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
424 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
425 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
426 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
427 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
428 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
429 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
430 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
431 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
432 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
433 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
434 PyObject* pysqlite_connection_rollback(pysqlite_Connection* self, PyObject* args) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
435 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
436 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
437 const char* tail; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
438 sqlite3_stmt* statement; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
439 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
440 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) { |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
441 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
442 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
443 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
444 if (self->inTransaction) { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
445 pysqlite_do_all_statements(self, ACTION_RESET); |
|
37362
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 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
448 rc = sqlite3_prepare(self->db, "ROLLBACK", -1, &statement, &tail); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
449 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
450 if (rc != SQLITE_OK) { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
451 _pysqlite_seterror(self->db, NULL); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
452 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
453 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
454 |
|
49154
4c77d1016f60
Fixes issue #3103. In the sqlite3 module, made one more function static. All renaming public symbos now have the pysqlite prefix to avoid name clashes. This at least once created problems where the same symbol name appeared somewhere in Apache and the sqlite3 module was used from mod_python.
Gerhard Häring <gh@ghaering.de>
parents:
49153
diff
changeset
|
455 rc = pysqlite_step(statement, self); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
456 if (rc == SQLITE_DONE) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
457 self->inTransaction = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
458 } else { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
459 _pysqlite_seterror(self->db, statement); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
460 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
461 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
462 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
463 rc = sqlite3_finalize(statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
464 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
465 if (rc != SQLITE_OK && !PyErr_Occurred()) { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
466 _pysqlite_seterror(self->db, NULL); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
467 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
468 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
469 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
470 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
471 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
472 if (PyErr_Occurred()) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
473 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
474 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
475 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
476 return Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
477 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
478 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
479 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
480 void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
481 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
482 long longval; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
483 const char* buffer; |
| 37387 | 484 Py_ssize_t buflen; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
485 PyObject* stringval; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
486 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
487 if ((!py_val) || PyErr_Occurred()) { |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
488 sqlite3_result_null(context); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
489 } else if (py_val == Py_None) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
490 sqlite3_result_null(context); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
491 } else if (PyInt_Check(py_val)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
492 longval = PyInt_AsLong(py_val); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
493 sqlite3_result_int64(context, (PY_LONG_LONG)longval); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
494 } else if (PyFloat_Check(py_val)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
495 sqlite3_result_double(context, PyFloat_AsDouble(py_val)); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
496 } else if (PyBuffer_Check(py_val)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
497 if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
498 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
|
499 } else { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
500 sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
501 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
502 } else if (PyString_Check(py_val)) { |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
503 sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
504 } else if (PyUnicode_Check(py_val)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
505 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
|
506 if (stringval) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
507 sqlite3_result_text(context, PyString_AsString(stringval), -1, SQLITE_TRANSIENT); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
508 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
|
509 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
510 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
511 /* TODO: raise error */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
512 } |
|
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 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
515 PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_value** argv) |
|
37362
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 int i; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
519 sqlite3_value* cur_value; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
520 PyObject* cur_py_value; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
521 const char* val_str; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
522 PY_LONG_LONG val_int; |
| 37387 | 523 Py_ssize_t buflen; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
524 void* raw_buffer; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
525 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
526 args = PyTuple_New(argc); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
527 if (!args) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
528 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
529 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
530 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
531 for (i = 0; i < argc; i++) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
532 cur_value = argv[i]; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
533 switch (sqlite3_value_type(argv[i])) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
534 case SQLITE_INTEGER: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
535 val_int = sqlite3_value_int64(cur_value); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
536 cur_py_value = PyInt_FromLong((long)val_int); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
537 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
538 case SQLITE_FLOAT: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
539 cur_py_value = PyFloat_FromDouble(sqlite3_value_double(cur_value)); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
540 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
541 case SQLITE_TEXT: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
542 val_str = (const char*)sqlite3_value_text(cur_value); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
543 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
|
544 /* TODO: have a way to show errors here */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
545 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
|
546 PyErr_Clear(); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
547 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
548 cur_py_value = Py_None; |
|
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 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
551 case SQLITE_BLOB: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
552 buflen = sqlite3_value_bytes(cur_value); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
553 cur_py_value = PyBuffer_New(buflen); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
554 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
|
555 break; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
556 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
557 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
|
558 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
|
559 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
|
560 break; |
|
37362
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 memcpy(raw_buffer, sqlite3_value_blob(cur_value), buflen); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
563 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
564 case SQLITE_NULL: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
565 default: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
566 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
567 cur_py_value = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
568 } |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
569 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
570 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
|
571 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
|
572 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
|
573 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
574 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
575 PyTuple_SetItem(args, i, cur_py_value); |
|
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 return args; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
580 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
581 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
582 void _pysqlite_func_callback(sqlite3_context* context, int argc, sqlite3_value** argv) |
|
37362
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 PyObject* args; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
585 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
|
586 PyObject* py_retval = NULL; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
587 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
588 PyGILState_STATE threadstate; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
589 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
590 threadstate = PyGILState_Ensure(); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
591 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
592 py_func = (PyObject*)sqlite3_user_data(context); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
593 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
594 args = _pysqlite_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
|
595 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
|
596 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
|
597 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
|
598 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
599 |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
600 if (py_retval) { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
601 _pysqlite_set_result(context, py_retval); |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
602 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
|
603 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
604 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
|
605 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
|
606 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
607 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
|
608 } |
|
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
|
609 _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
|
610 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
611 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
612 PyGILState_Release(threadstate); |
|
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 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
615 static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_value** params) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
616 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
617 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
|
618 PyObject* function_result = NULL; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
619 PyObject* aggregate_class; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
620 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
|
621 PyObject* stepmethod = NULL; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
622 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
623 PyGILState_STATE threadstate; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
624 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
625 threadstate = PyGILState_Ensure(); |
|
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 aggregate_class = (PyObject*)sqlite3_user_data(context); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
628 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
629 aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*)); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
630 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
631 if (*aggregate_instance == 0) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
632 *aggregate_instance = PyObject_CallFunction(aggregate_class, ""); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
633 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
634 if (PyErr_Occurred()) { |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
635 *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
|
636 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
|
637 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
|
638 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
639 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
|
640 } |
|
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
|
641 _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
|
642 goto error; |
|
37362
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 } |
|
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 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
|
647 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
|
648 goto error; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
649 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
650 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
651 args = _pysqlite_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
|
652 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
|
653 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
|
654 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
655 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
656 function_result = PyObject_CallObject(stepmethod, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
657 Py_DECREF(args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
658 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
659 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
|
660 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
|
661 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
|
662 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
663 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
|
664 } |
|
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
|
665 _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
|
666 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
667 |
|
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 error: |
|
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_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
|
670 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
|
671 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
672 PyGILState_Release(threadstate); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
673 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
674 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
675 void _pysqlite_final_callback(sqlite3_context* context) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
676 { |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
677 PyObject* function_result = NULL; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
678 PyObject** aggregate_instance; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
679 PyObject* aggregate_class; |
|
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 PyGILState_STATE threadstate; |
|
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 threadstate = PyGILState_Ensure(); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
684 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
685 aggregate_class = (PyObject*)sqlite3_user_data(context); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
686 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
687 aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*)); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
688 if (!*aggregate_instance) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
689 /* 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
|
690 * __init__ */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
691 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
692 goto error; |
|
37362
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 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
695 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
|
696 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
|
697 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
|
698 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
|
699 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
700 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
|
701 } |
|
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
|
702 _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
|
703 } else { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
704 _pysqlite_set_result(context, function_result); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
705 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
706 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
707 error: |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
708 Py_XDECREF(*aggregate_instance); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
709 Py_XDECREF(function_result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
710 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
711 PyGILState_Release(threadstate); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
712 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
713 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
714 void _pysqlite_drop_unused_statement_references(pysqlite_Connection* self) |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
715 { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
716 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
|
717 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
|
718 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
|
719 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
720 /* 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
|
721 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
|
722 return; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
723 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
724 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
725 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
|
726 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
727 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
|
728 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
|
729 return; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
730 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
731 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
732 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
|
733 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
|
734 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
|
735 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
|
736 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
|
737 return; |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
738 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
739 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
740 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
741 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
742 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
|
743 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
|
744 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
745 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
746 PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
747 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
748 static char *kwlist[] = {"name", "narg", "func", NULL, NULL}; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
749 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
750 PyObject* func; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
751 char* name; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
752 int narg; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
753 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
754 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
755 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO", kwlist, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
756 &name, &narg, &func)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
757 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
758 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
759 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
760 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
761 rc = sqlite3_create_function(self->db, name, narg, SQLITE_UTF8, (void*)func, _pysqlite_func_callback, NULL, NULL); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
762 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
763 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
|
764 /* Workaround for SQLite bug: no error code or string is available here */ |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
765 PyErr_SetString(pysqlite_OperationalError, "Error creating function"); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
766 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
|
767 } else { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
768 PyDict_SetItem(self->function_pinboard, func, Py_None); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
769 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
770 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
|
771 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
|
772 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
773 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
774 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
775 PyObject* pysqlite_connection_create_aggregate(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
776 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
777 PyObject* aggregate_class; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
778 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
779 int n_arg; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
780 char* name; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
781 static char *kwlist[] = { "name", "n_arg", "aggregate_class", NULL }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
782 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
783 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
784 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO:create_aggregate", |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
785 kwlist, &name, &n_arg, &aggregate_class)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
786 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
787 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
788 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
789 rc = sqlite3_create_function(self->db, name, n_arg, SQLITE_UTF8, (void*)aggregate_class, 0, &_pysqlite_step_callback, &_pysqlite_final_callback); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
790 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
|
791 /* Workaround for SQLite bug: no error code or string is available here */ |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
792 PyErr_SetString(pysqlite_OperationalError, "Error creating aggregate"); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
793 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
794 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
795 PyDict_SetItem(self->function_pinboard, aggregate_class, Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
796 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
797 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
798 return Py_None; |
|
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 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
802 static int _authorizer_callback(void* user_arg, int action, const char* arg1, const char* arg2 , const char* dbname, const char* access_attempt_source) |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
803 { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
804 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
|
805 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
|
806 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
|
807 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
808 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
|
809 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
|
810 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
811 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
|
812 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
|
813 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
|
814 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
815 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
|
816 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
817 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
818 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
|
819 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
820 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
|
821 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
|
822 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
823 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
|
824 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
825 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
|
826 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
827 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
828 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
|
829 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
|
830 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
831 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
832 static int _progress_handler(void* user_arg) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
833 { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
834 int rc; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
835 PyObject *ret; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
836 PyGILState_STATE gilstate; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
837 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
838 gilstate = PyGILState_Ensure(); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
839 ret = PyObject_CallFunction((PyObject*)user_arg, ""); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
840 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
841 if (!ret) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
842 if (_enable_callback_tracebacks) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
843 PyErr_Print(); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
844 } else { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
845 PyErr_Clear(); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
846 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
847 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
848 /* abort query if error occured */ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
849 rc = 1; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
850 } else { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
851 rc = (int)PyObject_IsTrue(ret); |
|
45632
a18a424c2bd3
Only DECREF if ret != NULL
Neal Norwitz <nnorwitz@gmail.com>
parents:
45580
diff
changeset
|
852 Py_DECREF(ret); |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
853 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
854 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
855 PyGILState_Release(gilstate); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
856 return rc; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
857 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
858 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
859 PyObject* pysqlite_connection_set_authorizer(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
860 { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
861 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
|
862 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
863 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
|
864 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
|
865 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
866 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
|
867 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
|
868 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
|
869 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
870 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
871 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
|
872 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
873 if (rc != SQLITE_OK) { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
874 PyErr_SetString(pysqlite_OperationalError, "Error setting authorizer callback"); |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
875 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
|
876 } else { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
877 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
|
878 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
879 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
|
880 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
|
881 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
882 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
883 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
884 PyObject* pysqlite_connection_set_progress_handler(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
885 { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
886 PyObject* progress_handler; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
887 int n; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
888 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
889 static char *kwlist[] = { "progress_handler", "n", NULL }; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
890 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
891 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi:set_progress_handler", |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
892 kwlist, &progress_handler, &n)) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
893 return NULL; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
894 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
895 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
896 if (progress_handler == Py_None) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
897 /* None clears the progress handler previously set */ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
898 sqlite3_progress_handler(self->db, 0, 0, (void*)0); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
899 } else { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
900 sqlite3_progress_handler(self->db, n, _progress_handler, progress_handler); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
901 PyDict_SetItem(self->function_pinboard, progress_handler, Py_None); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
902 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
903 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
904 Py_INCREF(Py_None); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
905 return Py_None; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
906 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
907 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
908 int pysqlite_check_thread(pysqlite_Connection* self) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
909 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
910 if (self->check_same_thread) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
911 if (PyThread_get_thread_ident() != self->thread_ident) { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
912 PyErr_Format(pysqlite_ProgrammingError, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
913 "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
|
914 "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
|
915 self->thread_ident, PyThread_get_thread_ident()); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
916 return 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
917 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
918 |
|
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 return 1; |
|
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 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
924 static PyObject* pysqlite_connection_get_isolation_level(pysqlite_Connection* self, void* unused) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
925 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
926 Py_INCREF(self->isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
927 return self->isolation_level; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
928 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
929 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
930 static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self, void* unused) |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
931 { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
932 if (!pysqlite_check_connection(self)) { |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
933 return NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
934 } else { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
935 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
|
936 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
937 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
938 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
939 static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
940 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
941 PyObject* res; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
942 PyObject* begin_statement; |
|
47991
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
47951
diff
changeset
|
943 char* begin_statement_str; |
|
37362
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 Py_XDECREF(self->isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
946 |
| 37763 | 947 if (self->begin_statement) { |
| 948 PyMem_Free(self->begin_statement); | |
| 949 self->begin_statement = NULL; | |
| 950 } | |
| 951 | |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
952 if (isolation_level == Py_None) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
953 Py_INCREF(Py_None); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
954 self->isolation_level = Py_None; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
955 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
956 res = pysqlite_connection_commit(self, NULL); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
957 if (!res) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
958 return -1; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
959 } |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
960 Py_DECREF(res); |
|
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 self->inTransaction = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
963 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
964 Py_INCREF(isolation_level); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
965 self->isolation_level = isolation_level; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
966 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
967 begin_statement = PyString_FromString("BEGIN "); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
968 if (!begin_statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
969 return -1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
970 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
971 PyString_Concat(&begin_statement, isolation_level); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
972 if (!begin_statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
973 return -1; |
|
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 |
|
47991
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
47951
diff
changeset
|
976 begin_statement_str = PyString_AsString(begin_statement); |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
47951
diff
changeset
|
977 if (!begin_statement_str) { |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
47951
diff
changeset
|
978 Py_DECREF(begin_statement); |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
47951
diff
changeset
|
979 return -1; |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
47951
diff
changeset
|
980 } |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
47951
diff
changeset
|
981 self->begin_statement = PyMem_Malloc(strlen(begin_statement_str) + 2); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
982 if (!self->begin_statement) { |
|
47991
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
47951
diff
changeset
|
983 Py_DECREF(begin_statement); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
984 return -1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
985 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
986 |
|
47991
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
47951
diff
changeset
|
987 strcpy(self->begin_statement, begin_statement_str); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
988 Py_DECREF(begin_statement); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
989 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
990 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
991 return 0; |
|
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 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
994 PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
995 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
996 PyObject* sql; |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
997 pysqlite_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
|
998 PyObject* weakref; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
999 int rc; |
|
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 if (!PyArg_ParseTuple(args, "O", &sql)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1002 return NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1003 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1004 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1005 _pysqlite_drop_unused_statement_references(self); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
1006 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1007 statement = PyObject_New(pysqlite_Statement, &pysqlite_StatementType); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1008 if (!statement) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1009 return NULL; |
|
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 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1012 rc = pysqlite_statement_create(statement, self, sql); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1013 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1014 if (rc != SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1015 if (rc == PYSQLITE_TOO_MUCH_SQL) { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1016 PyErr_SetString(pysqlite_Warning, "You can only execute one statement at a time."); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1017 } else if (rc == PYSQLITE_SQL_WRONG_TYPE) { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1018 PyErr_SetString(pysqlite_Warning, "SQL is of wrong type. Must be string or unicode."); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1019 } else { |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1020 (void)pysqlite_statement_reset(statement); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1021 _pysqlite_seterror(self->db, NULL); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1022 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1023 |
|
47951
afe8d515bfe2
Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47527
diff
changeset
|
1024 Py_CLEAR(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
|
1025 } else { |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
1026 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
|
1027 if (!weakref) { |
|
47951
afe8d515bfe2
Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47527
diff
changeset
|
1028 Py_CLEAR(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
|
1029 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
|
1030 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
1031 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
1032 if (PyList_Append(self->statements, weakref) != 0) { |
|
47951
afe8d515bfe2
Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47527
diff
changeset
|
1033 Py_CLEAR(weakref); |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
1034 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
|
1035 } |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
1036 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
1037 Py_DECREF(weakref); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1038 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1039 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37763
diff
changeset
|
1040 error: |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1041 return (PyObject*)statement; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1042 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1043 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1044 PyObject* pysqlite_connection_execute(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1045 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1046 PyObject* cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1047 PyObject* result = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1048 PyObject* method = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1049 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1050 cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1051 if (!cursor) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1052 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1053 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1054 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1055 method = PyObject_GetAttrString(cursor, "execute"); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1056 if (!method) { |
|
47951
afe8d515bfe2
Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47527
diff
changeset
|
1057 Py_CLEAR(cursor); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1058 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1059 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1060 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1061 result = PyObject_CallObject(method, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1062 if (!result) { |
|
47951
afe8d515bfe2
Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47527
diff
changeset
|
1063 Py_CLEAR(cursor); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1064 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1065 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1066 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1067 Py_XDECREF(result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1068 Py_XDECREF(method); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1069 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1070 return cursor; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1071 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1072 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1073 PyObject* pysqlite_connection_executemany(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1074 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1075 PyObject* cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1076 PyObject* result = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1077 PyObject* method = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1078 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1079 cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1080 if (!cursor) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1081 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1082 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1083 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1084 method = PyObject_GetAttrString(cursor, "executemany"); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1085 if (!method) { |
|
47951
afe8d515bfe2
Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47527
diff
changeset
|
1086 Py_CLEAR(cursor); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1087 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1088 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1089 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1090 result = PyObject_CallObject(method, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1091 if (!result) { |
|
47951
afe8d515bfe2
Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47527
diff
changeset
|
1092 Py_CLEAR(cursor); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1093 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1094 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1095 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1096 Py_XDECREF(result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1097 Py_XDECREF(method); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1098 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1099 return cursor; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1100 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1101 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1102 PyObject* pysqlite_connection_executescript(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1103 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1104 PyObject* cursor = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1105 PyObject* result = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1106 PyObject* method = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1107 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1108 cursor = PyObject_CallMethod((PyObject*)self, "cursor", ""); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1109 if (!cursor) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1110 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1111 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1112 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1113 method = PyObject_GetAttrString(cursor, "executescript"); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1114 if (!method) { |
|
47951
afe8d515bfe2
Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47527
diff
changeset
|
1115 Py_CLEAR(cursor); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1116 goto error; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1117 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1118 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1119 result = PyObject_CallObject(method, args); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1120 if (!result) { |
|
47951
afe8d515bfe2
Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47527
diff
changeset
|
1121 Py_CLEAR(cursor); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1122 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1123 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1124 error: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1125 Py_XDECREF(result); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1126 Py_XDECREF(method); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1127 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1128 return cursor; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1129 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1130 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1131 /* ------------------------- COLLATION CODE ------------------------ */ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1132 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1133 static int |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1134 pysqlite_collation_callback( |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1135 void* context, |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1136 int text1_length, const void* text1_data, |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1137 int text2_length, const void* text2_data) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1138 { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1139 PyObject* callback = (PyObject*)context; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1140 PyObject* string1 = 0; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1141 PyObject* string2 = 0; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1142 PyGILState_STATE gilstate; |
|
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 PyObject* retval = NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1145 int result = 0; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1146 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1147 gilstate = PyGILState_Ensure(); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1148 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1149 if (PyErr_Occurred()) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1150 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1151 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1152 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1153 string1 = PyString_FromStringAndSize((const char*)text1_data, text1_length); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1154 string2 = PyString_FromStringAndSize((const char*)text2_data, text2_length); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1155 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1156 if (!string1 || !string2) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1157 goto finally; /* failed to allocate strings */ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1158 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1159 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1160 retval = PyObject_CallFunctionObjArgs(callback, string1, string2, NULL); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1161 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1162 if (!retval) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1163 /* execution failed */ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1164 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1165 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1166 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1167 result = PyInt_AsLong(retval); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1168 if (PyErr_Occurred()) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1169 result = 0; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1170 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1171 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1172 finally: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1173 Py_XDECREF(string1); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1174 Py_XDECREF(string2); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1175 Py_XDECREF(retval); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1176 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1177 PyGILState_Release(gilstate); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1178 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1179 return result; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1180 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1181 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1182 static PyObject * |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1183 pysqlite_connection_interrupt(pysqlite_Connection* self, PyObject* args) |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1184 { |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1185 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
|
1186 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1187 if (!pysqlite_check_connection(self)) { |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1188 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
|
1189 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1190 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1191 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
|
1192 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1193 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
|
1194 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
|
1195 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1196 finally: |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1197 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
|
1198 } |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1199 |
|
46159
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1200 /* Function author: Paul Kippes <kippesp@gmail.com> |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1201 * Class method of Connection to call the Python function _iterdump |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1202 * of the sqlite3 module. |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1203 */ |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1204 static PyObject * |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1205 pysqlite_connection_iterdump(pysqlite_Connection* self, PyObject* args) |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1206 { |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1207 PyObject* retval = NULL; |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1208 PyObject* module = NULL; |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1209 PyObject* module_dict; |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1210 PyObject* pyfn_iterdump; |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1211 |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1212 if (!pysqlite_check_connection(self)) { |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1213 goto finally; |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1214 } |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1215 |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1216 module = PyImport_ImportModule(MODULE_NAME ".dump"); |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1217 if (!module) { |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1218 goto finally; |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1219 } |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1220 |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1221 module_dict = PyModule_GetDict(module); |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1222 if (!module_dict) { |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1223 goto finally; |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1224 } |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1225 |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1226 pyfn_iterdump = PyDict_GetItemString(module_dict, "_iterdump"); |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1227 if (!pyfn_iterdump) { |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1228 PyErr_SetString(pysqlite_OperationalError, "Failed to obtain _iterdump() reference"); |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1229 goto finally; |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1230 } |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1231 |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1232 args = PyTuple_New(1); |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1233 if (!args) { |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1234 goto finally; |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1235 } |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1236 Py_INCREF(self); |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1237 PyTuple_SetItem(args, 0, (PyObject*)self); |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1238 retval = PyObject_CallObject(pyfn_iterdump, args); |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1239 |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1240 finally: |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1241 Py_XDECREF(args); |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1242 Py_XDECREF(module); |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1243 return retval; |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1244 } |
|
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1245 |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1246 static PyObject * |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1247 pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args) |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1248 { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1249 PyObject* callable; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1250 PyObject* uppercase_name = 0; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1251 PyObject* name; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1252 PyObject* retval; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1253 char* chk; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1254 int rc; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1255 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1256 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) { |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1257 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1258 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1259 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1260 if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyString_Type, &name, &callable)) { |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1261 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1262 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1263 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1264 uppercase_name = PyObject_CallMethod(name, "upper", ""); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1265 if (!uppercase_name) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1266 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1267 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1268 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1269 chk = PyString_AsString(uppercase_name); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1270 while (*chk) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1271 if ((*chk >= '0' && *chk <= '9') |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1272 || (*chk >= 'A' && *chk <= 'Z') |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1273 || (*chk == '_')) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1274 { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1275 chk++; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1276 } else { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1277 PyErr_SetString(pysqlite_ProgrammingError, "invalid character in collation name"); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1278 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1279 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1280 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1281 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1282 if (callable != Py_None && !PyCallable_Check(callable)) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1283 PyErr_SetString(PyExc_TypeError, "parameter must be callable"); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1284 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1285 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1286 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1287 if (callable != Py_None) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1288 PyDict_SetItem(self->collations, uppercase_name, callable); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1289 } else { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1290 PyDict_DelItem(self->collations, uppercase_name); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1291 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1292 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1293 rc = sqlite3_create_collation(self->db, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1294 PyString_AsString(uppercase_name), |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1295 SQLITE_UTF8, |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1296 (callable != Py_None) ? callable : NULL, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1297 (callable != Py_None) ? pysqlite_collation_callback : NULL); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1298 if (rc != SQLITE_OK) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1299 PyDict_DelItem(self->collations, uppercase_name); |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1300 _pysqlite_seterror(self->db, NULL); |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1301 goto finally; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1302 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1303 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1304 finally: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1305 Py_XDECREF(uppercase_name); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1306 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1307 if (PyErr_Occurred()) { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1308 retval = NULL; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1309 } else { |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1310 Py_INCREF(Py_None); |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1311 retval = Py_None; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1312 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1313 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1314 return retval; |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1315 } |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
1316 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1317 /* Called when the connection is used as a context manager. Returns itself as a |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1318 * convenience to the caller. */ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1319 static PyObject * |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1320 pysqlite_connection_enter(pysqlite_Connection* self, PyObject* args) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1321 { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1322 Py_INCREF(self); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1323 return (PyObject*)self; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1324 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1325 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1326 /** Called when the connection is used as a context manager. If there was any |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1327 * exception, a rollback takes place; otherwise we commit. */ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1328 static PyObject * |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1329 pysqlite_connection_exit(pysqlite_Connection* self, PyObject* args) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1330 { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1331 PyObject* exc_type, *exc_value, *exc_tb; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1332 char* method_name; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1333 PyObject* result; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1334 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1335 if (!PyArg_ParseTuple(args, "OOO", &exc_type, &exc_value, &exc_tb)) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1336 return NULL; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1337 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1338 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1339 if (exc_type == Py_None && exc_value == Py_None && exc_tb == Py_None) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1340 method_name = "commit"; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1341 } else { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1342 method_name = "rollback"; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1343 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1344 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1345 result = PyObject_CallMethod((PyObject*)self, method_name, ""); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1346 if (!result) { |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1347 return NULL; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1348 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1349 Py_DECREF(result); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1350 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1351 Py_INCREF(Py_False); |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1352 return Py_False; |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1353 } |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1354 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1355 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
|
1356 PyDoc_STR("SQLite database connection object."); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1357 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1358 static PyGetSetDef connection_getset[] = { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1359 {"isolation_level", (getter)pysqlite_connection_get_isolation_level, (setter)pysqlite_connection_set_isolation_level}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1360 {"total_changes", (getter)pysqlite_connection_get_total_changes, (setter)0}, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1361 {NULL} |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1362 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1363 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1364 static PyMethodDef connection_methods[] = { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1365 {"cursor", (PyCFunction)pysqlite_connection_cursor, METH_VARARGS|METH_KEYWORDS, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1366 PyDoc_STR("Return a cursor for the connection.")}, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1367 {"close", (PyCFunction)pysqlite_connection_close, METH_NOARGS, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1368 PyDoc_STR("Closes the connection.")}, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1369 {"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1370 PyDoc_STR("Commit the current transaction.")}, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1371 {"rollback", (PyCFunction)pysqlite_connection_rollback, METH_NOARGS, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1372 PyDoc_STR("Roll back the current transaction.")}, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1373 {"create_function", (PyCFunction)pysqlite_connection_create_function, METH_VARARGS|METH_KEYWORDS, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1374 PyDoc_STR("Creates a new function. Non-standard.")}, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1375 {"create_aggregate", (PyCFunction)pysqlite_connection_create_aggregate, METH_VARARGS|METH_KEYWORDS, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1376 PyDoc_STR("Creates a new aggregate. Non-standard.")}, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1377 {"set_authorizer", (PyCFunction)pysqlite_connection_set_authorizer, METH_VARARGS|METH_KEYWORDS, |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1378 PyDoc_STR("Sets authorizer callback. Non-standard.")}, |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1379 {"set_progress_handler", (PyCFunction)pysqlite_connection_set_progress_handler, METH_VARARGS|METH_KEYWORDS, |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1380 PyDoc_STR("Sets progress handler callback. Non-standard.")}, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1381 {"execute", (PyCFunction)pysqlite_connection_execute, METH_VARARGS, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1382 PyDoc_STR("Executes a SQL statement. Non-standard.")}, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1383 {"executemany", (PyCFunction)pysqlite_connection_executemany, METH_VARARGS, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1384 PyDoc_STR("Repeatedly executes a SQL statement. Non-standard.")}, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1385 {"executescript", (PyCFunction)pysqlite_connection_executescript, METH_VARARGS, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1386 PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")}, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1387 {"create_collation", (PyCFunction)pysqlite_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
|
1388 PyDoc_STR("Creates a collation function. Non-standard.")}, |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1389 {"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS, |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
1390 PyDoc_STR("Abort any pending database operation. Non-standard.")}, |
|
46159
f9a629f41656
Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents:
45632
diff
changeset
|
1391 {"iterdump", (PyCFunction)pysqlite_connection_iterdump, METH_NOARGS, |
|
49153
ff15e62a349b
sqlite3 module: Mark iterdump() method as "Non-standard" like all the other methods not found in DB-API.
Gerhard Häring <gh@ghaering.de>
parents:
47991
diff
changeset
|
1392 PyDoc_STR("Returns iterator to the dump of the database in an SQL text format. Non-standard.")}, |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1393 {"__enter__", (PyCFunction)pysqlite_connection_enter, METH_NOARGS, |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1394 PyDoc_STR("For context manager. Non-standard.")}, |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1395 {"__exit__", (PyCFunction)pysqlite_connection_exit, METH_VARARGS, |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44350
diff
changeset
|
1396 PyDoc_STR("For context manager. Non-standard.")}, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1397 {NULL, NULL} |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1398 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1399 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1400 static struct PyMemberDef connection_members[] = |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1401 { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1402 {"Warning", T_OBJECT, offsetof(pysqlite_Connection, Warning), RO}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1403 {"Error", T_OBJECT, offsetof(pysqlite_Connection, Error), RO}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1404 {"InterfaceError", T_OBJECT, offsetof(pysqlite_Connection, InterfaceError), RO}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1405 {"DatabaseError", T_OBJECT, offsetof(pysqlite_Connection, DatabaseError), RO}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1406 {"DataError", T_OBJECT, offsetof(pysqlite_Connection, DataError), RO}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1407 {"OperationalError", T_OBJECT, offsetof(pysqlite_Connection, OperationalError), RO}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1408 {"IntegrityError", T_OBJECT, offsetof(pysqlite_Connection, IntegrityError), RO}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1409 {"InternalError", T_OBJECT, offsetof(pysqlite_Connection, InternalError), RO}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1410 {"ProgrammingError", T_OBJECT, offsetof(pysqlite_Connection, ProgrammingError), RO}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1411 {"NotSupportedError", T_OBJECT, offsetof(pysqlite_Connection, NotSupportedError), RO}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1412 {"row_factory", T_OBJECT, offsetof(pysqlite_Connection, row_factory)}, |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1413 {"text_factory", T_OBJECT, offsetof(pysqlite_Connection, text_factory)}, |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1414 {NULL} |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1415 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1416 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1417 PyTypeObject pysqlite_ConnectionType = { |
|
42333
6620a510e9a9
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents:
40625
diff
changeset
|
1418 PyVarObject_HEAD_INIT(NULL, 0) |
|
37495
d3969aeba777
upgrade to final version of pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37458
diff
changeset
|
1419 MODULE_NAME ".Connection", /* tp_name */ |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1420 sizeof(pysqlite_Connection), /* tp_basicsize */ |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1421 0, /* tp_itemsize */ |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1422 (destructor)pysqlite_connection_dealloc, /* tp_dealloc */ |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1423 0, /* tp_print */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1424 0, /* tp_getattr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1425 0, /* tp_setattr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1426 0, /* tp_compare */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1427 0, /* tp_repr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1428 0, /* tp_as_number */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1429 0, /* tp_as_sequence */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1430 0, /* tp_as_mapping */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1431 0, /* tp_hash */ |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1432 (ternaryfunc)pysqlite_connection_call, /* tp_call */ |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1433 0, /* tp_str */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1434 0, /* tp_getattro */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1435 0, /* tp_setattro */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1436 0, /* tp_as_buffer */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1437 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1438 connection_doc, /* tp_doc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1439 0, /* tp_traverse */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1440 0, /* tp_clear */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1441 0, /* tp_richcompare */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1442 0, /* tp_weaklistoffset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1443 0, /* tp_iter */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1444 0, /* tp_iternext */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1445 connection_methods, /* tp_methods */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1446 connection_members, /* tp_members */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1447 connection_getset, /* tp_getset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1448 0, /* tp_base */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1449 0, /* tp_dict */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1450 0, /* tp_descr_get */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1451 0, /* tp_descr_set */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1452 0, /* tp_dictoffset */ |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1453 (initproc)pysqlite_connection_init, /* tp_init */ |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1454 0, /* tp_alloc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1455 0, /* tp_new */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1456 0 /* tp_free */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1457 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1458 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1459 extern int pysqlite_connection_setup_types(void) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1460 { |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1461 pysqlite_ConnectionType.tp_new = PyType_GenericNew; |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38883
diff
changeset
|
1462 return PyType_Ready(&pysqlite_ConnectionType); |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1463 } |
