annotate Modules/_sqlite/connection.c @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents e31597b3bd15
children 649937bb8f1c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 *
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
3 * Copyright (C) 2004-2010 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
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
38 #if SQLITE_VERSION_NUMBER >= 3003008
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
39 #ifndef SQLITE_OMIT_LOAD_EXTENSION
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
40 #define HAVE_LOAD_EXTENSION
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
41 #endif
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
42 #endif
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
43
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
44 static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level);
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
45 static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
46
38833
d7bc6470e838 - Added version checks in C code to make sure we don't trigger bugs in older
Gerhard Häring <gh@ghaering.de>
parents: 38808
diff changeset
47
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
48 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
49 {
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 /* 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
51 * 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
52 * 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
53 #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
54 sqlite3_result_error(ctx, errmsg, len);
38835
0a8b851b0375 Speculative checkin (requires approval of Gerhard Haering)
Neal Norwitz <nnorwitz@gmail.com>
parents: 38833
diff changeset
55 #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
56 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
57 #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
58 }
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
59
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
60 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
61 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
62 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
63
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
64 PyObject* database;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
65 int detect_types = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
66 PyObject* isolation_level = NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
67 PyObject* factory = NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
68 int check_same_thread = 1;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
69 int cached_statements = 100;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
70 double timeout = 5.0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
71 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
72 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
73 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
74 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
75 PyObject* database_utf8;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
76
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
77 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|diOiOi", kwlist,
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
78 &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
79 {
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
80 return -1;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
81 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
82
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
83 self->initialized = 1;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
84
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
85 self->begin_statement = NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
86
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
87 self->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
88 self->statements = NULL;
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
89 self->cursors = NULL;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
90
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
91 Py_INCREF(Py_None);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
92 self->row_factory = Py_None;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
93
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
94 Py_INCREF(&PyUnicode_Type);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
95 self->text_factory = (PyObject*)&PyUnicode_Type;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
96
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
97 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
98 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
99 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
100 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
101 } else {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
102 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
103 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
104 return -1;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
105 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
106 }
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 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
109 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
110 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
111
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
112 Py_DECREF(database_utf8);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
113
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
114 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
115 _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
116 return -1;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
117 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
118 } else {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
119 /* 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
120 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
121 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
122 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
123 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
124 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
125 /* 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
126 * 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
127 * 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
128 * pysqlite_Connection */
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
129 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
130
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
131 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
132 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
133 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
134 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
135 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
136 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
137 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
138 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
139
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
140 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
141 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
142 return -1;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
143 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
144 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
145
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
146 if (!isolation_level) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
147 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
148 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
149 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
150 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
151 } else {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
152 Py_INCREF(isolation_level);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
153 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
154 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
155 pysqlite_connection_set_isolation_level(self, isolation_level);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
156 Py_DECREF(isolation_level);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
157
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
158 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
159 if (PyErr_Occurred()) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
160 return -1;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
161 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
162
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
163 self->created_statements = 0;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
164 self->created_cursors = 0;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
165
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
166 /* Create lists of weak references to statements/cursors */
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
167 self->statements = PyList_New(0);
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
168 self->cursors = PyList_New(0);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
169 if (!self->statements || !self->cursors) {
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
170 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
171 }
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
172
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
173 /* 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
174 * 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
175 * 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
176 * 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
177 */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
178 self->statement_cache->decref_factory = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
179 Py_DECREF(self);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
180
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
181 self->inTransaction = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
182 self->detect_types = detect_types;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
183 self->timeout = timeout;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
184 (void)sqlite3_busy_timeout(self->db, (int)(timeout*1000));
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
185 #ifdef WITH_THREAD
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
186 self->thread_ident = PyThread_get_thread_ident();
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
187 #endif
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
188 self->check_same_thread = check_same_thread;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
189
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
190 self->function_pinboard = PyDict_New();
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
191 if (!self->function_pinboard) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
192 return -1;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
193 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
194
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
195 self->collations = PyDict_New();
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
196 if (!self->collations) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
197 return -1;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
198 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
199
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 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
201 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
202 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
203 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
204 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
205 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
206 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
207 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
208 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
209 self->NotSupportedError = pysqlite_NotSupportedError;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
210
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
211 return 0;
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
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
214 /* 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
215 void pysqlite_flush_statement_cache(pysqlite_Connection* self)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
216 {
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
217 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
218 pysqlite_Statement* statement;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
219
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
220 node = self->statement_cache->first;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
221
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
222 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
223 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
224 (void)pysqlite_statement_finalize(statement);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
225 node = node->next;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
226 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
227
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
228 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
229 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
230 Py_DECREF(self);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
231 self->statement_cache->decref_factory = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
232 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
233
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
234 /* action in (ACTION_RESET, ACTION_FINALIZE) */
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
235 void pysqlite_do_all_statements(pysqlite_Connection* self, int action, int reset_cursors)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
236 {
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
237 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
238 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
239 PyObject* statement;
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
240 pysqlite_Cursor* cursor;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
241
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
242 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
243 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
244 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
245 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
246 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
247 (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
248 } else {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
249 (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
250 }
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
251 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
252 }
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
253
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
254 if (reset_cursors) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
255 for (i = 0; i < PyList_Size(self->cursors); i++) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
256 weakref = PyList_GetItem(self->cursors, i);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
257 cursor = (pysqlite_Cursor*)PyWeakref_GetObject(weakref);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
258 if ((PyObject*)cursor != Py_None) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
259 cursor->reset = 1;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
260 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
261 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
262 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
263 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
264
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
265 void pysqlite_connection_dealloc(pysqlite_Connection* self)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
266 {
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
267 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
268
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
269 Py_XDECREF(self->statement_cache);
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 /* Clean up if user has not called .close() explicitly. */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
272 if (self->db) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
273 Py_BEGIN_ALLOW_THREADS
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
274 sqlite3_close(self->db);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
275 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
276 } 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
277 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
278 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
279 Py_XDECREF(self->apsw_connection);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
280 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
281
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
282 if (self->begin_statement) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
283 PyMem_Free(self->begin_statement);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
284 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
285 Py_XDECREF(self->isolation_level);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
286 Py_XDECREF(self->function_pinboard);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
287 Py_XDECREF(self->row_factory);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
288 Py_XDECREF(self->text_factory);
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
289 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
290 Py_XDECREF(self->statements);
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
291 Py_XDECREF(self->cursors);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
292
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
293 self->ob_type->tp_free((PyObject*)self);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
294 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
295
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
296 /*
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
297 * Registers a cursor with the connection.
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
298 *
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
299 * 0 => error; 1 => ok
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
300 */
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
301 int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
302 {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
303 PyObject* weakref;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
304
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
305 weakref = PyWeakref_NewRef((PyObject*)cursor, NULL);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
306 if (!weakref) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
307 goto error;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
308 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
309
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
310 if (PyList_Append(connection->cursors, weakref) != 0) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
311 Py_CLEAR(weakref);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
312 goto error;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
313 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
314
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
315 Py_DECREF(weakref);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
316
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
317 return 1;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
318 error:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
319 return 0;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
320 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
321
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
322 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
323 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
324 static char *kwlist[] = {"factory", NULL, NULL};
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
325 PyObject* factory = NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
326 PyObject* cursor;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
327
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
328 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist,
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
329 &factory)) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
330 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
331 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
332
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
333 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
334 return NULL;
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 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
338 factory = (PyObject*)&pysqlite_CursorType;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
339 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
340
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
341 cursor = PyObject_CallFunction(factory, "O", self);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
342
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
343 _pysqlite_drop_unused_cursor_references(self);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
344
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
345 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
346 Py_XDECREF(((pysqlite_Cursor*)cursor)->row_factory);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
347 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
348 ((pysqlite_Cursor*)cursor)->row_factory = self->row_factory;
37362
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
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
351 return cursor;
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
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
354 PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
355 {
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
356 PyObject* ret;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
357 int rc;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
358
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
359 if (!pysqlite_check_thread(self)) {
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
360 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
361 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
362
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
363 pysqlite_do_all_statements(self, ACTION_FINALIZE, 1);
37362
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 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
366 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
367 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
368 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
369 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
370 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
371 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
372 } else {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
373 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
374 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
375 Py_END_ALLOW_THREADS
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
376
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
377 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
378 _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
379 return NULL;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
380 } else {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
381 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
382 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
383 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
384 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
385
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
386 Py_INCREF(Py_None);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
387 return Py_None;
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
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
390 /*
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
391 * 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
392 *
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
393 * 0 => error; 1 => ok
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
394 */
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
395 int pysqlite_check_connection(pysqlite_Connection* con)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
396 {
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
397 if (!con->initialized) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
398 PyErr_SetString(pysqlite_ProgrammingError, "Base Connection.__init__ not called.");
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
399 return 0;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
400 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
401
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
402 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
403 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
404 return 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
405 } else {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
406 return 1;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
407 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
408 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
409
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
410 PyObject* _pysqlite_connection_begin(pysqlite_Connection* self)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
411 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
412 int rc;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
413 const char* tail;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
414 sqlite3_stmt* statement;
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_prepare(self->db, self->begin_statement, -1, &statement, &tail);
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
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
420 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
421 _pysqlite_seterror(self->db, statement);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
422 goto error;
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
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
425 rc = pysqlite_step(statement, self);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
426 if (rc == SQLITE_DONE) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
427 self->inTransaction = 1;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
428 } else {
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
429 _pysqlite_seterror(self->db, statement);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
430 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
431
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
432 Py_BEGIN_ALLOW_THREADS
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
433 rc = sqlite3_finalize(statement);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
434 Py_END_ALLOW_THREADS
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 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
437 _pysqlite_seterror(self->db, NULL);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
438 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
439
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
440 error:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
441 if (PyErr_Occurred()) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
442 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
443 } else {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
444 Py_INCREF(Py_None);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
445 return Py_None;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
446 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
447 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
448
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
449 PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
450 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
451 int rc;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
452 const char* tail;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
453 sqlite3_stmt* statement;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
454
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
455 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
456 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
457 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
458
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
459 if (self->inTransaction) {
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
460 pysqlite_do_all_statements(self, ACTION_RESET, 0);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
461
37362
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_prepare(self->db, "COMMIT", -1, &statement, &tail);
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) {
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 goto error;
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
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
470 rc = pysqlite_step(statement, self);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
471 if (rc == SQLITE_DONE) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
472 self->inTransaction = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
473 } else {
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
474 _pysqlite_seterror(self->db, statement);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
475 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
476
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
477 Py_BEGIN_ALLOW_THREADS
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
478 rc = sqlite3_finalize(statement);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
479 Py_END_ALLOW_THREADS
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
480 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
481 _pysqlite_seterror(self->db, NULL);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
482 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
483
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
484 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
485
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
486 error:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
487 if (PyErr_Occurred()) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
488 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
489 } else {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
490 Py_INCREF(Py_None);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
491 return Py_None;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
492 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
493 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
494
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
495 PyObject* pysqlite_connection_rollback(pysqlite_Connection* self, PyObject* args)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
496 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
497 int rc;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
498 const char* tail;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
499 sqlite3_stmt* statement;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
500
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
501 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
502 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
503 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
504
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
505 if (self->inTransaction) {
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
506 pysqlite_do_all_statements(self, ACTION_RESET, 1);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
507
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
508 Py_BEGIN_ALLOW_THREADS
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
509 rc = sqlite3_prepare(self->db, "ROLLBACK", -1, &statement, &tail);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
510 Py_END_ALLOW_THREADS
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
511 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
512 _pysqlite_seterror(self->db, NULL);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
513 goto error;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
514 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
515
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
516 rc = pysqlite_step(statement, self);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
517 if (rc == SQLITE_DONE) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
518 self->inTransaction = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
519 } else {
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
520 _pysqlite_seterror(self->db, statement);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
521 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
522
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
523 Py_BEGIN_ALLOW_THREADS
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
524 rc = sqlite3_finalize(statement);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
525 Py_END_ALLOW_THREADS
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
526 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
527 _pysqlite_seterror(self->db, NULL);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
528 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
529
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
530 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
531
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
532 error:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
533 if (PyErr_Occurred()) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
534 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
535 } else {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
536 Py_INCREF(Py_None);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
537 return Py_None;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
538 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
539 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
540
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
541 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
542 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
543 const char* buffer;
37387
4ab8ec9e59df Make ssize_t clean
Neal Norwitz <nnorwitz@gmail.com>
parents: 37362
diff changeset
544 Py_ssize_t buflen;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
545 PyObject* stringval;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
546
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
547 if ((!py_val) || PyErr_Occurred()) {
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
548 sqlite3_result_null(context);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
549 } else if (py_val == Py_None) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
550 sqlite3_result_null(context);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
551 } else if (PyInt_Check(py_val)) {
77069
e31597b3bd15 Issue #14572: Prevent build failures with pre-3.5.0 versions of
Ned Deily <nad@acm.org>
parents: 75121
diff changeset
552 sqlite3_result_int64(context, (sqlite_int64)PyInt_AsLong(py_val));
75121
789a3ea97083 sqlite3: Fix 64-bit integer handling in user functions on 32-bit architectures
Petri Lehtinen <petri@digip.org>
parents: 68256
diff changeset
553 } else if (PyLong_Check(py_val)) {
789a3ea97083 sqlite3: Fix 64-bit integer handling in user functions on 32-bit architectures
Petri Lehtinen <petri@digip.org>
parents: 68256
diff changeset
554 sqlite3_result_int64(context, PyLong_AsLongLong(py_val));
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
555 } else if (PyFloat_Check(py_val)) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
556 sqlite3_result_double(context, PyFloat_AsDouble(py_val));
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
557 } else if (PyBuffer_Check(py_val)) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
558 if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
559 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
560 } else {
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
561 sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
562 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
563 } else if (PyString_Check(py_val)) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
564 sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
565 } else if (PyUnicode_Check(py_val)) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
566 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
567 if (stringval) {
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
568 sqlite3_result_text(context, PyString_AsString(stringval), -1, SQLITE_TRANSIENT);
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
569 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
570 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
571 } else {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
572 /* TODO: raise error */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
573 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
574 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
575
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
576 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
577 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
578 PyObject* args;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
579 int i;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
580 sqlite3_value* cur_value;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
581 PyObject* cur_py_value;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
582 const char* val_str;
77069
e31597b3bd15 Issue #14572: Prevent build failures with pre-3.5.0 versions of
Ned Deily <nad@acm.org>
parents: 75121
diff changeset
583 sqlite_int64 val_int;
37387
4ab8ec9e59df Make ssize_t clean
Neal Norwitz <nnorwitz@gmail.com>
parents: 37362
diff changeset
584 Py_ssize_t buflen;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
585 void* raw_buffer;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
586
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
587 args = PyTuple_New(argc);
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
588 if (!args) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
589 return NULL;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
590 }
37362
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 for (i = 0; i < argc; i++) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
593 cur_value = argv[i];
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
594 switch (sqlite3_value_type(argv[i])) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
595 case SQLITE_INTEGER:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
596 val_int = sqlite3_value_int64(cur_value);
75121
789a3ea97083 sqlite3: Fix 64-bit integer handling in user functions on 32-bit architectures
Petri Lehtinen <petri@digip.org>
parents: 68256
diff changeset
597 if(val_int < LONG_MIN || val_int > LONG_MAX)
789a3ea97083 sqlite3: Fix 64-bit integer handling in user functions on 32-bit architectures
Petri Lehtinen <petri@digip.org>
parents: 68256
diff changeset
598 cur_py_value = PyLong_FromLongLong(val_int);
789a3ea97083 sqlite3: Fix 64-bit integer handling in user functions on 32-bit architectures
Petri Lehtinen <petri@digip.org>
parents: 68256
diff changeset
599 else
789a3ea97083 sqlite3: Fix 64-bit integer handling in user functions on 32-bit architectures
Petri Lehtinen <petri@digip.org>
parents: 68256
diff changeset
600 cur_py_value = PyInt_FromLong((long)val_int);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
601 break;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
602 case SQLITE_FLOAT:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
603 cur_py_value = PyFloat_FromDouble(sqlite3_value_double(cur_value));
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
604 break;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
605 case SQLITE_TEXT:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
606 val_str = (const char*)sqlite3_value_text(cur_value);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
607 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
608 /* TODO: have a way to show errors here */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
609 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
610 PyErr_Clear();
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
611 Py_INCREF(Py_None);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
612 cur_py_value = Py_None;
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 break;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
615 case SQLITE_BLOB:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
616 buflen = sqlite3_value_bytes(cur_value);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
617 cur_py_value = PyBuffer_New(buflen);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
618 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
619 break;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
620 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
621 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
622 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
623 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
624 break;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
625 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
626 memcpy(raw_buffer, sqlite3_value_blob(cur_value), buflen);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
627 break;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
628 case SQLITE_NULL:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
629 default:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
630 Py_INCREF(Py_None);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
631 cur_py_value = Py_None;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
632 }
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
633
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 (!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
635 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
636 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
637 }
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
638
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
639 PyTuple_SetItem(args, i, cur_py_value);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
640
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
641 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
642
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
643 return args;
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
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
646 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
647 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
648 PyObject* args;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
649 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
650 PyObject* py_retval = NULL;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
651
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
652 #ifdef WITH_THREAD
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
653 PyGILState_STATE threadstate;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
654
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
655 threadstate = PyGILState_Ensure();
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
656 #endif
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
657
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
658 py_func = (PyObject*)sqlite3_user_data(context);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
659
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
660 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
661 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
662 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
663 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
664 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
665
38808
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
666 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
667 _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
668 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
669 } else {
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
670 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
671 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
672 } else {
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
673 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
674 }
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
675 _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
676 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
677
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
678 #ifdef WITH_THREAD
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
679 PyGILState_Release(threadstate);
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
680 #endif
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
681 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
682
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
683 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
684 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
685 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
686 PyObject* function_result = NULL;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
687 PyObject* aggregate_class;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
688 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
689 PyObject* stepmethod = NULL;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
690
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
691 #ifdef WITH_THREAD
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
692 PyGILState_STATE threadstate;
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 threadstate = PyGILState_Ensure();
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
695 #endif
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
696
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
697 aggregate_class = (PyObject*)sqlite3_user_data(context);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
698
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
699 aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*));
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
700
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
701 if (*aggregate_instance == 0) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
702 *aggregate_instance = PyObject_CallFunction(aggregate_class, "");
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
703
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
704 if (PyErr_Occurred()) {
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
705 *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
706 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
707 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
708 } else {
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
709 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
710 }
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
711 _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
712 goto error;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
713 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
714 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
715
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
716 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
717 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
718 goto error;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
719 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
720
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
721 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
722 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
723 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
724 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
725
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
726 function_result = PyObject_CallObject(stepmethod, args);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
727 Py_DECREF(args);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
728
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
729 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
730 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
731 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
732 } else {
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
733 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
734 }
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
735 _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
736 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
737
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
738 error:
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
739 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
740 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
741
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
742 #ifdef WITH_THREAD
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
743 PyGILState_Release(threadstate);
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
744 #endif
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
745 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
746
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
747 void _pysqlite_final_callback(sqlite3_context* context)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
748 {
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
749 PyObject* function_result = NULL;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
750 PyObject** aggregate_instance;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
751
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
752 #ifdef WITH_THREAD
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
753 PyGILState_STATE threadstate;
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 threadstate = PyGILState_Ensure();
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
756 #endif
37362
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 aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*));
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
759 if (!*aggregate_instance) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
760 /* 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
761 * __init__ */
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 goto error;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
764 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
765
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 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
767 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
768 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
769 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
770 } else {
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
771 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
772 }
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
773 _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
774 } 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
775 _pysqlite_set_result(context, function_result);
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
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
778 error:
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
779 Py_XDECREF(*aggregate_instance);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
780 Py_XDECREF(function_result);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
781
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
782 #ifdef WITH_THREAD
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
783 PyGILState_Release(threadstate);
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
784 #endif
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
785 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
786
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
787 static 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
788 {
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
789 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
790 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
791 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
792
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
793 /* 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
794 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
795 return;
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
796 }
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
797
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
798 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
799
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
800 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
801 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
802 return;
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
803 }
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
804
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
805 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
806 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
807 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
808 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
809 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
810 return;
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
811 }
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
812 }
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
813 }
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
814
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
815 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
816 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
817 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
818
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
819 static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
820 {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
821 PyObject* new_list;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
822 PyObject* weakref;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
823 int i;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
824
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
825 /* we only need to do this once in a while */
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
826 if (self->created_cursors++ < 200) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
827 return;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
828 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
829
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
830 self->created_cursors = 0;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
831
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
832 new_list = PyList_New(0);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
833 if (!new_list) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
834 return;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
835 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
836
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
837 for (i = 0; i < PyList_Size(self->cursors); i++) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
838 weakref = PyList_GetItem(self->cursors, i);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
839 if (PyWeakref_GetObject(weakref) != Py_None) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
840 if (PyList_Append(new_list, weakref) != 0) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
841 Py_DECREF(new_list);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
842 return;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
843 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
844 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
845 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
846
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
847 Py_DECREF(self->cursors);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
848 self->cursors = new_list;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
849 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
850
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
851 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
852 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
853 static char *kwlist[] = {"name", "narg", "func", NULL, NULL};
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
854
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
855 PyObject* func;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
856 char* name;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
857 int narg;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
858 int rc;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
859
59373
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
860 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
861 return NULL;
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
862 }
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
863
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
864 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO", kwlist,
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
865 &name, &narg, &func))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
866 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
867 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
868 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
869
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
870 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
871
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
872 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
873 /* 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
874 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
875 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
876 } else {
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
877 if (PyDict_SetItem(self->function_pinboard, func, Py_None) == -1)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
878 return NULL;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
879
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
880 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
881 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
882 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
883 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
884
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
885 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
886 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
887 PyObject* aggregate_class;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
888
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
889 int n_arg;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
890 char* name;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
891 static char *kwlist[] = { "name", "n_arg", "aggregate_class", NULL };
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
892 int rc;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
893
59373
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
894 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
895 return NULL;
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
896 }
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
897
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
898 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO:create_aggregate",
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
899 kwlist, &name, &n_arg, &aggregate_class)) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
900 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
901 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
902
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
903 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
904 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
905 /* 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
906 PyErr_SetString(pysqlite_OperationalError, "Error creating aggregate");
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
907 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
908 } else {
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
909 if (PyDict_SetItem(self->function_pinboard, aggregate_class, Py_None) == -1)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
910 return NULL;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
911
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
912 Py_INCREF(Py_None);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
913 return Py_None;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
914 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
915 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
916
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
917 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
918 {
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
919 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
920 int rc;
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
921 #ifdef WITH_THREAD
38808
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
922 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
923
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
924 gilstate = PyGILState_Ensure();
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
925 #endif
38808
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
926 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
927
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
928 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
929 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
930 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
931 } else {
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
932 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
933 }
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
934
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
935 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
936 } else {
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
937 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
938 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
939 } else {
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
940 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
941 }
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
942 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
943 }
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
944
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
945 #ifdef WITH_THREAD
38808
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
946 PyGILState_Release(gilstate);
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
947 #endif
38808
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
948 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
949 }
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
950
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
951 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
952 {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
953 int rc;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
954 PyObject *ret;
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
955 #ifdef WITH_THREAD
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
956 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
957
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
958 gilstate = PyGILState_Ensure();
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
959 #endif
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
960 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
961
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
962 if (!ret) {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
963 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
964 PyErr_Print();
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
965 } else {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
966 PyErr_Clear();
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
967 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
968
55049
74c0a78114ae Merged revisions 69846 via svnmerge from
Jesus Cea <jcea@jcea.es>
parents: 52903
diff changeset
969 /* abort query if error occurred */
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
970 rc = 1;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
971 } else {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
972 rc = (int)PyObject_IsTrue(ret);
45632
a18a424c2bd3 Only DECREF if ret != NULL
Neal Norwitz <nnorwitz@gmail.com>
parents: 45580
diff changeset
973 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
974 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
975
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
976 #ifdef WITH_THREAD
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
977 PyGILState_Release(gilstate);
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
978 #endif
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
979 return rc;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
980 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
981
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
982 static 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
983 {
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
984 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
985
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
986 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
987 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
988
59373
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
989 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
990 return NULL;
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
991 }
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
992
38808
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
993 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
994 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
995 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
996 }
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
997
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
998 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
999
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1000 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
1001 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
1002 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
1003 } else {
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1004 if (PyDict_SetItem(self->function_pinboard, authorizer_cb, Py_None) == -1)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1005 return NULL;
38808
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1006
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1007 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
1008 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
1009 }
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1010 }
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1011
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1012 static PyObject* pysqlite_connection_set_progress_handler(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1013 {
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1014 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
1015 int n;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1016
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1017 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
1018
59373
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
1019 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
1020 return NULL;
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
1021 }
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
1022
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1023 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
1024 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
1025 return NULL;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1026 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1027
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1028 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
1029 /* 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
1030 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
1031 } else {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1032 sqlite3_progress_handler(self->db, n, _progress_handler, progress_handler);
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1033 if (PyDict_SetItem(self->function_pinboard, progress_handler, Py_None) == -1)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1034 return NULL;
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1035 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1036
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1037 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
1038 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
1039 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1040
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1041 #ifdef HAVE_LOAD_EXTENSION
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1042 static PyObject* pysqlite_enable_load_extension(pysqlite_Connection* self, PyObject* args)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1043 {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1044 int rc;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1045 int onoff;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1046
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1047 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1048 return NULL;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1049 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1050
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1051 if (!PyArg_ParseTuple(args, "i", &onoff)) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1052 return NULL;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1053 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1054
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1055 rc = sqlite3_enable_load_extension(self->db, onoff);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1056
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1057 if (rc != SQLITE_OK) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1058 PyErr_SetString(pysqlite_OperationalError, "Error enabling load extension");
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1059 return NULL;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1060 } else {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1061 Py_INCREF(Py_None);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1062 return Py_None;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1063 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1064 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1065
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1066 static PyObject* pysqlite_load_extension(pysqlite_Connection* self, PyObject* args)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1067 {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1068 int rc;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1069 char* extension_name;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1070 char* errmsg;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1071
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1072 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1073 return NULL;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1074 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1075
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1076 if (!PyArg_ParseTuple(args, "s", &extension_name)) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1077 return NULL;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1078 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1079
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1080 rc = sqlite3_load_extension(self->db, extension_name, 0, &errmsg);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1081 if (rc != 0) {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1082 PyErr_SetString(pysqlite_OperationalError, errmsg);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1083 return NULL;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1084 } else {
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1085 Py_INCREF(Py_None);
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1086 return Py_None;
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1087 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1088 }
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1089 #endif
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1090
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
1091 int pysqlite_check_thread(pysqlite_Connection* self)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1092 {
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
1093 #ifdef WITH_THREAD
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1094 if (self->check_same_thread) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1095 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
1096 PyErr_Format(pysqlite_ProgrammingError,
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1097 "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
1098 "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
1099 self->thread_ident, PyThread_get_thread_ident());
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1100 return 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1101 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1102
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1103 }
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
1104 #endif
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1105 return 1;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1106 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1107
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
1108 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
1109 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1110 Py_INCREF(self->isolation_level);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1111 return self->isolation_level;
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
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
1114 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
1115 {
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
1116 if (!pysqlite_check_connection(self)) {
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1117 return NULL;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1118 } else {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1119 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
1120 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1121 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1122
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
1123 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
1124 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1125 PyObject* res;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1126 PyObject* begin_statement;
49469
69ea12db9b28 Issue #4046: Backport of issue #3312's patch: fixes two crashes in the sqlite3
Gerhard Häring <gh@ghaering.de>
parents: 38883
diff changeset
1127 char* begin_statement_str;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1128
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1129 Py_XDECREF(self->isolation_level);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1130
37763
b7a3972e9915 Fix memory leak
Neal Norwitz <nnorwitz@gmail.com>
parents: 37517
diff changeset
1131 if (self->begin_statement) {
b7a3972e9915 Fix memory leak
Neal Norwitz <nnorwitz@gmail.com>
parents: 37517
diff changeset
1132 PyMem_Free(self->begin_statement);
b7a3972e9915 Fix memory leak
Neal Norwitz <nnorwitz@gmail.com>
parents: 37517
diff changeset
1133 self->begin_statement = NULL;
b7a3972e9915 Fix memory leak
Neal Norwitz <nnorwitz@gmail.com>
parents: 37517
diff changeset
1134 }
b7a3972e9915 Fix memory leak
Neal Norwitz <nnorwitz@gmail.com>
parents: 37517
diff changeset
1135
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1136 if (isolation_level == Py_None) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1137 Py_INCREF(Py_None);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1138 self->isolation_level = Py_None;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1139
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
1140 res = pysqlite_connection_commit(self, NULL);
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1141 if (!res) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1142 return -1;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1143 }
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1144 Py_DECREF(res);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1145
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1146 self->inTransaction = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1147 } else {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1148 Py_INCREF(isolation_level);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1149 self->isolation_level = isolation_level;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1150
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1151 begin_statement = PyString_FromString("BEGIN ");
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1152 if (!begin_statement) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1153 return -1;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1154 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1155 PyString_Concat(&begin_statement, isolation_level);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1156 if (!begin_statement) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1157 return -1;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1158 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1159
49469
69ea12db9b28 Issue #4046: Backport of issue #3312's patch: fixes two crashes in the sqlite3
Gerhard Häring <gh@ghaering.de>
parents: 38883
diff changeset
1160 begin_statement_str = PyString_AsString(begin_statement);
69ea12db9b28 Issue #4046: Backport of issue #3312's patch: fixes two crashes in the sqlite3
Gerhard Häring <gh@ghaering.de>
parents: 38883
diff changeset
1161 if (!begin_statement_str) {
69ea12db9b28 Issue #4046: Backport of issue #3312's patch: fixes two crashes in the sqlite3
Gerhard Häring <gh@ghaering.de>
parents: 38883
diff changeset
1162 Py_DECREF(begin_statement);
69ea12db9b28 Issue #4046: Backport of issue #3312's patch: fixes two crashes in the sqlite3
Gerhard Häring <gh@ghaering.de>
parents: 38883
diff changeset
1163 return -1;
69ea12db9b28 Issue #4046: Backport of issue #3312's patch: fixes two crashes in the sqlite3
Gerhard Häring <gh@ghaering.de>
parents: 38883
diff changeset
1164 }
69ea12db9b28 Issue #4046: Backport of issue #3312's patch: fixes two crashes in the sqlite3
Gerhard Häring <gh@ghaering.de>
parents: 38883
diff changeset
1165 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
1166 if (!self->begin_statement) {
49469
69ea12db9b28 Issue #4046: Backport of issue #3312's patch: fixes two crashes in the sqlite3
Gerhard Häring <gh@ghaering.de>
parents: 38883
diff changeset
1167 Py_DECREF(begin_statement);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1168 return -1;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1169 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1170
49469
69ea12db9b28 Issue #4046: Backport of issue #3312's patch: fixes two crashes in the sqlite3
Gerhard Häring <gh@ghaering.de>
parents: 38883
diff changeset
1171 strcpy(self->begin_statement, begin_statement_str);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1172 Py_DECREF(begin_statement);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1173 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1174
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1175 return 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1176 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1177
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
1178 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
1179 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1180 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
1181 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
1182 PyObject* weakref;
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1183 int rc;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1184
59373
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
1185 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
1186 return NULL;
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
1187 }
bf586b2776f6 Issue #7670: sqlite3: Fixed crashes when operating on closed connections.
Gerhard Häring <gh@ghaering.de>
parents: 55049
diff changeset
1188
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1189 if (!PyArg_ParseTuple(args, "O", &sql)) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1190 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1191 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1192
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
1193 _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
1194
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
1195 statement = PyObject_New(pysqlite_Statement, &pysqlite_StatementType);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1196 if (!statement) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1197 return NULL;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1198 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1199
59821
581263af5820 Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59373
diff changeset
1200 statement->db = NULL;
581263af5820 Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59373
diff changeset
1201 statement->st = NULL;
581263af5820 Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59373
diff changeset
1202 statement->sql = NULL;
581263af5820 Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59373
diff changeset
1203 statement->in_use = 0;
581263af5820 Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59373
diff changeset
1204 statement->in_weakreflist = NULL;
581263af5820 Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59373
diff changeset
1205
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
1206 rc = pysqlite_statement_create(statement, self, sql);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1207
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1208 if (rc != SQLITE_OK) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1209 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
1210 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
1211 } 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
1212 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
1213 } else {
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1214 (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
1215 _pysqlite_seterror(self->db, NULL);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1216 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1217
47951
afe8d515bfe2 Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 47527
diff changeset
1218 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
1219 } else {
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
1220 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
1221 if (!weakref) {
47951
afe8d515bfe2 Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 47527
diff changeset
1222 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
1223 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
1224 }
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
1225
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
1226 if (PyList_Append(self->statements, weakref) != 0) {
47951
afe8d515bfe2 Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 47527
diff changeset
1227 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
1228 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
1229 }
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
1230
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
1231 Py_DECREF(weakref);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1232 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1233
37938
7da4af95ebad Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents: 37763
diff changeset
1234 error:
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1235 return (PyObject*)statement;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1236 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1237
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
1238 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
1239 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1240 PyObject* cursor = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1241 PyObject* result = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1242 PyObject* method = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1243
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1244 cursor = PyObject_CallMethod((PyObject*)self, "cursor", "");
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1245 if (!cursor) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1246 goto error;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1247 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1248
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1249 method = PyObject_GetAttrString(cursor, "execute");
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1250 if (!method) {
47951
afe8d515bfe2 Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 47527
diff changeset
1251 Py_CLEAR(cursor);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1252 goto error;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1253 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1254
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1255 result = PyObject_CallObject(method, args);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1256 if (!result) {
47951
afe8d515bfe2 Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 47527
diff changeset
1257 Py_CLEAR(cursor);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1258 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1259
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1260 error:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1261 Py_XDECREF(result);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1262 Py_XDECREF(method);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1263
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1264 return cursor;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1265 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1266
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
1267 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
1268 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1269 PyObject* cursor = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1270 PyObject* result = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1271 PyObject* method = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1272
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1273 cursor = PyObject_CallMethod((PyObject*)self, "cursor", "");
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1274 if (!cursor) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1275 goto error;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1276 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1277
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1278 method = PyObject_GetAttrString(cursor, "executemany");
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1279 if (!method) {
47951
afe8d515bfe2 Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 47527
diff changeset
1280 Py_CLEAR(cursor);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1281 goto error;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1282 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1283
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1284 result = PyObject_CallObject(method, args);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1285 if (!result) {
47951
afe8d515bfe2 Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 47527
diff changeset
1286 Py_CLEAR(cursor);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1287 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1288
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1289 error:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1290 Py_XDECREF(result);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1291 Py_XDECREF(method);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1292
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1293 return cursor;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1294 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1295
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
1296 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
1297 {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1298 PyObject* cursor = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1299 PyObject* result = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1300 PyObject* method = 0;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1301
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1302 cursor = PyObject_CallMethod((PyObject*)self, "cursor", "");
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1303 if (!cursor) {
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1304 goto error;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1305 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1306
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1307 method = PyObject_GetAttrString(cursor, "executescript");
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1308 if (!method) {
47951
afe8d515bfe2 Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 47527
diff changeset
1309 Py_CLEAR(cursor);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1310 goto error;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1311 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1312
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1313 result = PyObject_CallObject(method, args);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1314 if (!result) {
47951
afe8d515bfe2 Issue #3153: sqlite leaks on error.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 47527
diff changeset
1315 Py_CLEAR(cursor);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1316 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1317
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1318 error:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1319 Py_XDECREF(result);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1320 Py_XDECREF(method);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1321
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1322 return cursor;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1323 }
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1324
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1325 /* ------------------------- COLLATION CODE ------------------------ */
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1326
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1327 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
1328 pysqlite_collation_callback(
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1329 void* context,
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1330 int text1_length, const void* text1_data,
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1331 int text2_length, const void* text2_data)
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1332 {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1333 PyObject* callback = (PyObject*)context;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1334 PyObject* string1 = 0;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1335 PyObject* string2 = 0;
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
1336 #ifdef WITH_THREAD
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1337 PyGILState_STATE gilstate;
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
1338 #endif
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1339 PyObject* retval = NULL;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1340 int result = 0;
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
1341 #ifdef WITH_THREAD
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1342 gilstate = PyGILState_Ensure();
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
1343 #endif
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1344
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1345 if (PyErr_Occurred()) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1346 goto finally;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1347 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1348
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1349 string1 = PyString_FromStringAndSize((const char*)text1_data, text1_length);
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1350 string2 = PyString_FromStringAndSize((const char*)text2_data, text2_length);
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1351
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1352 if (!string1 || !string2) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1353 goto finally; /* failed to allocate strings */
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1354 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1355
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1356 retval = PyObject_CallFunctionObjArgs(callback, string1, string2, NULL);
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1357
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1358 if (!retval) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1359 /* execution failed */
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1360 goto finally;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1361 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1362
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1363 result = PyInt_AsLong(retval);
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1364 if (PyErr_Occurred()) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1365 result = 0;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1366 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1367
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1368 finally:
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1369 Py_XDECREF(string1);
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1370 Py_XDECREF(string2);
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1371 Py_XDECREF(retval);
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
1372 #ifdef WITH_THREAD
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1373 PyGILState_Release(gilstate);
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 49154
diff changeset
1374 #endif
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1375 return result;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1376 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1377
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1378 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
1379 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
1380 {
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1381 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
1382
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 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
1384 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
1385 }
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1386
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1387 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
1388
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1389 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
1390 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
1391
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1392 finally:
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1393 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
1394 }
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1395
46159
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1396 /* 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
1397 * 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
1398 * of the sqlite3 module.
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1399 */
38808
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1400 static PyObject *
46159
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1401 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
1402 {
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1403 PyObject* retval = NULL;
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1404 PyObject* module = NULL;
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1405 PyObject* module_dict;
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1406 PyObject* pyfn_iterdump;
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1407
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1408 if (!pysqlite_check_connection(self)) {
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1409 goto finally;
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1410 }
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1411
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1412 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
1413 if (!module) {
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1414 goto finally;
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1415 }
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1416
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1417 module_dict = PyModule_GetDict(module);
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1418 if (!module_dict) {
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1419 goto finally;
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1420 }
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1421
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1422 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
1423 if (!pyfn_iterdump) {
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1424 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
1425 goto finally;
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1426 }
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1427
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1428 args = PyTuple_New(1);
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1429 if (!args) {
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1430 goto finally;
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1431 }
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1432 Py_INCREF(self);
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1433 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
1434 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
1435
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1436 finally:
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1437 Py_XDECREF(args);
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1438 Py_XDECREF(module);
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1439 return retval;
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1440 }
f9a629f41656 Accept patch issue2426 by Paul Kippes (kippesp).
Gregory P. Smith <greg@mad-scientist.com>
parents: 45632
diff changeset
1441
38808
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
1442 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
1443 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
1444 {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1445 PyObject* callable;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1446 PyObject* uppercase_name = 0;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1447 PyObject* name;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1448 PyObject* retval;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1449 char* chk;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1450 int rc;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1451
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
1452 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
1453 goto finally;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1454 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1455
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1456 if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyString_Type, &name, &callable)) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1457 goto finally;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1458 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1459
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1460 uppercase_name = PyObject_CallMethod(name, "upper", "");
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1461 if (!uppercase_name) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1462 goto finally;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1463 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1464
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1465 chk = PyString_AsString(uppercase_name);
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1466 while (*chk) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1467 if ((*chk >= '0' && *chk <= '9')
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1468 || (*chk >= 'A' && *chk <= 'Z')
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1469 || (*chk == '_'))
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1470 {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1471 chk++;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1472 } 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
1473 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
1474 goto finally;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1475 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1476 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1477
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1478 if (callable != Py_None && !PyCallable_Check(callable)) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1479 PyErr_SetString(PyExc_TypeError, "parameter must be callable");
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1480 goto finally;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1481 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1482
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1483 if (callable != Py_None) {
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1484 if (PyDict_SetItem(self->collations, uppercase_name, callable) == -1)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1485 goto finally;
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1486 } else {
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1487 if (PyDict_DelItem(self->collations, uppercase_name) == -1)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1488 goto finally;
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1489 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1490
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1491 rc = sqlite3_create_collation(self->db,
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1492 PyString_AsString(uppercase_name),
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1493 SQLITE_UTF8,
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1494 (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
1495 (callable != Py_None) ? pysqlite_collation_callback : NULL);
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1496 if (rc != SQLITE_OK) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1497 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
1498 _pysqlite_seterror(self->db, NULL);
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1499 goto finally;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1500 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1501
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1502 finally:
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1503 Py_XDECREF(uppercase_name);
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1504
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1505 if (PyErr_Occurred()) {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1506 retval = NULL;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1507 } else {
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1508 Py_INCREF(Py_None);
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1509 retval = Py_None;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1510 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1511
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1512 return retval;
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1513 }
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37387
diff changeset
1514
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1515 /* 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
1516 * 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
1517 static PyObject *
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1518 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
1519 {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1520 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
1521 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
1522 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1523
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1524 /** 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
1525 * 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
1526 static PyObject *
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1527 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
1528 {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1529 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
1530 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
1531 PyObject* result;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1532
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1533 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
1534 return NULL;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1535 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1536
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1537 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
1538 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
1539 } else {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1540 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
1541 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1542
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1543 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
1544 if (!result) {
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1545 return NULL;
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1546 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1547 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
1548
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1549 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
1550 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
1551 }
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1552
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1553 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
1554 PyDoc_STR("SQLite database connection object.");
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1555
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1556 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
1557 {"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
1558 {"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
1559 {NULL}
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1560 };
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1561
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1562 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
1563 {"cursor", (PyCFunction)pysqlite_connection_cursor, METH_VARARGS|METH_KEYWORDS,
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1564 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
1565 {"close", (PyCFunction)pysqlite_connection_close, METH_NOARGS,
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1566 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
1567 {"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS,
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1568 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
1569 {"rollback", (PyCFunction)pysqlite_connection_rollback, METH_NOARGS,
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1570 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
1571 {"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
1572 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
1573 {"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
1574 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
1575 {"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
1576 PyDoc_STR("Sets authorizer callback. Non-standard.")},
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1577 #ifdef HAVE_LOAD_EXTENSION
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1578 {"enable_load_extension", (PyCFunction)pysqlite_enable_load_extension, METH_VARARGS,
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1579 PyDoc_STR("Enable dynamic loading of SQLite extension modules. Non-standard.")},
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1580 {"load_extension", (PyCFunction)pysqlite_load_extension, METH_VARARGS,
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1581 PyDoc_STR("Load SQLite extension module. Non-standard.")},
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 52868
diff changeset
1582 #endif
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 44350
diff changeset
1583 {"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
1584 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
1585 {"execute", (PyCFunction)pysqlite_connection_execute, METH_VARARGS,
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1586 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
1587 {"executemany", (PyCFunction)pysqlite_connection_executemany, METH_VARARGS,
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1588 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
1589 {"executescript", (PyCFunction)pysqlite_connection_executescript, METH_VARARGS,
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1590 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
1591 {"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
1592 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
1593 {"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
1594 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
1595 {"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
1596 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
1597 {"__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
1598 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
1599 {"__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
1600 PyDoc_STR("For context manager. Non-standard.")},
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1601 {NULL, NULL}
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1602 };
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1603
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1604 static struct PyMemberDef connection_members[] =
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1605 {
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
1606 {"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
1607 {"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
1608 {"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
1609 {"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
1610 {"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
1611 {"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
1612 {"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
1613 {"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
1614 {"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
1615 {"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
1616 {"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
1617 {"text_factory", T_OBJECT, offsetof(pysqlite_Connection, text_factory)},
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1618 {NULL}
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1619 };
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1620
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
1621 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
1622 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
1623 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
1624 sizeof(pysqlite_Connection), /* tp_basicsize */
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1625 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
1626 (destructor)pysqlite_connection_dealloc, /* tp_dealloc */
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1627 0, /* tp_print */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1628 0, /* tp_getattr */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1629 0, /* tp_setattr */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1630 0, /* tp_compare */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1631 0, /* tp_repr */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1632 0, /* tp_as_number */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1633 0, /* tp_as_sequence */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1634 0, /* tp_as_mapping */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1635 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
1636 (ternaryfunc)pysqlite_connection_call, /* tp_call */
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1637 0, /* tp_str */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1638 0, /* tp_getattro */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1639 0, /* tp_setattro */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1640 0, /* tp_as_buffer */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1641 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1642 connection_doc, /* tp_doc */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1643 0, /* tp_traverse */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1644 0, /* tp_clear */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1645 0, /* tp_richcompare */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1646 0, /* tp_weaklistoffset */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1647 0, /* tp_iter */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1648 0, /* tp_iternext */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1649 connection_methods, /* tp_methods */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1650 connection_members, /* tp_members */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1651 connection_getset, /* tp_getset */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1652 0, /* tp_base */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1653 0, /* tp_dict */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1654 0, /* tp_descr_get */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1655 0, /* tp_descr_set */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1656 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
1657 (initproc)pysqlite_connection_init, /* tp_init */
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1658 0, /* tp_alloc */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1659 0, /* tp_new */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1660 0 /* tp_free */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1661 };
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1662
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
1663 extern int pysqlite_connection_setup_types(void)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1664 {
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
1665 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
1666 return PyType_Ready(&pysqlite_ConnectionType);
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1667 }